Example usage for java.lang.reflect Method getDeclaringClass

List of usage examples for java.lang.reflect Method getDeclaringClass

Introduction

In this page you can find the example usage for java.lang.reflect Method getDeclaringClass.

Prototype

@Override
public Class<?> getDeclaringClass() 

Source Link

Document

Returns the Class object representing the class or interface that declares the method represented by this object.

Usage

From source file:org.encos.flydown.Flydown.java

private String getMethodKey(MethodSignature methodSignature) {

    Method method = methodSignature.getMethod();
    String methodName = method.getName();
    String className = method.getDeclaringClass().getSimpleName();
    return MessageFormat.format("{0}.{1}", className, methodName);
}

From source file:net.sf.jasperreports.compilers.JavaScriptFunctionsObject.java

protected Object resolveFunction(String name, Scriptable start) {
    Object function = functions.get(name);
    if (function != null) {
        return function;
    }/*ww  w .jav  a 2 s  .  c o m*/

    // remembering not found functions as well so that we don't look them up several times
    function = NOT_FOUND;

    Method method = functionsUtil.getMethod4Function(name);
    if (method != null) {
        Class<?> functionClass = method.getDeclaringClass();
        if (FunctionSupport.class.isAssignableFrom(functionClass)) {
            // instance method, create the instance
            @SuppressWarnings("unchecked")
            FunctionSupport functionSupport = evaluator
                    .getFunctionSupport((Class<? extends FunctionSupport>) functionClass);

            // wrap the function support as a JavaScript object
            final Scriptable functionScriptable = context.getWrapFactory().wrapAsJavaObject(context, start,
                    functionSupport, functionClass);
            // get the JavaScript method
            Object functionCall = functionScriptable.get(name, start);
            if (functionCall instanceof Callable)//this should be the case normally
            {
                Callable functionCallable = (Callable) functionCall;
                // wrap the method so that it uses functionScriptable as this object
                function = new JavaScriptCallableThisDecorator(functionCallable, functionScriptable);
            }
        } else {
            // static method
            // wrap the class
            Scriptable functionScriptable = context.getWrapFactory().wrapJavaClass(context, start,
                    functionClass);
            // get the static JavaScript method
            Object functionCall = functionScriptable.get(name, start);
            if (functionCall instanceof Callable)//this should be the case normally
            {
                function = functionCall;
            }
        }

        if (function == NOT_FOUND && log.isDebugEnabled()) {
            // should not happen normally
            log.debug("did not find JavaScript function " + name + " in class " + functionClass.getName());
        }
    }

    functions.put(name, function);
    return function;
}

From source file:com.quirklabs.authorise.ProxyAwareLocalVariableTableParameterNameDiscoverer.java

/**
 * Visit the given method and discover its parameter names.
 *///from www .  j  a  v a2  s .com
private ParameterNameDiscoveringVisitor visitMethod(Method method) throws IOException {
    ClassReader classReader = getClassReader(method.getDeclaringClass());
    FindMethodParameterNamesClassVisitor classVisitor = new FindMethodParameterNamesClassVisitor(method);
    classReader.accept(classVisitor, 0);
    return classVisitor;
}

From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java

@Test
public void checkImplementedMethods() {
    Class<?> bukkitEvent = eventImpl.getSuperclass();
    for (Method method : bukkitEvent.getMethods()) {
        int modifiers = method.getModifiers();
        if (Modifier.isStatic(modifiers) || isDefault(method) || method.getDeclaringClass() == Event.class
                || method.getDeclaringClass() == Object.class || method.getName().equals("getHandlers")
                || method.getName().startsWith("_INVALID_")) {
            continue;
        }//  w  ww .j av  a 2  s  .  c om

        try {
            eventImpl.getDeclaredMethod(method.getName(), method.getParameterTypes());
        } catch (NoSuchMethodException e) {
            fail(eventImpl.getSimpleName() + ": should override method " + method);
        }
    }
}

From source file:api.wiki.WikiGenerator.java

private String javaDocLink(Method method) {
    Class<?> declaringClass = method.getDeclaringClass();
    Package aPackage = declaringClass.getPackage();
    Class<?>[] parameterTypes = method.getParameterTypes();
    String groupIdSlashes = groupId.replace('.', '/');
    String packageSlashes = aPackage.getName().replace('.', '/');
    String parameterSlashes = stream(parameterTypes).map(Class::getName).collect(joining("-", "", "-"));
    String closestReleasedVersion = latestReleasedVersion(version);
    return "https://oss.sonatype.org/service/local/repositories/releases/archive/" + groupIdSlashes + "/"
            + artifactId + "/" + closestReleasedVersion + "/" + artifactId + "-" + closestReleasedVersion
            + "-javadoc.jar/!/" + packageSlashes + "/" + declaringClass.getSimpleName() + ".html#"
            + method.getName() + "-" + parameterSlashes;
}

