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:com.nineteendrops.tracdrops.api.search.populator.SearchTestInitializator.java

@DataProvider(name = "wikiPagesProvider")
public Iterator<Object[]> wikiPagesProvider(Method method) {

    return new LinesIterator(method.getDeclaringClass(), method, "wikiPages.txt", new SimpleLineConverter());
}

From source file:com.nineteendrops.tracdrops.api.search.populator.SearchTestInitializator.java

@DataProvider(name = "milestoneProvider")
public Iterator<Object[]> milestoneProvider(Method method) {

    return new LinesIterator(method.getDeclaringClass(), method, "milestones.txt",
            new MilestoneLineConverter());
}

From source file:com.liferay.portal.remote.json.web.service.extender.internal.ServiceJSONWebServiceScannerStrategy.java

@Override
public MethodDescriptor[] scan(Object service) {
    Class<?> clazz = null;/*  w  w w  .j a va2 s .  c  om*/

    try {
        clazz = getTargetClass(service);
    } catch (Exception e) {
        return new MethodDescriptor[0];
    }

    Method[] methods = clazz.getMethods();

    List<MethodDescriptor> methodDescriptors = new ArrayList<>(methods.length);

    for (Method method : methods) {
        Class<?> declaringClass = method.getDeclaringClass();

        if (declaringClass != clazz) {
            continue;
        }

        methodDescriptors.add(new MethodDescriptor(method));
    }

    return methodDescriptors.toArray(new MethodDescriptor[methodDescriptors.size()]);
}

From source file:org.archfirst.common.springtest.TraceTestExecutionListener.java

@Override
public void afterTestMethod(TestContext testContext) throws Exception {
    Method method = testContext.getTestMethod();
    logger.trace("<<< Exiting method '{}' of class [{}]", method.getName(),
            method.getDeclaringClass().getName());
}

From source file:org.archfirst.common.springtest.TraceTestExecutionListener.java

@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    Method method = testContext.getTestMethod();
    logger.trace(">>> Entering method '{}' of class [{}]", method.getName(),
            method.getDeclaringClass().getName());
}

From source file:grails.plugin.springsecurity.acl.access.method.SecuredAnnotationSecurityMetadataSource.java

/**
 * {@inheritDoc}/* w w  w  .j  a  v a2s .co m*/
 * @see org.springframework.security.access.method.AbstractFallbackMethodSecurityMetadataSource#findAttributes(
 *    java.lang.reflect.Method, java.lang.Class)
 */
@Override
protected Collection<ConfigAttribute> findAttributes(final Method method, final Class<?> targetClass) {
    Method actualMethod = ProxyUtils.unproxy(method);

    if (!isService(actualMethod.getDeclaringClass())) {
        return null;
    }

    return processAnnotation(actualMethod.getAnnotation(Secured.class));
}

From source file:com.quatico.base.aem.test.api.setup.SetupFactory.java

public T getSetup(final Object... implementors) {
    final Map<Class<?>, Object> interfaces = new HashMap<>();
    for (Object implementor : implementors) {
        List<Class<?>> implementorInterfaces = ClassUtils.getAllInterfaces(implementor.getClass());

        assert !implementorInterfaces.isEmpty();

        for (Class<?> implementorInterface : implementorInterfaces) {
            interfaces.put(implementorInterface, implementor);
        }//from ww w. j  a  v  a2  s  . co m
    }

    @SuppressWarnings("unchecked")
    T result = (T) Proxy.newProxyInstance(this.interfaze.getClassLoader(), new Class<?>[] { this.interfaze },
            new InvocationHandler() {
                private final Object fProxyObject = new Object() {
                    @Override
                    public String toString() {
                        return "Proxy for: " + SetupFactory.this.interfaze.getDeclaringClass().getName(); //$NON-NLS-1$
                    }
                };

                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if (method.getDeclaringClass().equals(Object.class)) {
                        method.invoke(this.fProxyObject, args);
                    }

                    if (interfaces.containsKey(method.getDeclaringClass())) {
                        return method.invoke(interfaces.get(method.getDeclaringClass()), args);
                    }

                    throw new UnsupportedOperationException(
                            "Created proxy has not received an implementation that supports this method: " //$NON-NLS-1$
                                    + method.getName());
                }
            });

    return result;
}

From source file:org.smartparam.spring.function.SpringFunctionRepository.java

@Override
protected Function createFunction(String functionName, Method method) {
    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
            method.getDeclaringClass());
    String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry);

    SpringFunction springFunction = new SpringFunction(functionName, FUNCTION_TYPE, beanName, method);

    return springFunction;
}

From source file:org.craftercms.commons.security.permissions.annotations.HasPermissionAnnotationHandler.java

protected Method getActualMethod(ProceedingJoinPoint pjp) {
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Method method = ms.getMethod();

    if (method.getDeclaringClass().isInterface()) {
        Class<?> targetClass = pjp.getTarget().getClass();
        try {//w w  w  .  j  av a 2 s  . co m
            method = targetClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
        } catch (NoSuchMethodException e) {
            // Should NEVER happen
            throw new RuntimeException(e);
        }
    }

    return method;
}

From source file:org.apache.pig.JVMReuseImpl.java

public void cleanupStaticData() {

    // Calling Pig builtin ones directly without reflection for optimization
    // and to reduce probability of NPE in PIG-4418
    SpillableMemoryManager.staticDataCleanup();
    PhysicalOperator.staticDataCleanup();
    PigContext.staticDataCleanup();/*from   w  ww  . j  a  v a2  s.  co  m*/
    PigGenericMapReduce.staticDataCleanup();
    PigStatusReporter.staticDataCleanup();
    PigCombiner.Combine.staticDataCleanup();
    DistinctCombiner.Combine.staticDataCleanup();

    String className = null;
    String msg = null;
    List<Method> staticCleanupMethods = JVMReuseManager.getInstance().getStaticDataCleanupMethods();
    for (Method m : staticCleanupMethods) {
        try {
            className = m.getDeclaringClass() == null ? "anonymous" : m.getDeclaringClass().getName();
            msg = "Invoking method " + m.getName() + " in class " + className + " for static data cleanup";
            if (className.startsWith("org.apache.pig")) {
                LOG.debug(msg);
            } else {
                LOG.info(msg);
            }
            m.invoke(null);
            msg = null;
        } catch (Exception e) {
            LOG.error("Exception while calling static methods:" + getMethodNames(staticCleanupMethods) + ". "
                    + msg, e);
            throw new RuntimeException("Error while " + msg, e);
        }
    }
}