Java Code Examples for com.sun.tools.javac.code.Type#WildcardType

The following examples show how to use com.sun.tools.javac.code.Type#WildcardType . 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: WildcardTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string form of a wildcard type ("?") along with any
 * "extends" or "super" clause.  Delimiting brackets are not
 * included.  Class names are qualified if "full" is true.
 */
static String wildcardTypeToString(DocEnv env,
                                   Type.WildcardType wildThing, boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
    }
    StringBuilder s = new StringBuilder("?");
    List<Type> bounds = getExtendsBounds(wildThing);
    if (bounds.nonEmpty()) {
        s.append(" extends ");
    } else {
        bounds = getSuperBounds(wildThing);
        if (bounds.nonEmpty()) {
            s.append(" super ");
        }
    }
    boolean first = true;   // currently only one bound is allowed
    for (Type b : bounds) {
        if (!first) {
            s.append(" & ");
        }
        s.append(TypeMaker.getTypeString(env, b, full));
        first = false;
    }
    return s.toString();
}
 
Example 2
Source File: TypeMaker.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 3
Source File: WildcardTypeImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string form of a wildcard type ("?") along with any
 * "extends" or "super" clause.  Delimiting brackets are not
 * included.  Class names are qualified if "full" is true.
 */
static String wildcardTypeToString(DocEnv env,
                                   Type.WildcardType wildThing, boolean full) {
    if (env.legacyDoclet) {
        return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
    }
    StringBuilder s = new StringBuilder("?");
    List<Type> bounds = getExtendsBounds(wildThing);
    if (bounds.nonEmpty()) {
        s.append(" extends ");
    } else {
        bounds = getSuperBounds(wildThing);
        if (bounds.nonEmpty()) {
            s.append(" super ");
        }
    }
    boolean first = true;   // currently only one bound is allowed
    for (Type b : bounds) {
        if (!first) {
            s.append(" & ");
        }
        s.append(TypeMaker.getTypeString(env, b, full));
        first = false;
    }
    return s.toString();
}
 
Example 4
Source File: TypeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 5
Source File: TypeMaker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 6
Source File: TypeMaker.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 7
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
/**
 * Erase all structural interface type literals to Object
 */
@Override
public void visitIdent( JCTree.JCIdent tree )
{
  super.visitIdent( tree );

  if( _tp.isGenerate() && !shouldProcessForGeneration() )
  {
    // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
    return;
  }

  if( TypeUtil.isStructuralInterface( _tp, tree.sym ) && !isReceiver( tree ) )
  {
    Symbol.ClassSymbol objectSym = getObjectClass();
    Tree parent = _tp.getParent( tree );
    JCTree.JCIdent objIdent = _tp.getTreeMaker().Ident( objectSym );
    if( parent instanceof JCTree.JCVariableDecl )
    {
      ((JCTree.JCVariableDecl)parent).type = objectSym.type;

      long parameterModifier = 8589934592L; // Flag.Flag.PARAMETER.value
      if( (((JCTree.JCVariableDecl)parent).mods.flags & parameterModifier) != 0 )
      {
        objIdent.type = objectSym.type;
        ((JCTree.JCVariableDecl)parent).sym.type = objectSym.type;
        ((JCTree.JCVariableDecl)parent).vartype = objIdent;
      }
    }
    else if( parent instanceof JCTree.JCWildcard )
    {
      JCTree.JCWildcard wildcard = (JCTree.JCWildcard)parent;
      wildcard.type = new Type.WildcardType( objectSym.type, wildcard.kind.kind, wildcard.type.tsym );
    }
    tree = objIdent;
    tree.type = objectSym.type;
  }
  result = tree;
}
 
Example 8
Source File: SourceUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static TypeMirror getBound(WildcardType wildcardType) {
    Type.TypeVar bound = ((Type.WildcardType)wildcardType).bound;
    try {
        return bound != null ? bound.bound : null;
    } catch (NoSuchFieldError err) {
        return bound != null ? bound.getUpperBound() : null;
    }
}
 
Example 9
Source File: TypeMaker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("fallthrough")
private static com.sun.javadoc.Type getTypeImpl(DocEnv env, Type t,
        boolean errToClassDoc, boolean considerAnnotations) {
    if (env.legacyDoclet) {
        t = env.types.erasure(t);
    }

    if (considerAnnotations && t.isAnnotated()) {
        return new AnnotatedTypeImpl(env, t);
    }

    switch (t.getTag()) {
    case CLASS:
        if (ClassDocImpl.isGeneric((ClassSymbol)t.tsym)) {
            return env.getParameterizedType((ClassType)t);
        } else {
            return env.getClassDoc((ClassSymbol)t.tsym);
        }
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return new WildcardTypeImpl(env, a);
    case TYPEVAR: return new TypeVariableImpl(env, (TypeVar)t);
    case ARRAY: return new ArrayTypeImpl(env, t);
    case BYTE: return PrimitiveType.byteType;
    case CHAR: return PrimitiveType.charType;
    case SHORT: return PrimitiveType.shortType;
    case INT: return PrimitiveType.intType;
    case LONG: return PrimitiveType.longType;
    case FLOAT: return PrimitiveType.floatType;
    case DOUBLE: return PrimitiveType.doubleType;
    case BOOLEAN: return PrimitiveType.booleanType;
    case VOID: return PrimitiveType.voidType;
    case ERROR:
        if (errToClassDoc)
            return env.getClassDoc((ClassSymbol)t.tsym);
        // FALLTHRU
    default:
        return new PrimitiveType(t.tsym.getQualifiedName().toString());
    }
}
 
