Java Code Examples for com.sun.tools.javac.code.Flags#ENUM

The following examples show how to use com.sun.tools.javac.code.Flags#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: T6889255.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 2
Source File: ClassDocImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if this is an enumeration.
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnum() {
    return (getFlags() & Flags.ENUM) != 0
           &&
           !env.legacyDoclet;
}
 
Example 3
Source File: TreeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassTree Enum(ModifiersTree modifiers, 
         CharSequence simpleName,
         List<? extends Tree> implementsClauses,
         List<? extends Tree> memberDecls) {
    long flags = getBitFlags(modifiers.getFlags()) | Flags.ENUM;
    return Class(flags, (com.sun.tools.javac.util.List<JCAnnotation>) modifiers.getAnnotations(), simpleName, Collections.<TypeParameterTree>emptyList(), null, implementsClauses, memberDecls);
}
 
Example 4
Source File: ClassDocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if this is an enumeration.
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnum() {
    return (getFlags() & Flags.ENUM) != 0
           &&
           !env.legacyDoclet;
}
 
Example 5
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 6
Source File: T6889255.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 7
Source File: T6889255.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 8
Source File: HandleUtilityClass.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static boolean checkLegality(JavacNode typeNode, JavacNode errorNode) {
	JCClassDecl typeDecl = null;
	if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
	long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
	boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0;
	
	if (typeDecl == null || notAClass) {
		errorNode.addError("@UtilityClass is only supported on a class (can't be an interface, enum, or annotation).");
		return false;
	}
	
	// It might be an inner class. This is okay, but only if it is / can be a static inner class. Thus, all of its parents have to be static inner classes until the top-level.
	JavacNode typeWalk = typeNode;
	while (true) {
		typeWalk = typeWalk.up();
		switch (typeWalk.getKind()) {
		case TYPE:
			JCClassDecl typeDef = (JCClassDecl) typeWalk.get();
			if ((typeDef.mods.flags & (Flags.STATIC | Flags.ANNOTATION | Flags.ENUM | Flags.INTERFACE)) != 0) continue;
			if (typeWalk.up().getKind() == Kind.COMPILATION_UNIT) return true;
			errorNode.addError("@UtilityClass automatically makes the class static, however, this class cannot be made static.");
			return false;
		case COMPILATION_UNIT:
			return true;
		default:
			errorNode.addError("@UtilityClass cannot be placed on a method local or anonymous inner class, or any class nested in such a class.");
			return false;
		}
	}
}
 
Example 9
Source File: ClassDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if this is an enumeration.
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnum() {
    return (getFlags() & Flags.ENUM) != 0
           &&
           !env.legacyDoclet;
}
 
Example 10
Source File: JCTree.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public Kind getKind() {
    if ((mods.flags & Flags.ANNOTATION) != 0)
        return Kind.ANNOTATION_TYPE;
    else if ((mods.flags & Flags.INTERFACE) != 0)
        return Kind.INTERFACE;
    else if ((mods.flags & Flags.ENUM) != 0)
        return Kind.ENUM;
    else
        return Kind.CLASS;
}
 
Example 11
Source File: T6889255.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 12
Source File: ClassDocImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if this is an enumeration.
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnum() {
    return (getFlags() & Flags.ENUM) != 0
           &&
           !env.legacyDoclet;
}
 
Example 13
Source File: ClassDocImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if this is an enumeration.
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnum() {
    return (getFlags() & Flags.ENUM) != 0
           &&
           !env.legacyDoclet;
}
 
Example 14
Source File: HandleWither.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateWitherForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelWither) {
	if (checkForTypeLevelWither) {
		if (hasAnnotation(Wither.class, typeNode)) {
			//The annotation will make it happen, so we can skip it.
			return;
		}
	}
	
	JCClassDecl typeDecl = null;
	if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
	long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
	boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0;
	
	if (typeDecl == null || notAClass) {
		errorNode.addError("@Wither is only supported on a class or a field.");
		return;
	}
	
	for (JavacNode field : typeNode.down()) {
		if (field.getKind() != Kind.FIELD) continue;
		JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
		//Skip fields that start with $
		if (fieldDecl.name.toString().startsWith("$")) continue;
		//Skip static fields.
		if ((fieldDecl.mods.flags & Flags.STATIC) != 0) continue;
		//Skip final initialized fields.
		if ((fieldDecl.mods.flags & Flags.FINAL) != 0 && fieldDecl.init != null) continue;
		
		generateWitherForField(field, errorNode.get(), level);
	}
}
 
Example 15
Source File: T6889255.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 16
Source File: FieldDocImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is this Doc item an enum constant?
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnumConstant() {
    return (getFlags() & Flags.ENUM) != 0 &&
           !env.legacyDoclet;
}
 
Example 17
Source File: FieldDocImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is this Doc item an enum constant?
 * (For legacy doclets, return false.)
 */
@Override
public boolean isEnumConstant() {
    return (getFlags() & Flags.ENUM) != 0 &&
           !env.legacyDoclet;
}
 
Example 18
Source File: PositionEstimator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isEnum(Tree tree) {
    if (tree instanceof FieldGroupTree) return ((FieldGroupTree) tree).isEnum();
    if (tree instanceof VariableTree) return (((JCVariableDecl) tree).getModifiers().flags & Flags.ENUM) != 0;
    return false;
}
 
Example 19
Source File: TreeUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**Checks whether the given tree represents a class.
 * @deprecated since 0.67, <code>Tree.getKind() == Kind.CLASS</code> should be used instead.
 */
@Deprecated
public boolean isClass(ClassTree tree) {
    return (((JCTree.JCModifiers)tree.getModifiers()).flags & (Flags.INTERFACE | Flags.ENUM | Flags.ANNOTATION)) == 0;
}
 
Example 20
Source File: TreeUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Checks wheteher given variable tree represents an enum constant.
 */
public boolean isEnumConstant(VariableTree tree) {
    return (((JCTree.JCModifiers) tree.getModifiers()).flags & Flags.ENUM) != 0;
}