本文整理汇总了Java中javax.lang.model.type.DeclaredType.getTypeArguments方法的典型用法代码示例。如果您正苦于以下问题:Java DeclaredType.getTypeArguments方法的具体用法?Java DeclaredType.getTypeArguments怎么用?Java DeclaredType.getTypeArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.DeclaredType
的用法示例。
在下文中一共展示了DeclaredType.getTypeArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: typeToTypeDeclaration
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private TypeDeclaration typeToTypeDeclaration(TypeMirror tMirror){
int dimension = 0;
TypeMirror aType = tMirror;
ITypeDeclaration[] generics = null;
if(tMirror.getKind() == TypeKind.ARRAY){
for(;aType.getKind() == TypeKind.ARRAY; aType = ((ArrayType)tMirror).getComponentType()) {
dimension++;
}
}
if(aType.getKind() == TypeKind.DECLARED){
DeclaredType dType = (DeclaredType) aType;
List<? extends TypeMirror> parameters = dType.getTypeArguments();
if( parameters!=null && parameters.size()>0){
generics = new ITypeDeclaration[parameters.size()];
int i=0;
for(TypeMirror gType: parameters){
generics[i] = typeToTypeDeclaration(gType);
i++;
}
}
}
return new TypeDeclaration(owner, generics, dimension);
}
示例2: hasUncheckedWarning
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
static boolean hasUncheckedWarning(TypeMirror type) {
switch (type.getKind()) {
case DECLARED:
DeclaredType declared = (DeclaredType) type;
for (TypeMirror typeParam : declared.getTypeArguments()) {
if (hasUncheckedWarning(typeParam)) {
return true;
}
}
return false;
case TYPEVAR:
return true;
case WILDCARD:
return ((WildcardType) type).getExtendsBound() != null;
case ARRAY:
return hasUncheckedWarning(((ArrayType) type).getComponentType());
default:
return false;
}
}
示例3: visitDeclared
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
@Override
public TypeMirror visitDeclared(DeclaredType t, CompilationInfo p) {
if (t.getTypeArguments().isEmpty()) {
return t;
}
List<TypeMirror> newArgs = new ArrayList<TypeMirror>(t.getTypeArguments().size());
for (TypeMirror tm : t.getTypeArguments()) {
newArgs.add(visit(tm, p));
}
TypeMirror enclosing = t.getEnclosingType();
if (enclosing != null) {
enclosing = visit(enclosing, p);
}
return p.getTypes().getDeclaredType(
(DeclaredType)enclosing,
(TypeElement)t.asElement(),
newArgs.toArray(new TypeMirror[newArgs.size()]));
}
示例4: findLookupMergerType
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private DeclaredType findLookupMergerType(DeclaredType t) {
String rawName = processingEnv.getTypeUtils().erasure(t).toString();
if (rawName.equals(LookupMerger.class.getName())) {
List<? extends TypeMirror> args = t.getTypeArguments();
if (args.size() == 1) {
return (DeclaredType) args.get(0);
} else {
return null;
}
}
for (TypeMirror supe : processingEnv.getTypeUtils().directSupertypes(t)) {
DeclaredType result = findLookupMergerType((DeclaredType) supe);
if (result != null) {
return result;
}
}
return null;
}
示例5: isSubtypeOfType
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
static boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
if (isTypeEqual(typeMirror, otherType)) {
return true;
}
if (typeMirror.getKind() != TypeKind.DECLARED) {
return false;
}
DeclaredType declaredType = (DeclaredType) typeMirror;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.size() > 0) {
StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
typeString.append('<');
for (int i = 0; i < typeArguments.size(); i++) {
if (i > 0) {
typeString.append(',');
}
typeString.append('?');
}
typeString.append('>');
if (typeString.toString().equals(otherType)) {
return true;
}
}
Element element = declaredType.asElement();
if (!(element instanceof TypeElement)) {
return false;
}
TypeElement typeElement = (TypeElement) element;
TypeMirror superType = typeElement.getSuperclass();
if (isSubtypeOfType(superType, otherType)) {
return true;
}
for (TypeMirror interfaceType : typeElement.getInterfaces()) {
if (isSubtypeOfType(interfaceType, otherType)) {
return true;
}
}
return false;
}
示例6: visitDeclared
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
@Override
public TypeMirror visitDeclared(DeclaredType t, Types types) {
if (TypeModeler.isSubElement((TypeElement) t.asElement(), collectionType)
|| TypeModeler.isSubElement((TypeElement) t.asElement(), mapType)) {
Collection<? extends TypeMirror> args = t.getTypeArguments();
TypeMirror[] safeArgs = new TypeMirror[args.size()];
int i = 0;
for (TypeMirror arg : args) {
safeArgs[i++] = visit(arg, types);
}
return types.getDeclaredType((TypeElement) t.asElement(), safeArgs);
}
return types.erasure(t);
}
示例7: visitDeclared
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
@Override
public Type visitDeclared(DeclaredType t, Type.Parameters p) {
Type.Reference reference = factory.reference(qualifiedNameOf(t));
List<? extends TypeMirror> typeArguments = t.getTypeArguments();
if (typeArguments.isEmpty()) {
return reference;
}
List<Type.Nonprimitive> args = new ArrayList<>();
for (TypeMirror a : typeArguments) {
args.add((Type.Nonprimitive) a.accept(this, p));
}
return factory.parameterized(reference, args);
}
示例8: getParameterizedTypes
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static List<TypeMirror> getParameterizedTypes(TypeMirror typeMirror) {
if (!(typeMirror instanceof DeclaredType)) {
return null;
}
DeclaredType declaredType = (DeclaredType)typeMirror;
return (List<TypeMirror>)declaredType.getTypeArguments();
}
示例9: isSubtypeOfType
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
if (otherType.equals(typeMirror.toString())) {
return true;
}
if (!(typeMirror instanceof DeclaredType)) {
return false;
}
DeclaredType declaredType = (DeclaredType) typeMirror;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.size() > 0) {
StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
typeString.append('<');
for (int i = 0; i < typeArguments.size(); i++) {
if (i > 0) {
typeString.append(',');
}
typeString.append('?');
}
typeString.append('>');
if (typeString.toString().equals(otherType)) {
return true;
}
}
Element element = declaredType.asElement();
if (!(element instanceof TypeElement)) {
return false;
}
TypeElement typeElement = (TypeElement) element;
if (isSubtypeOfType(typeElement.getSuperclass(), otherType)) {
return true;
}
for (TypeMirror interfaceType : typeElement.getInterfaces()) {
if (isSubtypeOfType(interfaceType, otherType)) {
return true;
}
}
return false;
}
示例10: containsErrorsRecursively
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
public static boolean containsErrorsRecursively(TypeMirror tm) {
switch (tm.getKind()) {
case ERROR:
return true;
case DECLARED:
DeclaredType type = (DeclaredType) tm;
for (TypeMirror t : type.getTypeArguments()) {
if (containsErrorsRecursively(t))
return true;
}
return false;
case ARRAY:
return containsErrorsRecursively(((ArrayType) tm).getComponentType());
case WILDCARD:
if (((WildcardType) tm).getExtendsBound() != null && containsErrorsRecursively(((WildcardType) tm).getExtendsBound())) {
return true;
}
if (((WildcardType) tm).getSuperBound() != null && containsErrorsRecursively(((WildcardType) tm).getSuperBound())) {
return true;
}
return false;
case OTHER:
return true;
default:
return false;
}
}
示例11: appendTypeArguments
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
void appendTypeArguments(DeclaredType type, StringBuilder sb) {
List<? extends TypeMirror> arguments = type.getTypeArguments();
if (!arguments.isEmpty()) {
sb.append("<");
String sep = "";
for (TypeMirror argument : arguments) {
sb.append(sep);
sep = ", ";
visit(argument, sb);
}
sb.append(">");
}
}
示例12: resolveCapturedTypeInt
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
/**
* Note: may return {@code null}, if an intersection type is encountered, to indicate a
* real type cannot be created.
*/
private static TypeMirror resolveCapturedTypeInt(CompilationInfo info, TypeMirror tm) {
if (tm == null) return tm;
TypeMirror orig = SourceUtils.resolveCapturedType(tm);
if (orig != null) {
tm = orig;
}
if (tm.getKind() == TypeKind.WILDCARD) {
TypeMirror extendsBound = ((WildcardType) tm).getExtendsBound();
TypeMirror superBound = ((WildcardType) tm).getSuperBound();
if (extendsBound != null || superBound != null) {
TypeMirror rct = resolveCapturedTypeInt(info, extendsBound != null ? extendsBound : superBound);
if (rct != null) {
switch (rct.getKind()) {
case WILDCARD:
return rct;
case ARRAY:
case DECLARED:
case ERROR:
case TYPEVAR:
case OTHER:
return info.getTypes().getWildcardType(
extendsBound != null ? rct : null, superBound != null ? rct : null);
}
} else {
// propagate failure out of all wildcards
return null;
}
}
} else if (tm.getKind() == TypeKind.INTERSECTION) {
return null;
}
if (tm.getKind() == TypeKind.DECLARED) {
DeclaredType dt = (DeclaredType) tm;
List<TypeMirror> typeArguments = new LinkedList<TypeMirror>();
for (TypeMirror t : dt.getTypeArguments()) {
TypeMirror targ = resolveCapturedTypeInt(info, t);
if (targ == null) {
// bail out, if the type parameter is a wildcard, it's probably not possible
// to create a proper parametrized type from it
if (t.getKind() == TypeKind.WILDCARD || t.getKind() == TypeKind.INTERSECTION) {
return null;
}
// use rawtype
typeArguments.clear();
break;
}
typeArguments.add(targ);
}
final TypeMirror enclosingType = dt.getEnclosingType();
if (enclosingType.getKind() == TypeKind.DECLARED) {
return info.getTypes().getDeclaredType((DeclaredType) enclosingType, (TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
} else {
if (dt.asElement() == null) return dt;
return info.getTypes().getDeclaredType((TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
}
}
if (tm.getKind() == TypeKind.ARRAY) {
ArrayType at = (ArrayType) tm;
TypeMirror tm2 = resolveCapturedTypeInt(info, at.getComponentType());
return info.getTypes().getArrayType(tm2 != null ? tm2 : tm);
}
return tm;
}
示例13: DeclaredTypeMoniker
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
public DeclaredTypeMoniker(DeclaredType type) {
typeDeclName = ((TypeElement) type.asElement()).getQualifiedName();
for (TypeMirror arg : type.getTypeArguments())
typeArgs.add(TypeMonikerFactory.getTypeMoniker(arg));
}
示例14: fixGenericTypes
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private <E extends Tree> E fixGenericTypes(E tree, final TreePath path, final Element member) {
final Map<TypeMirror, TypeParameterElement> mappings = new HashMap<TypeMirror, TypeParameterElement>();
DeclaredType declaredType = (DeclaredType) sourceType.asType();
for (TypeMirror typeMirror : declaredType.getTypeArguments()) {
DeclaredType currentElement = declaredType;
deepSearchTypes(currentElement, typeMirror, typeMirror, mappings);
}
final Types types = workingCopy.getTypes();
final Map<IdentifierTree, Tree> original2Translated = new HashMap<IdentifierTree, Tree>();
ErrorAwareTreeScanner<Void, Void> scanner = new ErrorAwareTreeScanner<Void, Void>() {
@Override
public Void visitIdentifier(IdentifierTree node, Void p) {
Element element = workingCopy.getTrees().getElement(new TreePath(path, node));
if (element != null && element.getKind() == ElementKind.TYPE_PARAMETER) {
Element typeElement = types.asElement(element.asType());
if (typeElement != null && typeElement.getKind() == ElementKind.TYPE_PARAMETER) {
TypeParameterElement parameterElement = (TypeParameterElement) typeElement;
Element genericElement = parameterElement.getGenericElement();
if (genericElement != member) {
// genericElement is niet gelijk aan het te verplaatsen element. Dus we moeten deze veranderen.
// Is het parameterElement gebruikt bij het maken van de superclass
Tree type;
TypeParameterElement target = mappings.get(parameterElement.asType());
if (target != null) {
type = make.Type(target.asType());
} else {
List<? extends TypeMirror> bounds = parameterElement.getBounds();
if (bounds.isEmpty()) {
type = make.Type("Object"); // NOI18N
} else {
type = make.Type(bounds.get(0));
}
}
original2Translated.put(node, type);
}
}
}
return super.visitIdentifier(node, p);
}
};
scanner.scan(tree, null);
E result = (E) workingCopy.getTreeUtilities().translate(tree, original2Translated);
return result;
}
示例15: addEventSource
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private void addEventSource(ExecutableElement m) {
if (consumed) {
return;
}
String sn = m.getSimpleName().toString();
if (!isAccessible(m, false)) {
return;
}
if (!sn.startsWith(EVENT_PREFIX) || sn.length() == EVENT_PREFIX_LEN) {
return;
}
if (m.getParameters().size() != 1) {
return;
}
VariableElement param = m.getParameters().get(0);
TypeMirror varType = param.asType();
// the type must be assignable to the event handler
if (compilationInfo.getTypes().isAssignable(varType, getHandlerBaseType())) {
return;
}
ElementHandle<TypeElement> eventHandle = null;
String eventClassName = null;
if (varType.getKind() == TypeKind.DECLARED) {
// extract event type as the type of event / argument for the event handler method
DeclaredType dt = (DeclaredType)varType;
List<? extends TypeMirror> tParams = dt.getTypeArguments();
if (tParams.size() != 1) {
// something very wrong, the event handler has just 1 type parameter
//throw new IllegalStateException();
return;
}
TypeMirror eventType = tParams.get(0);
if (eventType.getKind() == TypeKind.WILDCARD) {
TypeMirror t = ((WildcardType)eventType).getSuperBound();
if (t == null) {
t = ((WildcardType)eventType).getExtendsBound();
}
eventType = t;
}
if (eventType.getKind() != TypeKind.DECLARED) {
throw new IllegalStateException();
}
TypeElement te = (TypeElement)compilationInfo.getTypes().asElement(eventType);
eventClassName = te.getQualifiedName().toString();
eventHandle = ElementHandle.create(te);
addDependency(eventType);
}
String eventName = Character.toLowerCase(sn.charAt(EVENT_PREFIX_LEN)) + sn.substring(EVENT_PREFIX_LEN + 1);
FxEvent ei = new FxEvent(eventName);
ei.setEventClassName(eventClassName);
ei.setEventType(eventHandle);
addEvent(ei);
consumed = true;
}