Java Code Examples for javax.lang.model.type.WildcardType#getExtendsBound()

The following examples show how to use javax.lang.model.type.WildcardType#getExtendsBound() . 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: TypeUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public StringBuilder visitWildcard(WildcardType t, Boolean p) {
    int len = DEFAULT_VALUE.length();
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getSuperBound();
    if (bound == null) {
        bound = t.getExtendsBound();
        if (bound != null) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound, p);
        } else if (len == 0) {
            bound = SourceUtils.getBound(t);
            if (bound != null && (bound.getKind() != TypeKind.DECLARED || !((TypeElement)((DeclaredType)bound).asElement()).getQualifiedName().contentEquals("java.lang.Object"))) { //NOI18N
                DEFAULT_VALUE.append(" extends "); //NOI18N
                visit(bound, p);
            }
        }
    } else {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    }
    return DEFAULT_VALUE;
}
 
Example 2
Source File: SpringXMLConfigCompletionItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public StringBuilder visitWildcard(WildcardType t, Boolean p) {
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getSuperBound();
    if (bound == null) {
        bound = t.getExtendsBound();
        if (bound != null) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound, p);
        } else {
            bound = SourceUtils.getBound(t);
            if (bound != null && (bound.getKind() != TypeKind.DECLARED || !((TypeElement)((DeclaredType)bound).asElement()).getQualifiedName().contentEquals("java.lang.Object"))) { //NOI18N
                DEFAULT_VALUE.append(" extends "); //NOI18N
                visit(bound, p);
            }
        }
    } else {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    }
    return DEFAULT_VALUE;
}
 
Example 3
Source File: AutoImport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitWildcard(WildcardType type, Void p) {
    builder.append("?"); //NOI18N
    TypeMirror bound = type.getSuperBound();
    if (bound == null) {
        bound = type.getExtendsBound();
        if (bound != null) {
            builder.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound);
        }
    } else {
        builder.append(" super "); //NOI18N
        visit(bound);
    }
    return null;
}
 
Example 4
Source File: MethodModelSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public StringBuilder visitWildcard(WildcardType t, Boolean p) {
    int len = DEFAULT_VALUE.length();
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getSuperBound();
    if (bound == null) {
        bound = t.getExtendsBound();
        if (bound != null) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound, p);
        } else if (len == 0) {
            bound = SourceUtils.getBound(t);
            if (bound != null && (bound.getKind() != TypeKind.DECLARED || !((TypeElement)((DeclaredType)bound).asElement()).getQualifiedName().contentEquals("java.lang.Object"))) { //NOI18N
                DEFAULT_VALUE.append(" extends "); //NOI18N
                visit(bound, p);
            }
        }
    } else {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    }
    return DEFAULT_VALUE;
}
 
Example 5
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public StringBuilder visitWildcard(WildcardType t, Boolean p) {
    int len = DEFAULT_VALUE.length();
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getSuperBound();
    if (bound == null) {
        bound = t.getExtendsBound();
        if (bound != null) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound, p);
        } else if (len == 0) {
            bound = SourceUtils.getBound(t);
            if (bound != null && (bound.getKind() != TypeKind.DECLARED || !((TypeElement)((DeclaredType)bound).asElement()).getQualifiedName().contentEquals("java.lang.Object"))) { //NOI18N
                DEFAULT_VALUE.append(" extends "); //NOI18N
                visit(bound, p);
            }
        }
    } else {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    }
    return DEFAULT_VALUE;
}
 
Example 6
Source File: AbstractAssignabilityChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected boolean handleWildCard( TypeMirror argType, WildcardType varTypeArg,
        Types types )
{
    TypeMirror upperBound = varTypeArg.getExtendsBound();
    TypeMirror lowerBound = varTypeArg.getSuperBound();

    if ( argType instanceof ReferenceType && 
            argType.getKind()!=TypeKind.TYPEVAR)
    {
        return handleWildCardActualType(argType, types, upperBound,
                lowerBound);
    }            
    
    if ( argType.getKind() == TypeKind.TYPEVAR ){
        return handleWildCardTypeVar(argType, types, upperBound, lowerBound);
    }
    
    return false;
}
 
Example 7
Source File: BeanModelBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addDependency(TypeMirror tm) {
    if (tm.getKind() == TypeKind.ARRAY) {
        addDependency(((ArrayType)tm).getComponentType());
    } else if (tm.getKind() == TypeKind.WILDCARD) {
        WildcardType wt = (WildcardType)tm;
        TypeMirror bound = wt.getSuperBound();
        if (bound == null) {
            bound = wt.getExtendsBound();
        }
        addDependency(bound);
    } else if (tm.getKind() == TypeKind.DECLARED) {
        addDependency(
            ((TypeElement)compilationInfo.getTypes().asElement(tm)).getQualifiedName().toString()
        );
    }
}
 
