当前位置: 首页>>代码示例>>Java>>正文


Java Method.getDeclaringClass方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.getDeclaringClass方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getDeclaringClass方法的具体用法?Java Method.getDeclaringClass怎么用?Java Method.getDeclaringClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getDeclaringClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: provideExtractorForValue

import java.lang.reflect.Method; //导入方法依赖的package包/类
private <T> ValueExtractor provideExtractorForValue(Class<T> clazz, int target, List<String> chainOfProperties) {
    Class<?> propertyClass = clazz;
    List<ValueExtractor> chainedExtractors = Lists.newArrayList();

    for (String property : chainOfProperties) {
        Class<?> finalPropertyClass = propertyClass;

        Optional<Method> matchingMethod = Stream.of(property,
                "get" + WordUtils.capitalize(property),
                "is" + WordUtils.capitalize(property))
                .map(token -> MethodUtils.getMatchingMethod(finalPropertyClass, token))
                .findFirst();

        Method method = matchingMethod.orElseThrow(
                () -> new InvalidQueryException(
                        String.format("Cannot find appropriate method for property [%s] on class [%s]",
                                property, finalPropertyClass)));

        ReflectionExtractor extractor = new ReflectionExtractor(method.getName());
        chainedExtractors.add(extractor);
        propertyClass = method.getDeclaringClass();
    }

    return new ChainedExtractor(chainedExtractors.toArray(new ValueExtractor[chainedExtractors.size()]));
}
 
开发者ID:michalwojciechowski,项目名称:coherence-sql,代码行数:26,代码来源:ReflectionExtractorFactory.java

示例2: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    Class<?>[] parameterTypes = method.getParameterTypes();
    if (method.getDeclaringClass() == Object.class) {
        return method.invoke(invoker, args);
    }
    if ("toString".equals(methodName) && parameterTypes.length == 0) {
        return invoker.toString();
    }
    if ("hashCode".equals(methodName) && parameterTypes.length == 0) {
        return invoker.hashCode();
    }
    if ("equals".equals(methodName) && parameterTypes.length == 1) {
        return invoker.equals(args[0]);
    }
    return invoker.invoke(new RpcInvocation(method, args)).recreate();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:18,代码来源:InvokerInvocationHandler.java

示例3: isDefinitelyImmutableInfo

