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


Java TypeVariable類代碼示例

本文整理匯總了Java中javax.lang.model.type.TypeVariable的典型用法代碼示例。如果您正苦於以下問題:Java TypeVariable類的具體用法?Java TypeVariable怎麽用?Java TypeVariable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeVariable類屬於javax.lang.model.type包,在下文中一共展示了TypeVariable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitTypeVariable

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
@Override
public StringBuilder visitTypeVariable(TypeVariable t, Boolean p) {
    Element e = t.asElement();
    if (e != null) {
        String name = e.getSimpleName().toString();
        if (!CAPTURED_WILDCARD.equals(name))
            return DEFAULT_VALUE.append(name);
    }
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getLowerBound();
    if (bound != null && bound.getKind() != TypeKind.NULL) {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    } else {
        bound = t.getUpperBound();
        if (bound != null && bound.getKind() != TypeKind.NULL) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.TYPEVAR)
                bound = ((TypeVariable)bound).getLowerBound();
            visit(bound, p);
        }
    }
    return DEFAULT_VALUE;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:SpringXMLConfigCompletionItem.java

示例2: verifyTypeVarAccessible

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
private static boolean verifyTypeVarAccessible(ExecutableElement method, TypeMirror forType, List<Element> usedLocalTypeVariables, Element target) {
    Collection<TypeVariable> typeVars = Utilities.containedTypevarsRecursively(forType);
    
    if (method != null) {
        for (Iterator<TypeVariable> it = typeVars.iterator(); it.hasNext(); ) {
            TypeVariable tvar = it.next();
            Element tvarEl = tvar.asElement();

            if (method.getTypeParameters().contains(tvarEl)) {
                usedLocalTypeVariables.add(tvarEl);
                it.remove();
            }
        }
    }
    
    return allTypeVarsAccessible(typeVars, target);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:Utilities.java

示例3: containedTypevarsRecursively

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
private static void containedTypevarsRecursively(@NonNull TypeMirror tm, @NonNull Collection<TypeVariable> typeVars) {
    switch (tm.getKind()) {
        case TYPEVAR:
            typeVars.add((TypeVariable) tm);
            break;
        case DECLARED:
            DeclaredType type = (DeclaredType) tm;
            for (TypeMirror t : type.getTypeArguments()) {
                containedTypevarsRecursively(t, typeVars);
            }

            break;
        case ARRAY:
            containedTypevarsRecursively(((ArrayType) tm).getComponentType(), typeVars);
            break;
        case WILDCARD:
            if (((WildcardType) tm).getExtendsBound() != null) {
                containedTypevarsRecursively(((WildcardType) tm).getExtendsBound(), typeVars);
            }
            if (((WildcardType) tm).getSuperBound() != null) {
                containedTypevarsRecursively(((WildcardType) tm).getSuperBound(), typeVars);
            }
            break;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:Utilities.java

示例4: resolveTypeName

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
/**
 * uses FQNs where possible since javadoc does not match imports for
 * parameter types
 */
private CharSequence resolveTypeName(TypeMirror asType, boolean isVarArgs) {
    CharSequence ptype;
    if (asType.getKind() == TypeKind.DECLARED) {
        // snip generics
        Element e = ((DeclaredType) asType).asElement();
        ptype = e.getKind().isClass() || e.getKind().isInterface()
                ? ((TypeElement) e).getQualifiedName()
                : e.getSimpleName();
    } else if (asType.getKind() == TypeKind.TYPEVAR) {
        do {
            // Type Erasure JLS 4.6
            asType = ((TypeVariable) asType).getUpperBound();
        } while (asType.getKind() == TypeKind.TYPEVAR);
        ptype = resolveTypeName(asType, isVarArgs);
    } else if (isVarArgs && asType.getKind() == TypeKind.ARRAY) {
        ptype = resolveTypeName(((ArrayType)asType).getComponentType(), false) + "..."; //NOI18N
    } else {
        ptype = asType.toString();
    }
    
    return ptype;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:JavadocCompletionItem.java

示例5: visitTypeVariable

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
@Override
public Void visitTypeVariable(TypeVariable type, Void p) {
    Element e = type.asElement();
    if (e != null) {
        CharSequence name = e.getSimpleName();
        if (!CAPTURED_WILDCARD.contentEquals(name)) {
            builder.append(name);
            return null;
        }
    }
    builder.append("?"); //NOI18N
    TypeMirror bound = type.getLowerBound();
    if (bound != null && bound.getKind() != TypeKind.NULL) {
        builder.append(" super "); //NOI18N
        visit(bound);
    } else {
        bound = type.getUpperBound();
        if (bound != null && bound.getKind() != TypeKind.NULL) {
            builder.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.TYPEVAR)
                bound = ((TypeVariable)bound).getLowerBound();
            visit(bound);
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:AutoImport.java

示例6: getMethodParameterTypes

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
/**
 * 取得方法參數類型列表
 */
private List<String> getMethodParameterTypes(ExecutableElement executableElement) {
    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    if (methodParameters.size() == 0) {
        return null;
    }
    List<String> types = new ArrayList<>();
    for (VariableElement variableElement : methodParameters) {
        TypeMirror methodParameterType = variableElement.asType();
        if (methodParameterType instanceof TypeVariable) {
            TypeVariable typeVariable = (TypeVariable) methodParameterType;
            methodParameterType = typeVariable.getUpperBound();
        }
        types.add(methodParameterType.toString());
    }
    return types;
}
 
開發者ID:jutao,項目名稱:GankReader,代碼行數:20,代碼來源:OnceClickProcessor.java

示例7: getErasedType

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
static String getErasedType(TypeMirror type) {
    switch (type.getKind()) {
        case DECLARED:
            DeclaredType declared = (DeclaredType) type;
            TypeElement element = (TypeElement) declared.asElement();
            return element.getQualifiedName().toString();
        case TYPEVAR:
            return getErasedType(((TypeVariable) type).getUpperBound());
        case WILDCARD:
            return getErasedType(((WildcardType) type).getExtendsBound());
        case ARRAY:
            return getErasedType(((ArrayType) type).getComponentType()) + "[]";
        default:
            return type.toString();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:GeneratedPlugin.java

示例8: appendSimpleTypeName

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
private static void appendSimpleTypeName(StringBuilder ret, TypeMirror type) {
    switch (type.getKind()) {
        case DECLARED:
            DeclaredType declared = (DeclaredType) type;
            TypeElement element = (TypeElement) declared.asElement();
            ret.append(element.getSimpleName());
            break;
        case TYPEVAR:
            appendSimpleTypeName(ret, ((TypeVariable) type).getUpperBound());
            break;
        case WILDCARD:
            appendSimpleTypeName(ret, ((WildcardType) type).getExtendsBound());
            break;
        case ARRAY:
            appendSimpleTypeName(ret, ((ArrayType) type).getComponentType());
            ret.append("Array");
            break;
        default:
            ret.append(type);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:PluginGenerator.java

示例9: visitTypeVariable

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
@Override
public Boolean visitTypeVariable(TypeVariable a, EqualVisitorParam p) {
    if (p.type.getKind().equals(TYPEVAR)) {
        TypeVariable b = (TypeVariable) p.type;
        TypeParameterElement aElement = (TypeParameterElement) a.asElement();
        TypeParameterElement bElement = (TypeParameterElement) b.asElement();
        Set<ComparedElements> newVisiting = visitingSetPlus(p.visiting, aElement, bElement);
        if (newVisiting.equals(p.visiting)) {
            // We're already visiting this pair of elements.
            // This can happen with our friend Eclipse when looking at <T extends Comparable<T>>.
            // It incorrectly reports the upper bound of T as T itself.
            return true;
        }
        // We use aElement.getBounds() instead of a.getUpperBound() to avoid having to deal with
        // the different way intersection types (like <T extends Number & Comparable<T>>) are
        // represented before and after Java 8. We do have an issue that this code may consider
        // that <T extends Foo & Bar> is different from <T extends Bar & Foo>, but it's very
        // hard to avoid that, and not likely to be much of a problem in practice.
        return equalLists(aElement.getBounds(), bElement.getBounds(), newVisiting)
                && equal(a.getLowerBound(), b.getLowerBound(), newVisiting)
                && a.asElement().getSimpleName().equals(b.asElement().getSimpleName());
    }
    return false;
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:25,代碼來源:MoreTypes.java

示例10: get

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
/**
 * Make a TypeVariableName for the given TypeMirror. This form is used internally to avoid
 * infinite recursion in cases like {@code Enum<E extends Enum<E>>}. When we encounter such a
 * thing, we will make a TypeVariableName without bounds and add that to the {@code typeVariables}
 * map before looking up the bounds. Then if we encounter this TypeVariable again while
 * constructing the bounds, we can just return it from the map. And, the code that put the entry
 * in {@code variables} will make sure that the bounds are filled in before returning.
 */
static com.wrmsr.wava.java.poet.TypeVariableName get(
        TypeVariable mirror, Map<TypeParameterElement, com.wrmsr.wava.java.poet.TypeVariableName> typeVariables)
{
    TypeParameterElement element = (TypeParameterElement) mirror.asElement();
    com.wrmsr.wava.java.poet.TypeVariableName typeVariableName = typeVariables.get(element);
    if (typeVariableName == null) {
        // Since the bounds field is public, we need to make it an unmodifiableList. But we control
        // the List that that wraps, which means we can change it before returning.
        List<TypeName> bounds = new ArrayList<>();
        List<TypeName> visibleBounds = Collections.unmodifiableList(bounds);
        typeVariableName = new com.wrmsr.wava.java.poet.TypeVariableName(element.getSimpleName().toString(), visibleBounds);
        typeVariables.put(element, typeVariableName);
        for (TypeMirror typeMirror : element.getBounds()) {
            bounds.add(TypeName.get(typeMirror, typeVariables));
        }
        bounds.remove(OBJECT);
    }
    return typeVariableName;
}
 
開發者ID:wrmsr,項目名稱:wava,代碼行數:28,代碼來源:TypeVariableName.java

示例11: get

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
/**
 * Make a TypeVariableName for the given TypeMirror. This form is used internally to avoid
 * infinite recursion in cases like {@code Enum<E extends Enum<E>>}. When we encounter such a
 * thing, we will make a TypeVariableName without bounds and add that to the {@code typeVariables}
 * map before looking up the bounds. Then if we encounter this TypeVariable again while
 * constructing the bounds, we can just return it from the map. And, the code that put the entry
 * in {@code variables} will make sure that the bounds are filled in before returning.
 */
static TypeVariableName get(
        TypeVariable mirror, Map<TypeParameterElement, TypeVariableName> typeVariables) {
    TypeParameterElement element = (TypeParameterElement) mirror.asElement();
    TypeVariableName typeVariableName = typeVariables.get(element);
    if (typeVariableName == null) {
        // Since the bounds field is public, we need to make it an unmodifiableList. But we control
        // the List that that wraps, which means we can change it before returning.
        List<TypeName> bounds = new ArrayList<>();
        List<TypeName> visibleBounds = Collections.unmodifiableList(bounds);
        typeVariableName = new TypeVariableName(element.getSimpleName().toString(), visibleBounds);
        typeVariables.put(element, typeVariableName);
        for (TypeMirror typeMirror : element.getBounds()) {
            bounds.add(TypeName.get(typeMirror, typeVariables));
        }
        bounds.remove(OBJECT);
    }
    return typeVariableName;
}
 
開發者ID:flipkart-incubator,項目名稱:Lyrics,代碼行數:27,代碼來源:TypeVariableName.java

示例12: getFeatureParameterTypeVariableName

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
private TypeName getFeatureParameterTypeVariableName(DeclaredType featureType,
                                                     int featureParameterIndex) {
    Element paramElem = getFeatureParameterElement(featureType, featureParameterIndex);
    if (paramElem == null) {
        return null;
    }

    if (paramElem.getKind() == ElementKind.TYPE_PARAMETER) {
        return TypeVariableName.get((TypeVariable) paramElem.asType());

    } else if (paramElem.getKind() == ElementKind.CLASS) {
        return TypeName.get(paramElem.asType());
    }

    return null;
}
 
開發者ID:beworker,項目名稱:featured,代碼行數:17,代碼來源:Names.java

示例13: get

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
/**
 * Make a TypeVariableName for the given TypeMirror. This form is used internally to avoid
 * infinite recursion in cases like {@code Enum<E extends Enum<E>>}. When we encounter such a
 * thing, we will make a TypeVariableName without bounds and add that to the {@code typeVariables}
 * map before looking up the bounds. Then if we encounter this TypeVariable again while
 * constructing the bounds, we can just return it from the map. And, the code that put the entry
 * in {@code variables} will make sure that the bounds are filled in before returning.
 */
static TypeVariableName get(
    TypeVariable mirror, Map<TypeParameterElement, TypeVariableName> typeVariables) {
  TypeParameterElement element = (TypeParameterElement) mirror.asElement();
  TypeVariableName typeVariableName = typeVariables.get(element);
  if (typeVariableName == null) {
    // Since the bounds field is public, we need to make it an unmodifiableList. But we control
    // the List that that wraps, which means we can change it before returning.
    List<TypeName> bounds = new ArrayList<>();
    List<TypeName> visibleBounds = Collections.unmodifiableList(bounds);
    typeVariableName = new TypeVariableName(element.getSimpleName().toString(), visibleBounds);
    typeVariables.put(element, typeVariableName);
    for (TypeMirror typeMirror : element.getBounds()) {
      bounds.add(TypeName.get(typeMirror, typeVariables));
    }
    bounds.remove(OBJECT);
  }
  return typeVariableName;
}
 
開發者ID:Ufkoku,項目名稱:AndroidMVPHelper,代碼行數:27,代碼來源:TypeVariableName.java

示例14: visitTypeVariable

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
@Override public TypeKey visitTypeVariable(TypeVariable t, Set<TypeParameterElement> visited) {
  TypeParameterElement element = (TypeParameterElement) t.asElement();
  if (visited.contains(element)) {
    // This avoids infinite recursion with adapted types like <T extends Comparable<T>>.
    // It should probably check that T is bound correctly, but this is unlikely to be an issue
    // in the wild.
    return AnyKey.get(t.toString());
  }
  visited.add(element);
  ImmutableList.Builder<TypeKey> builder = ImmutableList.builder();
  for (TypeMirror bound : element.getBounds()) {
    TypeKey boundKey = bound.accept(this, visited);
    if (!boundKey.equals(OBJECT)) {
      builder.add(boundKey);
    }
  }
  ImmutableList<TypeKey> bounds = builder.build();
  if (bounds.size() == 0) {
    return AnyKey.get(t.toString());
  } else {
    return BoundedKey.get(t.toString(), bounds);
  }
}
 
開發者ID:grandstaish,項目名稱:paperparcel,代碼行數:24,代碼來源:TypeKey.java

示例15: AnnotationInfo

import javax.lang.model.type.TypeVariable; //導入依賴的package包/類
public AnnotationInfo(TypeMirror tm, String idProperty, boolean keepNonIdProperty,
		TypeMirror idGeneratorType, boolean customGenerator) {
	this.tm = tm;
	if (tm.getKind() != TypeKind.DECLARED) {
		throw new RuntimeException(tm + " should be declared");
	}
	DeclaredType dt = (DeclaredType) tm;
	List<? extends TypeMirror> typeArguments = dt.getTypeArguments();
	if (typeArguments != null) {
		for (TypeMirror tms : typeArguments) {
			if (tms instanceof TypeVariable) {
				typeVariables.add((TypeVariable) tms);
			} else if (tms instanceof WildcardType) {
				typeWildcards.add((WildcardType) tms);
			}
		}
	}
	this.idGeneratorType = idGeneratorType;
	this.customGenerator = customGenerator;
	this.idProperty = Strings.nullToEmpty(idProperty).trim();
	this.keepNonIdProperty = keepNonIdProperty;
}
 
開發者ID:guicamest,項目名稱:bsoneer,代碼行數:23,代碼來源:AnnotationInfo.java


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