Java Code Examples for com.sun.tools.javac.code.Type#getTag()

The following examples show how to use com.sun.tools.javac.code.Type#getTag() . 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: TypeMaker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static String getTypeName(Type t, boolean full) {
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = ((ArrayType)t).elemtype;
        }
        s.insert(0, getTypeName(t, full));
        return s.toString();
    case CLASS:
        return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 2
Source File: TypeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static String getTypeName(Type t, boolean full) {
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = ((ArrayType)t).elemtype;
        }
        s.insert(0, getTypeName(t, full));
        return s.toString();
    case CLASS:
        return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 3
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 4
Source File: TypeMaker.java    From openjdk-jdk8u-backup 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 5
Source File: JavacTrees.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Boolean visitType(Type t, Type s) {
    if (t == s)
        return true;

    if (s.isPartial())
        return visit(s, t);

    switch (t.getTag()) {
    case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
    case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
        return t.hasTag(s.getTag());
    default:
        throw new AssertionError("fuzzyMatcher " + t.getTag());
    }
}
 
Example 6
Source File: JavacTrees.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Boolean visitType(Type t, Type s) {
    if (t == s)
        return true;

    if (s.isPartial())
        return visit(s, t);

    switch (t.getTag()) {
    case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
    case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
        return t.hasTag(s.getTag());
    default:
        throw new AssertionError("fuzzyMatcher " + t.getTag());
    }
}
 