import java.lang.reflect.Method; //导入方法依赖的package包/类
static boolean isDefinitelyImmutableInfo(Class<?> implClass) {
    if (!NotificationBroadcaster.class.isAssignableFrom(implClass))
        return true;
    synchronized (definitelyImmutable) {
        Boolean immutable = definitelyImmutable.get(implClass);
        if (immutable == null) {
            final Class<NotificationBroadcasterSupport> nbs =
                    NotificationBroadcasterSupport.class;
            if (nbs.isAssignableFrom(implClass)) {
                try {
                    Method m = implClass.getMethod("getNotificationInfo");
                    immutable = (m.getDeclaringClass() == nbs);
                } catch (Exception e) {
                    // Too bad, we'll say no for now.
                    return false;
                }
            } else
                immutable = false;
            definitelyImmutable.put(implClass, immutable);
        }
        return immutable;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:StandardMBeanIntrospector.java

示例4: checkProxyMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Check if the given method is a method declared in the proxy interface
 * implemented by the given proxy instance.
 *
 * @param proxy a proxy instance
 * @param method an interface method dispatched to a InvocationHandler
 *
 * @throws IllegalArgumentException if the given proxy or method is invalid.
 */
public static void checkProxyMethod(Object proxy, Method method) {
    // check if it is a valid proxy instance
    if (proxy == null || !Proxy.isProxyClass(proxy.getClass())) {
        throw new IllegalArgumentException("Not a Proxy instance");
    }
    if (Modifier.isStatic(method.getModifiers())) {
        throw new IllegalArgumentException("Can't handle static method");
    }

    Class<?> c = method.getDeclaringClass();
    if (c == Object.class) {
        String name = method.getName();
        if (name.equals("hashCode") || name.equals("equals") || name.equals("toString")) {
            return;
        }
    }

    if (isSuperInterface(proxy.getClass(), c)) {
        return;
    }

    // disallow any method not declared in one of the proxy interfaces
    throw new IllegalArgumentException("Can't handle: " + method);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ReflectUtil.java

示例5: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.getDeclaringClass() == Object.class) {
        return method.invoke(map, args);
    }
    String methodName = method.getName();
    Object value = null;
    if (methodName.length() > 3 && methodName.startsWith("get")) {
        value = map.get(methodName.substring(3, 4).toLowerCase() + methodName.substring(4));
    } else if (methodName.length() > 2 && methodName.startsWith("is")) {
        value = map.get(methodName.substring(2, 3).toLowerCase() + methodName.substring(3));
    } else {
        value = map.get(methodName.substring(0, 1).toLowerCase() + methodName.substring(1));
    }
    if (value instanceof Map<?,?> && ! Map.class.isAssignableFrom(method.getReturnType())) {
        value = realize0((Map<String, Object>) value, method.getReturnType(), null, new IdentityHashMap<Object, Object>());
    }
    return value;
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:20,代码来源:PojoUtils.java

示例6: findAccessibleMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Finds method that is accessible from public class or interface through class hierarchy.
 *
 * @param method  object that represents found method
 * @return object that represents accessible method
 * @throws NoSuchMethodException if method is not accessible or is not found
 *                               in specified superclass or interface
 */
public static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
    Class<?> type = method.getDeclaringClass();
    if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) {
        return method;
    }
    if (Modifier.isStatic(method.getModifiers())) {
        throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
    }
    for (Type generic : type.getGenericInterfaces()) {
        try {
            return findAccessibleMethod(method, generic);
        }
        catch (NoSuchMethodException exception) {
            // try to find in superclass or another interface
        }
    }
    return findAccessibleMethod(method, type.getGenericSuperclass());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:MethodFinder.java

示例7: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        if(method.getDeclaringClass()==Locatable.class)
            return method.invoke(this,args);
        if(Modifier.isStatic(method.getModifiers()))
            // malicious code can pass in a static Method object.
            // doing method.invoke() would end up executing it,
            // so we need to protect against it.
            throw new IllegalArgumentException();

        return method.invoke(core,args);
    } catch (InvocationTargetException e) {
        if(e.getTargetException()!=null)
            throw e.getTargetException();
        throw e;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:LocatableAnnotation.java

示例8: isWebMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean isWebMethod(Method method) {
    int modifiers = method.getModifiers();
    if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers))
        return false;

    Class clazz = method.getDeclaringClass();
    boolean declHasWebService = getAnnotation(clazz, WebService.class) != null;
    WebMethod webMethod = getAnnotation(method, WebMethod.class);
    if (webMethod != null && !webMethod.exclude() && declHasWebService)
        return true;
    return declHasWebService && !classUsesWebMethod.contains(clazz);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:RuntimeModeler.java