Example 10
Source File: WildcardTypeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static List<Type> getExtendsBounds(Type.WildcardType wild) {
    return wild.isSuperBound()
            ? List.<Type>nil()
            : List.of(wild.type);
}
 
Example 11
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public R visitWildcardType(Type.WildcardType t, P p) {
    return defaultAction(t, p);
}
 
Example 12
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
/**
 * Erase all structural interface type literals to Object
 */
@Override
public void visitSelect( JCTree.JCFieldAccess tree )
{
  super.visitSelect( tree );

  if( _tp.isGenerate() && !shouldProcessForGeneration() )
  {
    // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
    return;
  }

  if( TypeUtil.isStructuralInterface( _tp, tree.sym ) && !isReceiver( tree ) )
  {
    Symbol.ClassSymbol objectSym = getObjectClass();
    JCTree.JCIdent objIdent = _tp.getTreeMaker().Ident( objectSym );
    Tree parent = _tp.getParent( tree );
    if( parent instanceof JCTree.JCVariableDecl )
    {
      ((JCTree.JCVariableDecl)parent).type = objectSym.type;
      long parameterModifier = 8589934592L; // Flag.Flag.PARAMETER.value
      if( (((JCTree.JCVariableDecl)parent).mods.flags & parameterModifier) != 0 )
      {
        objIdent.type = objectSym.type;
        ((JCTree.JCVariableDecl)parent).sym.type = objectSym.type;
        ((JCTree.JCVariableDecl)parent).vartype = objIdent;
      }
    }
    else if( parent instanceof JCTree.JCWildcard )
    {
      JCTree.JCWildcard wildcard = (JCTree.JCWildcard)parent;
      wildcard.type = new Type.WildcardType( objectSym.type, wildcard.kind.kind, wildcard.type.tsym );
    }
    result = objIdent;
  }
  else if( isJailbreakReceiver( tree ) )
  {
    result = replaceWithReflection( tree );
  }
  else
  {
    result = tree;
  }
}
 
Example 13
Source File: WildcardTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static List<Type> getExtendsBounds(Type.WildcardType wild) {
    return wild.isSuperBound()
            ? List.nil()
            : List.of(wild.type);
}
 
Example 14
Source File: WildcardTypeImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
    super(env, type);
}
 
Example 15
Source File: WildcardTypeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static List<Type> getSuperBounds(Type.WildcardType wild) {
    return wild.isExtendsBound()
            ? List.<Type>nil()
            : List.of(wild.type);
}
 
Example 16
Source File: WildcardTypeImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
    super(env, type);
}
 
Example 17
Source File: SrcClassUtil.java    From manifold with Apache License 2.0 4 votes vote down vote up
private String typeNoAnnotations( Type type )
{
  if( isJava8() )
  {
    return type.toString();
  }

  StringBuilder sb = new StringBuilder();
  if( type instanceof Type.ClassType )
  {
    if( type.getEnclosingType().hasTag( CLASS ) &&
        ReflectUtil.field( type.tsym.owner, "kind" ).get() == ReflectUtil.field( "com.sun.tools.javac.code.Kinds$Kind", "TYP" ).getStatic() )
    {
      sb.append( typeNoAnnotations( type.getEnclosingType() ) );
      sb.append( "." );
      sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, false ) );
    }
    else
    {
      sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, true ) );
    }

    List<Type> typeArgs = type.getTypeArguments();
    if( typeArgs.nonEmpty() )
    {
      sb.append( '<' );
      for( int i = 0; i < typeArgs.size(); i++ )
      {
        if( i > 0 )
        {
          sb.append( ", " );
        }
        Type typeArg = typeArgs.get( i );
        sb.append( typeNoAnnotations( typeArg ) );
      }
      sb.append( ">" );
    }
  }
  else if( type instanceof Type.ArrayType )
  {
    sb.append( typeNoAnnotations( ((Type.ArrayType)type).getComponentType() ) ).append( "[]" );
  }
  else if( type instanceof Type.WildcardType )
  {
    Type.WildcardType wildcardType = (Type.WildcardType)type;
    BoundKind kind = wildcardType.kind;
    sb.append( kind.toString() );
    if( kind != BoundKind.UNBOUND )
    {
      sb.append( typeNoAnnotations( wildcardType.type ) );
    }
  }
  else
  {
    sb.append( type.toString() );
  }
  return sb.toString();
}
 
Example 18
Source File: WildcardTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static List<Type> getSuperBounds(Type.WildcardType wild) {
    return wild.isExtendsBound()
            ? List.nil()
            : List.of(wild.type);
}
 
Example 19
Source File: WildcardTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
    super(env, type);
}
 
Example 20
Source File: WildcardTypeImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static List<Type> getExtendsBounds(Type.WildcardType wild) {
    return wild.isSuperBound()
            ? List.<Type>nil()
            : List.of(wild.type);
}