本文整理汇总了Java中javax.lang.model.element.TypeParameterElement.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TypeParameterElement.getBounds方法的具体用法?Java TypeParameterElement.getBounds怎么用?Java TypeParameterElement.getBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.TypeParameterElement
的用法示例。
在下文中一共展示了TypeParameterElement.getBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: alligatorWithBounds
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
/**
* The type parameters to place on the builder, with the "extends ..." bounds.
*/
String alligatorWithBounds() {
List<TypeParameterElement> allParameters = allParameters();
if (allParameters.isEmpty()) {
return "";
}
StringBuilder alligator = new StringBuilder("<");
String separator = "";
for (TypeParameterElement param : allParameters) {
alligator.append(separator);
separator = ", ";
alligator.append(param.toString());
for (TypeMirror bound : param.getBounds()) {
alligator.append(" extends ").append(bound);
}
}
return alligator.append(">").toString();
}
示例2: getChildInstanceOfClassFromGeneric
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
private Map<TypeParameterElement, TypeMirror> getChildInstanceOfClassFromGeneric(final TypeElement typeElement, final Class<?> aClass) {
Map<TypeParameterElement, TypeMirror> result = new HashMap<>();
for (TypeParameterElement element : typeElement.getTypeParameters()) {
List<? extends TypeMirror> bounds = element.getBounds();
for (TypeMirror bound : bounds) {
if (bound instanceof DeclaredType && ((DeclaredType) bound).asElement() instanceof TypeElement) {
Collection<TypeMirror> viewsType = getViewsType((TypeElement) ((DeclaredType) bound).asElement());
boolean isViewType = false;
for (TypeMirror viewType : viewsType) {
if (((DeclaredType) viewType).asElement().toString().equals(aClass.getCanonicalName())) {
isViewType = true;
}
}
if (isViewType) {
result.put(element, bound);
break;
}
}
}
}
return result;
}
示例3: visitType
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
public Boolean visitType(TypeElement arg0, Void arg1) {
for (TypeParameterElement e : arg0.getTypeParameters()) {
if (stop) {
return false;
}
for (TypeMirror b : e.getBounds()) {
if (stop) {
return false;
}
if (b.accept(this, arg1)) {
return true;
}
}
}
TypeMirror superclass = arg0.getSuperclass();
if (superclass.getKind() == TypeKind.DECLARED) {
if (!((DeclaredType) superclass).asElement().getKind().isInterface()) {
return false;
}
}
return superclass.accept(this, arg1);
}
示例4: get
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的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;
}
示例5: get
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的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;
}
示例6: get
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的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: addTo
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
@Override public void addTo(SourceBuilder source) {
if (!typeParameters.isEmpty()) {
String prefix = "<";
for (Object typeParameter : typeParameters) {
source.add("%s%s", prefix, typeParameter);
if (typeParameter instanceof TypeParameterElement) {
TypeParameterElement element = (TypeParameterElement) typeParameter;
if (!extendsObject(element)) {
String separator = " extends ";
for (TypeMirror bound : element.getBounds()) {
source.add("%s%s", separator, bound);
separator = " & ";
}
}
}
prefix = ", ";
}
source.add(">");
}
}
示例8: visitTypeVariable
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的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: getBounds
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
private List<Type.Defined> getBounds(Type.Parameters parameters, TypeParameterElement p) {
List<Type.Defined> bounds = new ArrayList<>();
for (TypeMirror b : p.getBounds()) {
bounds.add((Type.Defined) b.accept(converter, parameters));
}
return bounds;
}
示例10: createHtmlHeader
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
private static String createHtmlHeader(boolean deprecated, TypeElement e) {
StringBuilder sb = new StringBuilder();
sb.append("<html>");
if (deprecated) sb.append("<s>");
sb.append(e.getSimpleName());
if (deprecated) sb.append("</s>");
List<? extends TypeParameterElement> typeParams = e.getTypeParameters();
if (typeParams != null && !typeParams.isEmpty()) {
sb.append("<"); // NOI18N
for(Iterator<? extends TypeParameterElement> it = typeParams.iterator(); it.hasNext();) {
TypeParameterElement tp = it.next();
sb.append(tp.getSimpleName());
try {
List<? extends TypeMirror> bounds = tp.getBounds();
if (!bounds.isEmpty()) {
sb.append(translateToHTML(printBounds(bounds)));
}
}
catch (NullPointerException npe) {
}
if (it.hasNext()) {
sb.append(", "); // NOI18N
}
}
sb.append(">"); // NOI18N
}
return sb.toString();
}
示例11: visitTypeParameter
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
@Override
public Tree visitTypeParameter(TypeParameterElement e, Void p) {
List<ExpressionTree> bounds = new LinkedList<ExpressionTree>();
for (TypeMirror b : e.getBounds()) {
bounds.add((ExpressionTree) make.Type(b));
}
return make.TypeParameter(e.getSimpleName(), bounds);
}
示例12: appendTypeParameterWithBounds
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
private void appendTypeParameterWithBounds(StringBuilder sb, TypeParameterElement typeParameter) {
sb.append(typeParameter.getSimpleName());
String sep = " extends ";
for (TypeMirror bound : typeParameter.getBounds()) {
if (!bound.toString().equals("java.lang.Object")) {
sb.append(sep);
sep = " & ";
bound.accept(toStringTypeVisitor, sb);
}
}
}
示例13: getBounds
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
public List<? extends TypeMirror> getBounds(TypeParameterElement tpe) {
List<? extends TypeMirror> bounds = tpe.getBounds();
if (!bounds.isEmpty()) {
TypeMirror upperBound = bounds.get(bounds.size() - 1);
if (ignoreBounds(upperBound)) {
return Collections.emptyList();
}
}
return bounds;
}
示例14: visitTypeVariable
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
@Override
public Integer visitTypeVariable(TypeVariable t, Set<Element> visiting) {
int result = hashKind(HASH_SEED, t);
result *= HASH_MULTIPLIER;
result += t.getLowerBound().accept(this, visiting);
TypeParameterElement element = (TypeParameterElement) t.asElement();
for (TypeMirror bound : element.getBounds()) {
result *= HASH_MULTIPLIER;
result += bound.accept(this, visiting);
}
return result;
}
示例15: appendTypeParameterWithBounds
import javax.lang.model.element.TypeParameterElement; //导入方法依赖的package包/类
private void appendTypeParameterWithBounds(StringBuilder sb, TypeParameterElement typeParameter) {
sb.append(typeParameter.getSimpleName());
String sep = " extends ";
for (TypeMirror bound : typeParameter.getBounds()) {
if (!bound.toString().equals("java.lang.Object")) {
sb.append(sep);
sep = " & ";
bound.accept(toStringTypeVisitor, sb);
}
}
}