Example 7
Source File: TypeMaker.java    From openjdk-8 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 8
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 9
Source File: TypeMaker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("fallthrough")
public static com.sun.javadoc.Type getType(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: Constants.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string representation of a constant value (given in
 * internal representation), quoted and formatted as in Java source.
 */
public static String format(Object value, Type type) {
    value = decode(value, type);
    switch (type.getTag()) {
    case BYTE:      return formatByte((Byte) value);
    case LONG:      return formatLong((Long) value);
    case FLOAT:     return formatFloat((Float) value);
    case DOUBLE:    return formatDouble((Double) value);
    case CHAR:      return formatChar((Character) value);
    }
    if (value instanceof String)
        return formatString((String) value);
    return value + "";
}
 
Example 11
Source File: Constants.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string representation of a constant value (given in
 * internal representation), quoted and formatted as in Java source.
 */
public static String format(Object value, Type type) {
    value = decode(value, type);
    switch (type.getTag()) {
    case BYTE:      return formatByte((Byte) value);
    case LONG:      return formatLong((Long) value);
    case FLOAT:     return formatFloat((Float) value);
    case DOUBLE:    return formatDouble((Double) value);
    case CHAR:      return formatChar((Character) value);
    }
    if (value instanceof String)
        return formatString((String) value);
    return value + "";
}
 
Example 12
Source File: Constants.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Converts a constant in internal representation (in which
 * boolean, char, byte, short, and int are each represented by an
 * Integer) into standard representation.  Other values (including
 * null) are returned unchanged.
 */
public static Object decode(Object value, Type type) {
    if (value instanceof Integer) {
        int i = (Integer) value;
        switch (type.getTag()) {
        case BOOLEAN:  return i != 0;
        case CHAR:     return (char) i;
        case BYTE:     return (byte) i;
        case SHORT:    return (short) i;
        }
    }
    return value;
}
 
Example 13
Source File: Constants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string representation of a constant value (given in
 * internal representation), quoted and formatted as in Java source.
 */
public static String format(Object value, Type type) {
    value = decode(value, type);
    switch (type.getTag()) {
    case BYTE:      return formatByte((Byte) value);
    case LONG:      return formatLong((Long) value);
    case FLOAT:     return formatFloat((Float) value);
    case DOUBLE:    return formatDouble((Double) value);
    case CHAR:      return formatChar((Character) value);
    }
    if (value instanceof String)
        return formatString((String) value);
    return value + "";
}
 
Example 14
Source File: JVMNames.java    From annotation-tools with MIT License 5 votes vote down vote up
/**
 * Converts a MethodTree into a JVML format method signature.
 * There is probably an API to do this, but I couldn't find it.
 *
 * @param methodTree the tree to convert
 * @return a String signature of methodTree in JVML format
 */
public static String getJVMMethodSignature(MethodTree methodTree) {
    ExecutableElement methodElement = ((JCMethodDecl) methodTree).sym;
    StringBuilder builder = new StringBuilder();
    String returnTypeStr;
    builder.append(methodTree.getName());
    builder.append("(");

    if (methodElement == null) {
        // use source AST in lieu of symbol table
        List<JCVariableDecl> params = ((JCMethodDecl) methodTree).params;
        JCVariableDecl param = params.head;
        JCExpression typeTree = ((JCMethodDecl) methodTree).restype;
        returnTypeStr = treeToJVMLString(typeTree);
        while (param != null) {
            builder.append(treeToJVMLString(param.vartype));
            params = params.tail;
            param = params.head;
        }
    } else {
        TypeMirror returnType = methodElement.getReturnType();
        returnTypeStr = typeToJvmlString((Type)returnType);
        for (VariableElement ve : methodElement.getParameters()) {
            Type vt = (Type) ve.asType();
            if (vt.getTag() == TypeTag.TYPEVAR) {
                vt = vt.getUpperBound();
            }
            builder.append(typeToJvmlString(vt));
        }
    }
    builder.append(")");
    builder.append(returnTypeStr);
    return builder.toString();
}
 
Example 15
Source File: TypeMaker.java    From openjdk-jdk8u-backup 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 16
Source File: Constants.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string representation of a constant value (given in
 * internal representation), quoted and formatted as in Java source.
 */
public static String format(Object value, Type type) {
    value = decode(value, type);
    switch (type.getTag()) {
    case BYTE:      return formatByte((Byte) value);
    case LONG:      return formatLong((Long) value);
    case FLOAT:     return formatFloat((Float) value);
    case DOUBLE:    return formatDouble((Double) value);
    case CHAR:      return formatChar((Character) value);
    }
    if (value instanceof String)
        return formatString((String) value);
    return value + "";
}
 
Example 17
Source File: Constants.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts a constant in internal representation (in which
 * boolean, char, byte, short, and int are each represented by an
 * Integer) into standard representation.  Other values (including
 * null) are returned unchanged.
 */
public static Object decode(Object value, Type type) {
    if (value instanceof Integer) {
        int i = (Integer) value;
        switch (type.getTag()) {
        case BOOLEAN:  return i != 0;
        case CHAR:     return (char) i;
        case BYTE:     return (byte) i;
        case SHORT:    return (short) i;
        }
    }
    return value;
}
 
Example 18
Source File: Operators.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Perform unary promotion of a type; this routine implements JLS 5.6.1.
 * If the input type is not supported by unary promotion, it is returned unaltered.
 */
Type unaryPromotion(Type t) {
    Type unboxed = types.unboxedTypeOrType(t);
    switch (unboxed.getTag()) {
        case BYTE:
        case SHORT:
        case CHAR:
            return syms.intType;
        default:
            return unboxed;
    }
}
 
Example 19
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void checkAnnotationResType(DiagnosticPosition pos, Type type) {
    switch (type.getTag()) {
    case CLASS:
        if ((type.tsym.flags() & ANNOTATION) != 0)
            checkNonCyclicElementsInternal(pos, type.tsym);
        break;
    case ARRAY:
        checkAnnotationResType(pos, types.elemtype(type));
        break;
    default:
        break; // int etc
    }
}
 
Example 20
Source File: ClassWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void writeStackMapType(Type t) {
    if (t == null) {
        if (debugstackmap) System.out.print("empty");
        databuf.appendByte(0);
    }
    else switch(t.getTag()) {
    case BYTE:
    case CHAR:
    case SHORT:
    case INT:
    case BOOLEAN:
        if (debugstackmap) System.out.print("int");
        databuf.appendByte(1);
        break;
    case FLOAT:
        if (debugstackmap) System.out.print("float");
        databuf.appendByte(2);
        break;
    case DOUBLE:
        if (debugstackmap) System.out.print("double");
        databuf.appendByte(3);
        break;
    case LONG:
        if (debugstackmap) System.out.print("long");
        databuf.appendByte(4);
        break;
    case BOT: // null
        if (debugstackmap) System.out.print("null");
        databuf.appendByte(5);
        break;
    case CLASS:
    case ARRAY:
        if (debugstackmap) System.out.print("object(" + t + ")");
        databuf.appendByte(7);
        databuf.appendChar(pool.put(t));
        break;
    case TYPEVAR:
        if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
        databuf.appendByte(7);
        databuf.appendChar(pool.put(types.erasure(t).tsym));
        break;
    case UNINITIALIZED_THIS:
        if (debugstackmap) System.out.print("uninit_this");
        databuf.appendByte(6);
        break;
    case UNINITIALIZED_OBJECT:
        { UninitializedType uninitType = (UninitializedType)t;
        databuf.appendByte(8);
        if (debugstackmap) System.out.print("uninit_object@" + uninitType.offset);
        databuf.appendChar(uninitType.offset);
        }
        break;
    default:
        throw new AssertionError();
    }
}