Example 8
Source File: TypeSimplifier.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
@Override public boolean apply(TypeMirror arg) {
  if (arg.getKind() == TypeKind.WILDCARD) {
    WildcardType wildcard = (WildcardType) arg;
    if (wildcard.getExtendsBound() == null || isJavaLangObject(wildcard.getExtendsBound())) {
      // This is <?>, unless there's a super bound, in which case it is <? super Foo> and
      // is erased.
      return (wildcard.getSuperBound() != null);
    }
  }
  return true;
}
 
Example 9
Source File: TypeSimplifier.java    From SimpleWeibo with Apache License 2.0 5 votes vote down vote up
@Override public Void visitWildcard(WildcardType t, Void p) {
  for (TypeMirror bound : new TypeMirror[] {t.getSuperBound(), t.getExtendsBound()}) {
    if (bound != null) {
      visit(bound, p);
    }
  }
  return null;
}
 
Example 10
Source File: TypeSimplifier.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
@Override public Void visitWildcard(WildcardType t, Void p) {
  for (TypeMirror bound : new TypeMirror[] {t.getSuperBound(), t.getExtendsBound()}) {
    if (bound != null) {
      visit(bound, p);
    }
  }
  return null;
}
 
Example 11
Source File: TypeSimplifier.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
@Override public StringBuilder visitWildcard(WildcardType type, StringBuilder sb) {
  sb.append("?");
  TypeMirror extendsBound = type.getExtendsBound();
  TypeMirror superBound = type.getSuperBound();
  if (superBound != null) {
    sb.append(" super ");
    visit(superBound, sb);
  } else if (extendsBound != null) {
    sb.append(" extends ");
    visit(extendsBound, sb);
  }
  return sb;
}
 
Example 12
Source File: TypeSimplifier.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
@Override public boolean apply(TypeMirror arg) {
  if (arg.getKind() == TypeKind.WILDCARD) {
    WildcardType wildcard = (WildcardType) arg;
    if (wildcard.getExtendsBound() == null || isJavaLangObject(wildcard.getExtendsBound())) {
      // This is <?>, unless there's a super bound, in which case it is <? super Foo> and
      // is erased.
      return (wildcard.getSuperBound() != null);
    }
  }
  return true;
}
 
Example 13
Source File: TypeSimplifier.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
@Override public Void visitWildcard(WildcardType t, Void p) {
  for (TypeMirror bound : new TypeMirror[] {t.getSuperBound(), t.getExtendsBound()}) {
    if (bound != null) {
      visit(bound, p);
    }
  }
  return null;
}
 
Example 14
Source File: TypeSimplifier.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
@Override public StringBuilder visitWildcard(WildcardType type, StringBuilder sb) {
  sb.append("?");
  TypeMirror extendsBound = type.getExtendsBound();
  TypeMirror superBound = type.getSuperBound();
  if (superBound != null) {
    sb.append(" super ");
    visit(superBound, sb);
  } else if (extendsBound != null) {
    sb.append(" extends ");
    visit(extendsBound, sb);
  }
  return sb;
}
 
Example 15
Source File: Utils.java    From paperparcel with Apache License 2.0 5 votes vote down vote up
@Override public TypeMirror visitWildcard(WildcardType type, Types types) {
  if (type.getExtendsBound() != null) {
    return type.getExtendsBound().accept(this, types);
  } else {
    return type.getSuperBound().accept(this, types);
  }
}
 
Example 16
Source File: TypeMirrorAppender.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitWildcard(WildcardType t, QualifiedNameAppendable a) {
  a.append("?");
  if (t.getSuperBound() != null) {
    a.append(" super ");
    t.getSuperBound().accept(this, a);
  }
  if (t.getExtendsBound() != null) {
    a.append(" extends ");
    t.getExtendsBound().accept(this, a);
  }
  return null;
}
 
Example 17
Source File: TypeSimplifier.java    From SimpleWeibo with Apache License 2.0 5 votes vote down vote up
@Override public boolean apply(TypeMirror arg) {
  if (arg.getKind() == TypeKind.WILDCARD) {
    WildcardType wildcard = (WildcardType) arg;
    if (wildcard.getExtendsBound() == null || isJavaLangObject(wildcard.getExtendsBound())) {
      // This is <?>, unless there's a super bound, in which case it is <? super Foo> and
      // is erased.
      return (wildcard.getSuperBound() != null);
    }
  }
  return true;
}
 
