Java Code Examples for com.sun.tools.javac.code.Attribute#Enum

The following examples show how to use com.sun.tools.javac.code.Attribute#Enum . 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: AnnotationProxyMaker.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public void visitEnum(Attribute.Enum e) {
    if (returnClass.isEnum()) {
        String constName = e.value.toString();
        try {
            value = Enum.valueOf((Class)returnClass, constName);
        } catch (IllegalArgumentException ex) {
            value = new EnumConstantNotPresentExceptionProxy(
                                (Class<Enum<?>>) returnClass, constName);
        }
    } else {
        value = null;   // indicates a type mismatch
    }
}
 
Example 2
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Attribute getAnnotationEnumValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
    Type result = attr.attribTree(tree, env, annotationValueInfo(expectedElementType));
    Symbol sym = TreeInfo.symbol(tree);
    if (sym == null ||
            TreeInfo.nonstaticSelect(tree) ||
            sym.kind != VAR ||
            (sym.flags() & Flags.ENUM) == 0) {
        log.error(tree.pos(), Errors.EnumAnnotationMustBeEnumConstant);
        return new Attribute.Error(result.getOriginalType());
    }
    VarSymbol enumerator = (VarSymbol) sym;
    return new Attribute.Enum(expectedElementType, enumerator);
}
 
Example 3
Source File: AnnotationProxyMaker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public void visitEnum(Attribute.Enum e) {
    if (returnClass.isEnum()) {
        String constName = e.value.toString();
        try {
            value = Enum.valueOf((Class)returnClass, constName);
        } catch (IllegalArgumentException ex) {
            value = new EnumConstantNotPresentExceptionProxy(
                                (Class<Enum<?>>) returnClass, constName);
        }
    } else {
        value = null;   // indicates a type mismatch
    }
}
 
Example 4
Source File: AnnotationProxyMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public void visitEnum(Attribute.Enum e) {
    if (returnClass.isEnum()) {
        String constName = e.value.toString();
        try {
            value = Enum.valueOf((Class)returnClass, constName);
        } catch (IllegalArgumentException ex) {
            value = new EnumConstantNotPresentExceptionProxy(
                                (Class<Enum<?>>) returnClass, constName);
        }
    } else {
        value = null;   // indicates a type mismatch
    }
}
 
Example 5
Source File: ClassWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    databuf.appendByte('e');
    databuf.appendChar(pool.put(typeSig(e.value.type)));
    databuf.appendChar(pool.put(e.value.name));
}
 
Example 6
Source File: DPrinter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum a) {
    printSymbol("value", a.value, Details.SUMMARY);
    visitAttribute(a);
}
 
Example 7
Source File: DPrinter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum a) {
    printSymbol("value", a.value, Details.SUMMARY);
    visitAttribute(a);
}
 
Example 8
Source File: AnnotationValueImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    value = env.getFieldDoc(e.value);
}
 
Example 9
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Is the annotation applicable to the symbol? */
boolean annotationApplicable(JCAnnotation a, Symbol s) {
    Attribute.Array arr = getAttributeTargetAttribute(a.annotationType.type.tsym);
    Name[] targets;

    if (arr == null) {
        targets = defaultTargetMetaInfo(a, s);
    } else {
        // TODO: can we optimize this?
        targets = new Name[arr.values.length];
        for (int i=0; i<arr.values.length; ++i) {
            Attribute app = arr.values[i];
            if (!(app instanceof Attribute.Enum)) {
                return true; // recovery
            }
            Attribute.Enum e = (Attribute.Enum) app;
            targets[i] = e.value.name;
        }
    }
    for (Name target : targets) {
        if (target == names.TYPE) {
            if (s.kind == TYP)
                return true;
        } else if (target == names.FIELD) {
            if (s.kind == VAR && s.owner.kind != MTH)
                return true;
        } else if (target == names.METHOD) {
            if (s.kind == MTH && !s.isConstructor())
                return true;
        } else if (target == names.PARAMETER) {
            if (s.kind == VAR && s.owner.kind == MTH &&
                  (s.flags() & PARAMETER) != 0) {
                return true;
            }
        } else if (target == names.CONSTRUCTOR) {
            if (s.kind == MTH && s.isConstructor())
                return true;
        } else if (target == names.LOCAL_VARIABLE) {
            if (s.kind == VAR && s.owner.kind == MTH &&
                  (s.flags() & PARAMETER) == 0) {
                return true;
            }
        } else if (target == names.ANNOTATION_TYPE) {
            if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) {
                return true;
            }
        } else if (target == names.PACKAGE) {
            if (s.kind == PCK)
                return true;
        } else if (target == names.TYPE_USE) {
            if (s.kind == VAR && s.owner.kind == MTH && s.type.hasTag(NONE)) {
                //cannot type annotate implictly typed locals
                return false;
            } else if (s.kind == TYP || s.kind == VAR ||
                    (s.kind == MTH && !s.isConstructor() &&
                            !s.type.getReturnType().hasTag(VOID)) ||
                    (s.kind == MTH && s.isConstructor())) {
                return true;
            }
        } else if (target == names.TYPE_PARAMETER) {
            if (s.kind == TYP && s.type.hasTag(TYPEVAR))
                return true;
        } else
            return true; // Unknown ElementType. This should be an error at declaration site,
                         // assume applicable.
    }
    return false;
}
 
Example 10
Source File: AnnotationValueImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    value = env.getFieldDoc(e.value);
}
 
Example 11
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    throw new AssertionError(); // shouldn't happen
}
 
Example 12
Source File: AnnotationValueImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    value = env.getFieldDoc(e.value);
}
 
Example 13
Source File: DPrinter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum a) {
    printSymbol("value", a.value, Details.SUMMARY);
    visitAttribute(a);
}
 
Example 14
Source File: AnnotationValueImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    sb.append(e);
}
 
Example 15
Source File: AnnotationValueImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    value = env.getFieldDoc(e.value);
}
 
Example 16
Source File: DPrinter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum a) {
    printSymbol("value", a.value, Details.SUMMARY);
    visitAttribute(a);
}
 
Example 17
Source File: AnnotationValueImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    sb.append(e);
}
 
Example 18
Source File: AnnotationValueImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    value = env.getFieldDoc(e.value);
}
 
Example 19
Source File: DPrinter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum a) {
    printSymbol("value", a.value, Details.SUMMARY);
    visitAttribute(a);
}
 
Example 20
Source File: AnnotationValueImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void visitEnum(Attribute.Enum e) {
    value = env.getFieldDoc(e.value);
}