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


Java MethodRepository类代码示例

本文整理汇总了Java中sun.reflect.generics.repository.MethodRepository的典型用法代码示例。如果您正苦于以下问题:Java MethodRepository类的具体用法?Java MethodRepository怎么用?Java MethodRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getGenericInfo

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
@Override
MethodRepository getGenericInfo() {
    // lazily initialize repository if necessary
    if (genericInfo == null) {
        // create and cache generic info repository
        genericInfo = MethodRepository.make(getGenericSignature(),
                                            getFactory());
    }
    return genericInfo; //return cached repository
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:Method.java

示例2: getGenericInfo

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
private MethodRepository getGenericInfo() {
// lazily initialize repository if necessary
if (genericInfo == null) {
    // create and cache generic info repository
    genericInfo = MethodRepository.make(getGenericSignature(), 
					getFactory());
}
return genericInfo; //return cached repository
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:10,代码来源:Method.java

示例3: getGenericInfo

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
private MethodRepository getGenericInfo() {
    // lazily initialize repository if necessary
    if (genericInfo == null) {
        // create and cache generic info repository
        genericInfo = MethodRepository.make(getGenericSignature(),
                                            getFactory());
    }
    return genericInfo; //return cached repository
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:10,代码来源:Method.java

示例4: method

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
public static Method method(String internalName, String name, String descriptior) throws ClassNotFoundException {
    Class<?> aClass = Class.forName(internalName.replace('/', '.'));
    MethodRepository repository = MethodRepository.make(descriptior, Signature.genericsFactory(aClass));
    Sequence<Type> parameterTypes = sequence(repository.getParameterTypes());
    Type returnType = repository.getReturnType();
        return sequence(aClass.getMethods()).
                filter(m -> m.getName().equals(name)).
                filter(m -> m.getReturnType().equals(returnType)).
                filter(m -> sequence(m.getParameterTypes()).equals(parameterTypes)).
                head();
}
 
开发者ID:bodar,项目名称:totallylazy,代码行数:12,代码来源:Methods.java

示例5: getEnclosingMethod

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
/**
    * If this <tt>Class</tt> object represents a local or anonymous
    * class within a method, returns a {@link
    * java.lang.reflect.Method Method} object representing the
    * immediately enclosing method of the underlying class. Returns
    * <tt>null</tt> otherwise.
    *
    * In particular, this method returns <tt>null</tt> if the underlying
    * class is a local or anonymous class immediately enclosed by a type
    * declaration, instance initializer or static initializer.
    *
    * @return the immediately enclosing method of the underlying class, if
    *     that class is a local or anonymous class; otherwise <tt>null</tt>.
    * @since 1.5
    */
   public Method getEnclosingMethod() {
EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();

if (enclosingInfo == null)
    return null;
else {
    if (!enclosingInfo.isMethod())
	return null;

    MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(), 
						      getFactory());
    Class      returnType       = toClass(typeInfo.getReturnType());
    Type []    parameterTypes   = typeInfo.getParameterTypes();
    Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];

    // Convert Types to Classes; returned types *should*
    // be class objects since the methodDescriptor's used
    // don't have generics information
    for(int i = 0; i < parameterClasses.length; i++)
	parameterClasses[i] = toClass(parameterTypes[i]);

    /*
     * Loop over all declared methods; match method name,
     * number of and type of parameters, *and* return
     * type.  Matching return type is also necessary
     * because of covariant returns, etc.
     */
    for(Method m: enclosingInfo.getEnclosingClass().getDeclaredMethods()) {
	if (m.getName().equals(enclosingInfo.getName()) ) {
	    Class<?>[] candidateParamClasses = m.getParameterTypes();
	    if (candidateParamClasses.length == parameterClasses.length) {
		boolean matches = true;
		for(int i = 0; i < candidateParamClasses.length; i++) {
		    if (!candidateParamClasses[i].equals(parameterClasses[i])) {
			matches = false;
			break;
		    }
		}
		    
		if (matches) { // finally, check return type
		    if (m.getReturnType().equals(returnType) )
			return m;
		}
	    }
	}
    }
	
    throw new InternalError("Enclosing method not found");
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:66,代码来源:Class.java

示例6: getEnclosingMethod

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
/**
 * If this {@code Class} object represents a local or anonymous
 * class within a method, returns a {@link
 * java.lang.reflect.Method Method} object representing the
 * immediately enclosing method of the underlying class. Returns
 * {@code null} otherwise.
 *
 * In particular, this method returns {@code null} if the underlying
 * class is a local or anonymous class immediately enclosed by a type
 * declaration, instance initializer or static initializer.
 *
 * @return the immediately enclosing method of the underlying class, if
 *     that class is a local or anonymous class; otherwise {@code null}.
 * @since 1.5
 */
@CallerSensitive
public Method getEnclosingMethod() {
    EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();

    if (enclosingInfo == null)
        return null;
    else {
        if (!enclosingInfo.isMethod())
            return null;

        MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
                                                          getFactory());
        Class<?>   returnType       = toClass(typeInfo.getReturnType());
        Type []    parameterTypes   = typeInfo.getParameterTypes();
        Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];

        // Convert Types to Classes; returned types *should*
        // be class objects since the methodDescriptor's used
        // don't have generics information
        for(int i = 0; i < parameterClasses.length; i++)
            parameterClasses[i] = toClass(parameterTypes[i]);

        // Perform access check
        Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
        // be very careful not to change the stack depth of this
        // checkMemberAccess call for security reasons
        // see java.lang.SecurityManager.checkMemberAccess
        //
        // Note that we need to do this on the enclosing class
        enclosingCandidate.checkMemberAccess(Member.DECLARED,
                                             Reflection.getCallerClass(), true);
        /*
         * Loop over all declared methods; match method name,
         * number of and type of parameters, *and* return
         * type.  Matching return type is also necessary
         * because of covariant returns, etc.
         */
        for(Method m: enclosingCandidate.getDeclaredMethods()) {
            if (m.getName().equals(enclosingInfo.getName()) ) {
                Class<?>[] candidateParamClasses = m.getParameterTypes();
                if (candidateParamClasses.length == parameterClasses.length) {
                    boolean matches = true;
                    for(int i = 0; i < candidateParamClasses.length; i++) {
                        if (!candidateParamClasses[i].equals(parameterClasses[i])) {
                            matches = false;
                            break;
                        }
                    }

                    if (matches) { // finally, check return type
                        if (m.getReturnType().equals(returnType) )
                            return m;
                    }
                }
            }
        }

        throw new InternalError("Enclosing method not found");
    }
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:76,代码来源:Class.java

示例7: getEnclosingMethod

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
/**
 * If this {@code Class} object represents a local or anonymous
 * class within a method, returns a {@link
 * java.lang.reflect.Method Method} object representing the
 * immediately enclosing method of the underlying class. Returns
 * {@code null} otherwise.
 *
 * In particular, this method returns {@code null} if the underlying
 * class is a local or anonymous class immediately enclosed by a type
 * declaration, instance initializer or static initializer.
 *
 * @return the immediately enclosing method of the underlying class, if
 *     that class is a local or anonymous class; otherwise {@code null}.
 * @since 1.5
 */
public Method getEnclosingMethod() {
    EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();

    if (enclosingInfo == null)
        return null;
    else {
        if (!enclosingInfo.isMethod())
            return null;

        MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
                                                          getFactory());
        Class<?>   returnType       = toClass(typeInfo.getReturnType());
        Type []    parameterTypes   = typeInfo.getParameterTypes();
        Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];

        // Convert Types to Classes; returned types *should*
        // be class objects since the methodDescriptor's used
        // don't have generics information
        for(int i = 0; i < parameterClasses.length; i++)
            parameterClasses[i] = toClass(parameterTypes[i]);

        /*
         * Loop over all declared methods; match method name,
         * number of and type of parameters, *and* return
         * type.  Matching return type is also necessary
         * because of covariant returns, etc.
         */
        for(Method m: enclosingInfo.getEnclosingClass().getDeclaredMethods()) {
            if (m.getName().equals(enclosingInfo.getName()) ) {
                Class<?>[] candidateParamClasses = m.getParameterTypes();
                if (candidateParamClasses.length == parameterClasses.length) {
                    boolean matches = true;
                    for(int i = 0; i < candidateParamClasses.length; i++) {
                        if (!candidateParamClasses[i].equals(parameterClasses[i])) {
                            matches = false;
                            break;
                        }
                    }

                    if (matches) { // finally, check return type
                        if (m.getReturnType().equals(returnType) )
                            return m;
                    }
                }
            }
        }

        throw new InternalError("Enclosing method not found");
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:66,代码来源:Class.java

示例8: getGenericInfo

import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
private MethodRepository getGenericInfo() {
    throw new UnsupportedOperationException();
}
 
开发者ID:stephanenicolas,项目名称:reflection-no-reflection,代码行数:4,代码来源:Method.java


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