Example 18
Source File: Utils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void formatTypeMirror( TypeMirror typeMirror,
        StringBuilder stringBuilder, boolean FQNs )
{
    if (typeMirror == null) {
        return;
    }

    switch (typeMirror.getKind()) {
        case BOOLEAN:
        case BYTE:
        case CHAR:
        case DOUBLE:
        case FLOAT:
        case INT:
        case LONG:
        case NONE:
        case NULL:
        case SHORT:
        case VOID:
            stringBuilder.append(typeMirror);

            break;

        case TYPEVAR:
            TypeVariable typeVariable = (TypeVariable) typeMirror;
            stringBuilder.append(typeVariable.asElement().getSimpleName()
                    .toString());
            break;

        case WILDCARD:
            WildcardType wildcardType = (WildcardType) typeMirror;
            stringBuilder.append("?");
            if (wildcardType.getExtendsBound() != null) {
                stringBuilder.append(" extends "); // NOI18N
                formatTypeMirror(wildcardType.getExtendsBound(),
                        stringBuilder, FQNs);
            }
            if (wildcardType.getSuperBound() != null) {
                stringBuilder.append(" super "); // NOI18N
                formatTypeMirror(wildcardType.getSuperBound(),
                        stringBuilder, FQNs);
            }

            break;

        case DECLARED:
            DeclaredType declaredType = (DeclaredType) typeMirror;
            Element element = declaredType.asElement();
            if (element instanceof TypeElement) {
                stringBuilder.append(FQNs ? ((TypeElement) element)
                        .getQualifiedName().toString() : element
                        .getSimpleName().toString());
            }
            else {
                stringBuilder.append(element.getSimpleName().toString());
            }
            List<? extends TypeMirror> typeArgs = declaredType
                    .getTypeArguments();
            if (!typeArgs.isEmpty()) {
                stringBuilder.append("<");
                formatTypeMirrors(typeArgs, stringBuilder, FQNs);
                stringBuilder.append(">");
            }

            break;

        case ARRAY:

            int dims = 0;

            while (typeMirror.getKind() == TypeKind.ARRAY) {
                dims++;
                typeMirror = ((ArrayType) typeMirror).getComponentType();
            }

            formatTypeMirror(typeMirror, stringBuilder, FQNs);

            for (int i = 0; i < dims; i++) {
                stringBuilder.append("[]");
            }

            break;
    }
}
 
Example 19
Source File: ElementNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static String print( TypeMirror tm ) {
    StringBuilder sb;
    switch (tm.getKind()) {
        case DECLARED:
            DeclaredType dt = (DeclaredType)tm;
            sb = new StringBuilder(dt.asElement().getSimpleName().toString());
            List<? extends TypeMirror> typeArgs = dt.getTypeArguments();
            if (!typeArgs.isEmpty()) {
                sb.append("<"); // NOI18N
                for (Iterator<? extends TypeMirror> it = typeArgs.iterator(); it.hasNext();) {
                    TypeMirror ta = it.next();
                    sb.append(print(ta));
                    if (it.hasNext()) {
                        sb.append(", "); // NOI18N
                    }
                }
                sb.append(">"); // NOI18N
            }                    
            return sb.toString();
        case TYPEVAR:
            TypeVariable tv = (TypeVariable)tm;
            sb = new StringBuilder(tv.asElement().getSimpleName().toString());
            return sb.toString();
        case ARRAY:
            ArrayType at = (ArrayType)tm;
            sb = new StringBuilder(print(at.getComponentType()));
            sb.append("[]"); // NOI18N
            return sb.toString();
        case WILDCARD:
            WildcardType wt = (WildcardType)tm;
            sb = new StringBuilder("?"); // NOI18N
            if (wt.getExtendsBound() != null) {
                sb.append(" extends "); // NOI18N
                sb.append(print(wt.getExtendsBound()));
            }
            if (wt.getSuperBound() != null) {
                sb.append(" super "); // NOI18N
                sb.append(print(wt.getSuperBound()));
            }
            return sb.toString();
        default:
            return tm.toString();
    }
}
 
Example 20
Source File: ExportNonAccessibleElement.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Boolean visitWildcard(WildcardType wild, Void arg1) {
    TypeMirror eb = wild.getExtendsBound();
    TypeMirror sb = wild.getSuperBound();
    return (eb != null && eb.accept(this, arg1)) ||
           (sb != null && sb.accept(this, arg1));
}