示例9: ensureInvocableMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void ensureInvocableMethod(Method m)
        throws InvocationTargetException {
    Class<?> clazz = m.getDeclaringClass();
    if (clazz.equals(AccessController.class) ||
            clazz.equals(Method.class) ||
            clazz.getName().startsWith("java.lang.invoke."))
        throw new InvocationTargetException(
                new UnsupportedOperationException("invocation not supported"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:MethodUtil.java

示例10: findRunnableKey

import java.lang.reflect.Method; //导入方法依赖的package包/类
public String findRunnableKey(Runnable runnable) {
    logger.info("findRunnableKey : {}", runnable);

    if (runnable instanceof ScheduledMethodRunnable) {
        ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
        Method method = scheduledMethodRunnable.getMethod();
        Class clz = method.getDeclaringClass();

        logger.info("{}.{}", clz.getCanonicalName(), method.getName());

        return clz.getCanonicalName() + "." + method.getName();
    } else {
        return runnable.toString();
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:16,代码来源:ProxyTaskScheduler.java

示例11: MemberName

import java.lang.reflect.Method; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Method m, boolean wantSpecial) {
    m.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have m in hand:
    MethodHandleNatives.init(this, m);
    if (clazz == null) {  // MHN.init failed
        if (m.getDeclaringClass() == MethodHandle.class &&
            isMethodHandleInvokeName(m.getName())) {
            // The JVM did not reify this signature-polymorphic instance.
            // Need a special case here.
            // See comments on MethodHandleNatives.linkMethod.
            MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes());
            int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual);
            init(MethodHandle.class, m.getName(), type, flags);
            if (isMethodHandleInvoke())
                return;
        }
        throw new LinkageError(m.toString());
    }
    assert(isResolved() && this.clazz != null);
    this.name = m.getName();
    if (this.type == null)
        this.type = new Object[] { m.getReturnType(), m.getParameterTypes() };
    if (wantSpecial) {
        if (isAbstract())
            throw new AbstractMethodError(this.toString());
        if (getReferenceKind() == REF_invokeVirtual)
            changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual);
        else if (getReferenceKind() == REF_invokeInterface)
            // invokeSpecial on a default method
            changeReferenceKind(REF_invokeSpecial, REF_invokeInterface);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:MemberName.java

示例12: ensureInvocableMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void ensureInvocableMethod(Method m)
    throws InvocationTargetException
{
    Class<?> clazz = m.getDeclaringClass();
    if (clazz.equals(AccessController.class) ||
        clazz.equals(Method.class) ||
        clazz.getName().startsWith("java.lang.invoke."))
        throw new InvocationTargetException(
            new UnsupportedOperationException("invocation not supported"));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:MethodUtil.java

示例13: isAssignable

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean isAssignable(Method m1, Method m2) {
    if (m1 == null) {
        return true; // choose second method
    }
    if (m2 == null) {
        return false; // choose first method
    }
    if (!m1.getName().equals(m2.getName())) {
        return true; // choose second method by default
    }
    Class<?> type1 = m1.getDeclaringClass();
    Class<?> type2 = m2.getDeclaringClass();
    if (!type1.isAssignableFrom(type2)) {
        return false; // choose first method: it declared later
    }
    type1 = getReturnType(getClass0(), m1);
    type2 = getReturnType(getClass0(), m2);
    if (!type1.isAssignableFrom(type2)) {
        return false; // choose first method: it overrides return type
    }
    Class<?>[] args1 = getParameterTypes(getClass0(), m1);
    Class<?>[] args2 = getParameterTypes(getClass0(), m2);
    if (args1.length != args2.length) {
        return true; // choose second method by default
    }
    for (int i = 0; i < args1.length; i++) {
        if (!args1[i].isAssignableFrom(args2[i])) {
            return false; // choose first method: it overrides parameter
        }
    }
    return true; // choose second method
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:PropertyDescriptor.java

示例14: isMethodOverridden

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean isMethodOverridden(NodeAction d, String name) {
    try {
        Method m = d.getClass().getMethod(name, new Class[0]);

        return m.getDeclaringClass() != CallableSystemAction.class;
    } catch (java.lang.NoSuchMethodException ex) {
        ex.printStackTrace();
        throw new IllegalStateException("Error searching for method " + name + " in " + d); // NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavaRefactoringGlobalAction.java

示例15: assertTargetBean

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Assert that the target bean class is an instance of the class where the given
 * method is declared. In some cases the actual endpoint instance at request-
 * processing time may be a JDK dynamic proxy (lazy initialization, prototype beans,
 * and others). Endpoint classes that require proxying should prefer class-based proxy
 * mechanisms.
 */
private void assertTargetBean(Method method, Object targetBean, Object[] args) {
	Class<?> methodDeclaringClass = method.getDeclaringClass();
	Class<?> targetBeanClass = targetBean.getClass();
	if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
		String text = "The mapped handler method class '"
				+ methodDeclaringClass.getName()
				+ "' is not an instance of the actual endpoint bean class '"
				+ targetBeanClass.getName() + "'. If the endpoint requires proxying "
				+ "(e.g. due to @Transactional), please use class-based proxying.";
		throw new IllegalStateException(getInvocationErrorMessage(text, args));
	}
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:20,代码来源:InvocableHandlerMethod.java


注:本文中的java.lang.reflect.Method.getDeclaringClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。