本文整理匯總了Java中java.lang.reflect.GenericDeclaration類的典型用法代碼示例。如果您正苦於以下問題:Java GenericDeclaration類的具體用法?Java GenericDeclaration怎麽用?Java GenericDeclaration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GenericDeclaration類屬於java.lang.reflect包,在下文中一共展示了GenericDeclaration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: equals
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
@Override
public boolean equals(Object o) {
if (o instanceof TypeVariable) {
TypeVariable that = (TypeVariable) o;
GenericDeclaration thatDecl = that.getGenericDeclaration();
String thatName = that.getName();
return
(genericDeclaration == null ?
thatDecl == null :
genericDeclaration.equals(thatDecl)) &&
(name == null ?
thatName == null :
name.equals(thatName));
} else
return false;
}
示例2: translateTypeVariable
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
private static Type translateTypeVariable(Map<String, Type> lookup, TypeVariable var) {
GenericDeclaration declaredBy = var.getGenericDeclaration();
if (!(declaredBy instanceof Class)) {
// if the <T> is not defined by class, there is no way to get the actual type
return Object.class;
}
Class clazz = (Class) declaredBy;
Type actualType = lookup.get(var.getName() + "@" + clazz.getCanonicalName());
if (actualType == null) {
// should not happen
return Object.class;
}
if (actualType instanceof TypeVariable) {
// translate to another variable, try again
return translateTypeVariable(lookup, (TypeVariable) actualType);
}
return actualType;
}
示例3: createByParamName
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
private static JavaType createByParamName(final ImplementClass implementClass, final TypeVariable<?> variable) {
GenericDeclaration declaration = variable.getGenericDeclaration();
String name = variable.getName();
TypeVariable<?>[] typeParameters = declaration.getTypeParameters();
for (int index = 0; index < typeParameters.length; index++) {
TypeVariable<?> type = typeParameters[index];
if (name.equals(type.getName())) {
if (declaration instanceof Class) {
Class<?> declarationClass = (Class<?>) declaration;
Class<?> sub = implementClass.getSubclass(declarationClass);
if (sub != null) {
Type genericSuperclass = implementClass.getGenericParentClass(declarationClass);
if (genericSuperclass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
return create(implementClass, parameterizedType.getActualTypeArguments()[index]);
}
// Generics未指定
}
return new VariableJavaType(implementClass, type);
} else if (declaration instanceof Executable) {
return new VariableJavaType(implementClass, type);
}
}
}
throw new IllegalArgumentException();
}
示例4: getInheritGenericType
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
Type type = null;
GenericDeclaration gd = tv.getGenericDeclaration();
do {
type = clazz.getGenericSuperclass();
if (type == null) {
return null;
}
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
if (ptype.getRawType() == gd) {
TypeVariable<?>[] tvs = gd.getTypeParameters();
Type[] types = ptype.getActualTypeArguments();
for (int i = 0; i < tvs.length; i++) {
if (tvs[i] == tv) return types[i];
}
return null;
}
}
clazz = TypeUtils.getClass(type);
} while (type != null);
return null;
}
示例5: enhanceExecutable
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
protected <T extends Member & GenericDeclaration> void enhanceExecutable(JvmExecutable result, T member,
String simpleName, Type[] parameterTypes, Annotation[][] annotations, int offset) {
StringBuilder fqName = new StringBuilder(48);
fqName.append(member.getDeclaringClass().getName());
fqName.append('.');
fqName.append(simpleName);
fqName.append('(');
InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>)result.getParameters();
for (int typeIdx = offset, annotationIdx = annotations.length - parameterTypes.length + offset; typeIdx < parameterTypes.length; typeIdx++, annotationIdx++) {
if (typeIdx != offset)
fqName.append(',');
Type parameterType = parameterTypes[typeIdx];
uriHelper.computeTypeName(parameterType, fqName);
parameters.addUnique(
createFormalParameter(parameterType, "arg" + (typeIdx - offset), result, member,
annotations[annotationIdx]));
}
fqName.append(')');
result.internalSetIdentifier(fqName.toString());
result.setSimpleName(simpleName);
setVisibility(result, member.getModifiers());
}
示例6: createFormalParameter
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
protected JvmFormalParameter createFormalParameter(Type parameterType, String paramName,
JvmMember container, GenericDeclaration member, Annotation[] annotations) {
JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter();
result.setName(paramName);
if (isLocal(parameterType, member)) {
result.setParameterType(createLocalTypeReference(parameterType, (JvmTypeParameterDeclarator) container,
member));
} else {
result.setParameterType(createTypeReference(parameterType));
}
if (annotations.length != 0) {
InternalEList<JvmAnnotationReference> annotationsReferences = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
for (Annotation annotation : annotations) {
annotationsReferences.addUnique(createAnnotationReference(annotation));
}
}
return result;
}
示例7: getInheritGenericType
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
Type type = null;
GenericDeclaration gd = tv.getGenericDeclaration();
do {
type = clazz.getGenericSuperclass();
if (type == null) {
return null;
}
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
if (ptype.getRawType() == gd) {
TypeVariable<?>[] tvs = gd.getTypeParameters();
Type[] types = ptype.getActualTypeArguments();
for (int i = 0; i < tvs.length; i++) {
if (tvs[i] == tv)
return types[i];
}
return null;
}
}
clazz = TypeUtils.getClass(type);
} while (type != null);
return null;
}
示例8: resolve
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
Type resolve()
{
GenericDeclaration d = decl;
while (d != null)
{
for (TypeVariable t : d.getTypeParameters())
{
if (t.getName().equals(name))
{
return t;
}
}
d = getParent(d);
}
throw new MalformedParameterizedTypeException();
}
示例9: resolve
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
private static Type resolve(TypeVariable<? extends GenericDeclaration> value, Set<ParameterizedType> types) {
GenericDeclaration genericDeclaration = value.getGenericDeclaration();
if (genericDeclaration instanceof Class<?>) {
Class<?> clazz = (Class<?>) genericDeclaration;
Optional<ParameterizedType> matching = types.stream()
.filter(type -> type.getRawType() == clazz)
.sorted(Types::byMostConcrete)
.findFirst();
if (matching.isPresent()) {
TypeVariable<?>[] params = genericDeclaration.getTypeParameters();
Type[] actual = matching.get().getActualTypeArguments();
for (int i = 0; i < params.length && i < actual.length; i++) {
if (params[i] == value) {
return actual[i];
}
}
}
}
return value;
}
示例10: toLongString
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
/**
* Format a {@link TypeVariable} including its {@link GenericDeclaration}.
*
* @param var the type variable to create a String representation for, not {@code null}
* @return String
* @since 3.2
*/
public static String toLongString(final TypeVariable<?> var) {
Validate.notNull(var, "var is null");
final StringBuilder buf = new StringBuilder();
final GenericDeclaration d = ((TypeVariable<?>) var).getGenericDeclaration();
if (d instanceof Class<?>) {
Class<?> c = (Class<?>) d;
while (true) {
if (c.getEnclosingClass() == null) {
buf.insert(0, c.getName());
break;
}
buf.insert(0, c.getSimpleName()).insert(0, '.');
c = c.getEnclosingClass();
}
} else if (d instanceof Type) {// not possible as of now
buf.append(toString((Type) d));
} else {
buf.append(d);
}
return buf.append(':').append(typeVariableToString(var)).toString();
}
示例11: resolve
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
void resolve() {
if (formalVar != null) {
return;
}
GenericDeclaration curLayer = declOfVarUser;
TypeVariable var;
while ((var = findFormalVar(curLayer, name)) == null) {
curLayer = nextLayer(curLayer);
if (curLayer == null) {
throw new AssertionError("illegal type variable reference");
}
}
formalVar = (TypeVariableImpl<D>) var;
this.genericDeclaration = formalVar.genericDeclaration;
this.bounds = formalVar.bounds;
}
示例12: parseForClass
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
/**
* Parses the generic signature of a class and creates the data structure
* representing the signature.
*
* @param genericDecl the GenericDeclaration calling this method
* @param signature the generic signature of the class
*/
public void parseForClass(GenericDeclaration genericDecl, String signature) {
setInput(genericDecl, signature);
if (!eof) {
parseClassSignature();
} else {
if(genericDecl instanceof Class) {
Class c = (Class) genericDecl;
this.formalTypeParameters = EmptyArray.TYPE_VARIABLE;
this.superclassType = c.getSuperclass();
Class<?>[] interfaces = c.getInterfaces();
if (interfaces.length == 0) {
this.interfaceTypes = ListOfTypes.EMPTY;
} else {
this.interfaceTypes = new ListOfTypes(interfaces);
}
} else {
this.formalTypeParameters = EmptyArray.TYPE_VARIABLE;
this.superclassType = Object.class;
this.interfaceTypes = ListOfTypes.EMPTY;
}
}
}
示例13: parseForMethod
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
/**
* Parses the generic signature of a method and creates the data structure
* representing the signature.
*
* @param genericDecl the GenericDeclaration calling this method
* @param signature the generic signature of the class
*/
public void parseForMethod(GenericDeclaration genericDecl,
String signature, Class<?>[] rawExceptionTypes) {
setInput(genericDecl, signature);
if (!eof) {
parseMethodTypeSignature(rawExceptionTypes);
} else {
Method m = (Method) genericDecl;
this.formalTypeParameters = EmptyArray.TYPE_VARIABLE;
Class<?>[] parameterTypes = m.getParameterTypes();
if (parameterTypes.length == 0) {
this.parameterTypes = ListOfTypes.EMPTY;
} else {
this.parameterTypes = new ListOfTypes(parameterTypes);
}
Class<?>[] exceptionTypes = m.getExceptionTypes();
if (exceptionTypes.length == 0) {
this.exceptionTypes = ListOfTypes.EMPTY;
} else {
this.exceptionTypes = new ListOfTypes(exceptionTypes);
}
this.returnType = m.getReturnType();
}
}
示例14: parseForConstructor
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
/**
* Parses the generic signature of a constructor and creates the data
* structure representing the signature.
*
* @param genericDecl the GenericDeclaration calling this method
* @param signature the generic signature of the class
*/
public void parseForConstructor(GenericDeclaration genericDecl,
String signature, Class<?>[] rawExceptionTypes) {
setInput(genericDecl, signature);
if (!eof) {
parseMethodTypeSignature(rawExceptionTypes);
} else {
Constructor c = (Constructor) genericDecl;
this.formalTypeParameters = EmptyArray.TYPE_VARIABLE;
Class<?>[] parameterTypes = c.getParameterTypes();
if (parameterTypes.length == 0) {
this.parameterTypes = ListOfTypes.EMPTY;
} else {
this.parameterTypes = new ListOfTypes(parameterTypes);
}
Class<?>[] exceptionTypes = c.getExceptionTypes();
if (exceptionTypes.length == 0) {
this.exceptionTypes = ListOfTypes.EMPTY;
} else {
this.exceptionTypes = new ListOfTypes(exceptionTypes);
}
}
}
示例15: parseFormalTypeParameter
import java.lang.reflect.GenericDeclaration; //導入依賴的package包/類
TypeVariableImpl<GenericDeclaration> parseFormalTypeParameter() {
// FormalTypeParameter ::= Ident ClassBound {InterfaceBound}.
scanIdentifier();
String name = identifier.intern(); // FIXME: is this o.k.?
ListOfTypes bounds = new ListOfTypes(8);
// ClassBound ::= ":" [FieldTypeSignature].
expect(':');
if (symbol == 'L' || symbol == '[' || symbol == 'T') {
bounds.add(parseFieldTypeSignature());
}
while (symbol == ':') {
// InterfaceBound ::= ":" FieldTypeSignature.
scanSymbol();
bounds.add(parseFieldTypeSignature());
}
return new TypeVariableImpl<GenericDeclaration>(genericDecl, name, bounds);
}