javax.lang.model.type.TypeVariable#asElement ( )源码实例Demo

下面列出了javax.lang.model.type.TypeVariable#asElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JReFrameworker   文件: TypeVariableName.java
/**
 * 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;
}
 
源代码2 项目: netbeans   文件: SpringXMLConfigCompletionItem.java
@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;
}
 
源代码3 项目: netbeans   文件: AutoImport.java
@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 项目: JReFrameworker   文件: TypeVariableName.java
/**
 * 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;
}
 
源代码5 项目: auto-parcel   文件: MoreTypes.java
@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;
}
 
源代码6 项目: auto   文件: MoreTypes.java
@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;
}
 
源代码7 项目: TencentKona-8   文件: T6421111.java
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);
    }
}
 
源代码8 项目: jdk8u60   文件: T6421111.java
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);
    }
}
 
源代码9 项目: paperparcel   文件: Utils.java
@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;
}
 
源代码10 项目: netbeans   文件: JavaSymbolProvider.java
@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 项目: netbeans   文件: MethodModelSupport.java
@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;
}
 
源代码12 项目: paperparcel   文件: Utils.java
@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;
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: T6421111.java
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);
    }
}
 
源代码14 项目: openjdk-jdk9   文件: T6421111.java
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);
    }
}
 
源代码15 项目: openjdk-8-source   文件: T6421111.java
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);
    }
}
 
源代码16 项目: openjdk-8   文件: T6421111.java
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);
    }
}
 
源代码17 项目: paperparcel   文件: Utils.java
@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;
}
 
源代码18 项目: RetroFacebook   文件: BuilderSpec.java
@Override public Element visitTypeVariable(TypeVariable t, Void p) {
  return t.asElement();
}
 
源代码19 项目: auto   文件: MoreTypes.java
@Override
public Element visitTypeVariable(TypeVariable t, Void p) {
  return t.asElement();
}
 
源代码20 项目: SimpleWeibo   文件: BuilderSpec.java
@Override public Element visitTypeVariable(TypeVariable t, Void p) {
  return t.asElement();
}