001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017/* 018Copyright 2005-2006 Seth Fitzsimmons <seth@note.amherst.edu> 019 020Licensed under the Apache License, Version 2.0 (the "License"); 021you may not use this file except in compliance with the License. 022You may obtain a copy of the License at 023 024 http://www.apache.org/licenses/LICENSE-2.0 025 026Unless required by applicable law or agreed to in writing, software 027distributed under the License is distributed on an "AS IS" BASIS, 028WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 029See the License for the specific language governing permissions and 030limitations under the License. 031*/ 032package com.echothree.view.client.web.struts.sprout.support; 033 034import java.lang.reflect.Method; 035import java.util.ArrayList; 036import java.util.Arrays; 037import java.util.Collection; 038import org.slf4j.Logger; 039import org.slf4j.LoggerFactory; 040 041/** 042 * Sprout utility methods. 043 * 044 * @author Seth Fitzsimmons 045 */ 046public class SproutUtils { 047 048 private static final Logger log = LoggerFactory.getLogger( SproutUtils.class ); 049 050 /** 051 * Gets a collection of methods declared in a specified range of a given 052 * class' hierarchy. 053 * 054 * @param clazz Class to inspect. 055 * @param upto Methods declared in this class and its subclasses will be 056 * included. Any methods declared in superclasses will be ignored. 057 * @return Collection of methods declared within the specified range. 058 */ 059 public static Collection<Method> getDeclaredMethods(Class clazz, final Class upto) { 060 // collect methods to register (include methods for all classes up to and including this one) 061 final Collection<Method> methods = new ArrayList<>(); 062 while ( !clazz.equals( upto.getSuperclass() ) ) { 063 methods.addAll( Arrays.asList( clazz.getDeclaredMethods() ) ); 064 clazz = clazz.getSuperclass(); 065 } 066 067 return methods; 068 } 069 070}