From source file:com.rockagen.gnext.service.spring.aspect.OpLogAspect.java

/**
 * Get {@link com.rockagen.gnext.annotation.Plog} value
 * /*from w w  w .  j  a  va 2s.c  o  m*/
 * @param method method
 * @return {@link com.rockagen.gnext.annotation.Plog} value
 */
private String getPlogValue(Method method) {
    if (method.isAnnotationPresent(Plog.class)) {
        Plog plog = method.getAnnotation(Plog.class);
        return plog.value();
    } else {
        return method.getDeclaringClass() + "#" + method.getName();
    }
}

From source file:net.sourceforge.cobertura.metrics.model.location.SourceLocation.java

/**
 * Convenience constructor digging out package class and method names from
 * the supplied Method object.//from   w w  w  .  j  a  v  a  2 s.c om
 *
 * @param method        The non-null Method object holding package, class and method names.
 * @param lineNumber    The line number in the class containing this SourceLocation.
 * @param branchSegment The branch segment on the lineNumber in the class containing this SourceLocation.
 */
public SourceLocation(final Method method, final int lineNumber, final int branchSegment) {
    // Delegate
    this(method.getDeclaringClass().getPackage().getName(), method.getDeclaringClass().getSimpleName(),
            method.getName(), lineNumber, branchSegment);
}

From source file:de.escalon.hypermedia.spring.AffordanceBuilderFactory.java

@Override
public AffordanceBuilder linkTo(Method method, Object... parameters) {
    return linkTo(method.getDeclaringClass(), method, parameters);
}

From source file:com.dianping.resource.io.util.ClassUtils.java

/**
 * Given a method, which may come from an interface, and a target class used
 * in the current reflective invocation, find the corresponding target method
 * if there is one. E.g. the method may be {@code IFoo.bar()} and the
 * target class may be {@code DefaultFoo}. In this case, the method may be
 * {@code DefaultFoo.bar()}. This enables attributes on that method to be found.
 * <p><b>NOTE:</b> In contrast to {@link org.springframework.aop.support.AopUtils#getMostSpecificMethod},
 * this method does <i>not</i> resolve Java 5 bridge methods automatically.
 * Call {@link org.springframework.core.BridgeMethodResolver#findBridgedMethod}
 * if bridge method resolution is desirable (e.g. for obtaining metadata from
 * the original method definition)./*www . j  a  va 2  s.  com*/
 * <p><b>NOTE:</b> Since Spring 3.1.1, if Java security settings disallow reflective
 * access (e.g. calls to {@code Class#getDeclaredMethods} etc, this implementation
 * will fall back to returning the originally provided method.
 * @param method the method to be invoked, which may come from an interface
 * @param targetClass the target class for the current invocation.
 * May be {@code null} or may not even implement the method.
 * @return the specific target method, or the original method if the
 * {@code targetClass} doesn't implement it or is {@code null}
 */
public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
    if (method != null && isOverridable(method, targetClass) && targetClass != null
            && !targetClass.equals(method.getDeclaringClass())) {
        try {
            if (Modifier.isPublic(method.getModifiers())) {
                try {
                    return targetClass.getMethod(method.getName(), method.getParameterTypes());
                } catch (NoSuchMethodException ex) {
                    return method;
                }
            } else {
                Method specificMethod = ReflectionUtils.findMethod(targetClass, method.getName(),
                        method.getParameterTypes());
                return (specificMethod != null ? specificMethod : method);
            }
        } catch (AccessControlException ex) {
            // Security settings are disallowing reflective access; fall back to 'method' below.
        }
    }
    return method;
}

From source file:com.gopivotal.cloudfoundry.test.support.runner.BuildpackClassRunner.java

private Set<String> getExcludedApplicationNames(Method method) {
    Set<String> names = new HashSet<>();

    names.addAll(nullSafeValue(AnnotationUtils.findAnnotation(method, ExcludedApplications.class)));
    names.addAll(nullSafeValue(/*from w  w w .  ja  v a  2 s  .c o m*/
            AnnotationUtils.findAnnotation(method.getDeclaringClass(), ExcludedApplications.class)));

    return names;
}