本文整理汇总了Java中javax.lang.model.type.TypeVariable.asElement方法的典型用法代码示例。如果您正苦于以下问题:Java TypeVariable.asElement方法的具体用法?Java TypeVariable.asElement怎么用?Java TypeVariable.asElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.TypeVariable
的用法示例。
在下文中一共展示了TypeVariable.asElement方法的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;
}
示例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);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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);
}
}
示例9: 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
if (!insideCapturedWildcard) {
insideCapturedWildcard = true;
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);
}
}
insideCapturedWildcard = false;
}
return DEFAULT_VALUE;
}
示例10: 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
if (!insideCapturedWildcard) {
insideCapturedWildcard = true;
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);
}
}
insideCapturedWildcard = false;
}
return DEFAULT_VALUE;
}
示例11: test
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
void test(TypeElement element, boolean fbound) {
TypeParameterElement tpe = element.getTypeParameters().iterator().next();
tpe.getBounds().getClass();
if (fbound) {
DeclaredType type = (DeclaredType)tpe.getBounds().get(0);
if (type.asElement() != element)
throw error("%s != %s", type.asElement(), element);
TypeVariable tv = (TypeVariable)type.getTypeArguments().get(0);
if (tv.asElement() != tpe)
throw error("%s != %s", tv.asElement(), tpe);
}
}
示例12: typeIsImmutable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
private boolean typeIsImmutable(AnnotatedTypeMirror type) {
TypeMirror underlyingType = type.getUnderlyingType();
boolean fieldIsImmutable = type.hasAnnotation(Immutable.class);
if (!fieldIsImmutable) {
// Check for permitted special cases: primitives and type parameters.
boolean typeIsPrimitive = underlyingType instanceof PrimitiveType;
boolean typeIsImmutableClassTypeParameter = false;
if (underlyingType.getKind() == TypeKind.TYPEVAR) {
// Type variables can be assumed to be immutable if they are on an immutable class. Otherwise they are unsafe.
TypeVariable typeVariable = (TypeVariable) underlyingType;
TypeParameterElement typeVariableElement = (TypeParameterElement) (typeVariable.asElement());
Element elementEnclosingTypeVariable = typeVariableElement.getGenericElement();
if (elementEnclosingTypeVariable.getKind() == ElementKind.CLASS || elementEnclosingTypeVariable.getKind() == ElementKind.ENUM) {
// Check to see if this class is immutable.
TypeElement classElement = (TypeElement) elementEnclosingTypeVariable;
AnnotatedTypeMirror classTypeMirror = atypeFactory.getAnnotatedType(classElement);
if (classTypeMirror.hasAnnotation(Immutable.class)) {
typeIsImmutableClassTypeParameter = true;
}
}
}
if (!typeIsPrimitive && !typeIsImmutableClassTypeParameter) {
return false;
}
}
if (underlyingType.getKind() == TypeKind.ARRAY) {
// Arrays must be immutable arrays of immmutable objects.
AnnotatedArrayType arrayType = (AnnotatedArrayType) type;
AnnotatedTypeMirror componentType = arrayType.getComponentType();
return typeIsImmutable(componentType);
}
return true;
}
示例13: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override public Boolean visitTypeVariable(TypeVariable t, Set<TypeParameterElement> visited) {
TypeParameterElement element = (TypeParameterElement) t.asElement();
if (visited.contains(element)) return false;
visited.add(element);
for (TypeMirror bound : element.getBounds()) {
if (bound.accept(this, visited)) return true;
}
return false;
}
示例14: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
@Nullable
public R visitTypeVariable(TypeVariable t, P p) {
// Avoid infinite recursion in cases like T extends List<T>
TypeParameterElement typeParameterElement = (TypeParameterElement) t.asElement();
if (visitedTypeVars.contains(typeParameterElement)) {
return defaultValue;
}
visitedTypeVars.add(typeParameterElement);
scan(t.getLowerBound(), p);
return scan(t.getUpperBound(), p);
}
示例15: visitTypeVariable
import javax.lang.model.type.TypeVariable; //导入方法依赖的package包/类
@Override
public Element visitTypeVariable(TypeVariable t, Void p) {
return t.asElement();
}