下面列出了java.lang.annotation.Inherited#com.sun.tools.javac.code.TypeTags 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
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);
}
}
/**
* 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;
}
/**
* 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;
}
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);
}
}
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);
}
}
/**
* 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;
}
/**
* 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;
}
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;
}
}
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;
}
}