当前位置: 首页>>代码示例>>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;未经允许,请勿转载。