當前位置: 首頁>>代碼示例>>Java>>正文


Java GenericDeclaration類代碼示例

本文整理匯總了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;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:20,代碼來源:TypeVariableImpl.java

示例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;
}
 
開發者ID:zdongcoding,項目名稱:jsouplib,代碼行數:19,代碼來源:Resource.java

示例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();
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:27,代碼來源:JavaType.java

示例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;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:24,代碼來源:FieldInfo.java

示例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());
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:23,代碼來源:ReflectionTypeFactory.java

示例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;
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:19,代碼來源:ReflectionTypeFactory.java

示例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;
}
 
開發者ID:BigAppOS,項目名稱:BigApp_Discuz_Android,代碼行數:25,代碼來源:FieldInfo.java

示例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();
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:17,代碼來源:GenericSignatureParser.java

示例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;
}
 
開發者ID:almondtools,項目名稱:testrecorder,代碼行數:21,代碼來源:Types.java

示例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();
}
 
開發者ID:rogerxaic,項目名稱:gestock,代碼行數:29,代碼來源:TypeUtils.java

示例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;
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:17,代碼來源:TypeVariableImpl.java

示例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;
        }
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:30,代碼來源:GenericSignatureParser.java

示例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();
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:31,代碼來源:GenericSignatureParser.java

示例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);
        }
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:30,代碼來源:GenericSignatureParser.java

示例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);
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:23,代碼來源:GenericSignatureParser.java


注:本文中的java.lang.reflect.GenericDeclaration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。