Java Code Examples for javax.lang.model.type.TypeVariable#asElement()
The following examples show how to use
javax.lang.model.type.TypeVariable#asElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoreTypes.java From auto with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: MoreTypes.java From auto-parcel with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: TypeVariableName.java From JReFrameworker with MIT License | 6 votes |
/** * 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; }
Example 4
Source File: SpringXMLConfigCompletionItem.java From netbeans with Apache License 2.0 | 6 votes |
@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; }
Example 5
Source File: AutoImport.java From netbeans with Apache License 2.0 | 6 votes |
@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; }
Example 6
Source File: TypeVariableName.java From JReFrameworker with MIT License | 6 votes |
/** * 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; }
Example 7
Source File: T6421111.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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); } }
Example 8
Source File: Utils.java From paperparcel with Apache License 2.0 | 5 votes |
@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; }
Example 9
Source File: T6421111.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 10
Source File: T6421111.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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); } }
Example 11
Source File: T6421111.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 12
Source File: T6421111.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 13
Source File: Utils.java From paperparcel with Apache License 2.0 | 5 votes |
@Override public Void visitTypeVariable(TypeVariable type, Set<String> visited) { if (visited.contains(type.toString())) return null; visited.add(type.toString()); TypeParameterElement element = (TypeParameterElement) type.asElement(); for (TypeMirror bound : element.getBounds()) { bound.accept(this, visited); } return null; }
Example 14
Source File: MethodModelSupport.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example 15
Source File: JavaSymbolProvider.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example 16
Source File: Utils.java From paperparcel with Apache License 2.0 | 5 votes |
@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 mirror : element.getBounds()) { if (mirror.accept(this, visited)) return true; } return false; }
Example 17
Source File: T6421111.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 18
Source File: BuilderSpec.java From RetroFacebook with Apache License 2.0 | 4 votes |
@Override public Element visitTypeVariable(TypeVariable t, Void p) { return t.asElement(); }
Example 19
Source File: MoreTypes.java From auto with Apache License 2.0 | 4 votes |
@Override public Element visitTypeVariable(TypeVariable t, Void p) { return t.asElement(); }
Example 20
Source File: BuilderSpec.java From SimpleWeibo with Apache License 2.0 | 4 votes |
@Override public Element visitTypeVariable(TypeVariable t, Void p) { return t.asElement(); }