com.sun.tools.javac.code.TypeTags Java Examples

The following examples show how to use com.sun.tools.javac.code.TypeTags. 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: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public Kind getKind() {
    switch (typetag) {
        case TypeTags.INT:
            return Kind.INT_LITERAL;
        case TypeTags.LONG:
            return Kind.LONG_LITERAL;
        case TypeTags.FLOAT:
            return Kind.FLOAT_LITERAL;
        case TypeTags.DOUBLE:
            return Kind.DOUBLE_LITERAL;
        case TypeTags.BOOLEAN:
            return Kind.BOOLEAN_LITERAL;
        case TypeTags.CHAR:
            return Kind.CHAR_LITERAL;
        case TypeTags.CLASS:
            return Kind.STRING_LITERAL;
        case TypeTags.BOT:
            return Kind.NULL_LITERAL;
        default:
            throw new AssertionError("unknown literal kind " + this);
    }
}
 
Example #2
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (typetag) {
        case TypeTags.BOOLEAN:
            return TypeKind.BOOLEAN;
        case TypeTags.BYTE:
            return TypeKind.BYTE;
        case TypeTags.SHORT:
            return TypeKind.SHORT;
        case TypeTags.INT:
            return TypeKind.INT;
        case TypeTags.LONG:
            return TypeKind.LONG;
        case TypeTags.CHAR:
            return TypeKind.CHAR;
        case TypeTags.FLOAT:
            return TypeKind.FLOAT;
        case TypeTags.DOUBLE:
            return TypeKind.DOUBLE;
        case TypeTags.VOID:
            return TypeKind.VOID;
        default:
            throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example #3
Source File: JavacElements.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * An internal-use utility that creates a reified annotation.
 * This overloaded version take annotation inheritance into account.
 */
public static <A extends Annotation> A getAnnotation(ClassSymbol annotated,
                                                     Class<A> annoType) {
    boolean inherited = annoType.isAnnotationPresent(Inherited.class);
    A result = null;
    while (annotated.name != annotated.name.table.names.java_lang_Object) {
        result = getAnnotation((Symbol)annotated, annoType);
        if (result != null || !inherited)
            break;
        Type sup = annotated.getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous())
            break;
        annotated = (ClassSymbol) sup.tsym;
    }
    return result;
}
 
Example #4
Source File: JavacElements.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns all annotations of an element, whether
 * inherited or directly present.
 *
 * @param e  the element being examined
 * @return all annotations of the element
 */
public List<Attribute.Compound> getAllAnnotationMirrors(Element e) {
    Symbol sym = cast(Symbol.class, e);
    List<Attribute.Compound> annos = sym.getAnnotationMirrors();
    while (sym.getKind() == ElementKind.CLASS) {
        Type sup = ((ClassSymbol) sym).getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous() ||
                sup.tsym == syms.objectType.tsym) {
            break;
        }
        sym = sup.tsym;
        List<Attribute.Compound> oldAnnos = annos;
        for (Attribute.Compound anno : sym.getAnnotationMirrors()) {
            if (isInherited(anno.type) &&
                    !containsAnnoOfType(oldAnnos, anno.type)) {
                annos = annos.prepend(anno);
            }
        }
    }
    return annos;
}
 
Example #5
Source File: JCTree.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public Kind getKind() {
    switch (typetag) {
        case TypeTags.INT:
            return Kind.INT_LITERAL;
        case TypeTags.LONG:
            return Kind.LONG_LITERAL;
        case TypeTags.FLOAT:
            return Kind.FLOAT_LITERAL;
        case TypeTags.DOUBLE:
            return Kind.DOUBLE_LITERAL;
        case TypeTags.BOOLEAN:
            return Kind.BOOLEAN_LITERAL;
        case TypeTags.CHAR:
            return Kind.CHAR_LITERAL;
        case TypeTags.CLASS:
            return Kind.STRING_LITERAL;
        case TypeTags.BOT:
            return Kind.NULL_LITERAL;
        default:
            throw new AssertionError("unknown literal kind " + this);
    }
}
 
Example #6
Source File: JCTree.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (typetag) {
        case TypeTags.BOOLEAN:
            return TypeKind.BOOLEAN;
        case TypeTags.BYTE:
            return TypeKind.BYTE;
        case TypeTags.SHORT:
            return TypeKind.SHORT;
        case TypeTags.INT:
            return TypeKind.INT;
        case TypeTags.LONG:
            return TypeKind.LONG;
        case TypeTags.CHAR:
            return TypeKind.CHAR;
        case TypeTags.FLOAT:
            return TypeKind.FLOAT;
        case TypeTags.DOUBLE:
            return TypeKind.DOUBLE;
        case TypeTags.VOID:
            return TypeKind.VOID;
        default:
            throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example #7
Source File: JavacElements.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * An internal-use utility that creates a reified annotation.
 * This overloaded version take annotation inheritance into account.
 */
public static <A extends Annotation> A getAnnotation(ClassSymbol annotated,
                                                     Class<A> annoType) {
    boolean inherited = annoType.isAnnotationPresent(Inherited.class);
    A result = null;
    while (annotated.name != annotated.name.table.names.java_lang_Object) {
        result = getAnnotation((Symbol)annotated, annoType);
        if (result != null || !inherited)
            break;
        Type sup = annotated.getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous())
            break;
        annotated = (ClassSymbol) sup.tsym;
    }
    return result;
}
 
Example #8
Source File: JavacElements.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns all annotations of an element, whether
 * inherited or directly present.
 *
 * @param e  the element being examined
 * @return all annotations of the element
 */
public List<Attribute.Compound> getAllAnnotationMirrors(Element e) {
    Symbol sym = cast(Symbol.class, e);
    List<Attribute.Compound> annos = sym.getAnnotationMirrors();
    while (sym.getKind() == ElementKind.CLASS) {
        Type sup = ((ClassSymbol) sym).getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous() ||
                sup.tsym == syms.objectType.tsym) {
            break;
        }
        sym = sup.tsym;
        List<Attribute.Compound> oldAnnos = annos;
        for (Attribute.Compound anno : sym.getAnnotationMirrors()) {
            if (isInherited(anno.type) &&
                    !containsAnnoOfType(oldAnnos, anno.type)) {
                annos = annos.prepend(anno);
            }
        }
    }
    return annos;
}
 
Example #9
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public Object getValue() {
    switch (typetag) {
        case TypeTags.BOOLEAN:
            int bi = (Integer) value;
            return (bi != 0);
        case TypeTags.CHAR:
            int ci = (Integer) value;
            char c = (char) ci;
            if (c != ci)
                throw new AssertionError("bad value for char literal");
            return c;
        default:
            return value;
    }
}
 
Example #10
Source File: JCTree.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public Object getValue() {
    switch (typetag) {
        case TypeTags.BOOLEAN:
            int bi = (Integer) value;
            return (bi != 0);
        case TypeTags.CHAR:
            int ci = (Integer) value;
            char c = (char) ci;
            if (c != ci)
                throw new AssertionError("bad value for char literal");
            return c;
        default:
            return value;
    }
}