本文整理汇总了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
}
示例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
}
示例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
}
示例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();
}
示例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");
}
}
示例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");
}
}
示例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");
}
}
示例8: getGenericInfo
import sun.reflect.generics.repository.MethodRepository; //导入依赖的package包/类
private MethodRepository getGenericInfo() {
throw new UnsupportedOperationException();
}