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

The following examples show how to use com.sun.tools.javac.code.Flags#ANNOTATION . 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: HandleGetter.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void generateGetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelGetter) {
	if (checkForTypeLevelGetter) {
		if (hasAnnotation(Getter.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)) != 0;
	
	if (typeDecl == null || notAClass) {
		errorNode.addError("@Getter is only supported on a class, an enum, or a field.");
		return;
	}
	
	for (JavacNode field : typeNode.down()) {
		if (fieldQualifiesForGetterGeneration(field)) generateGetterForField(field, errorNode.get(), level, false);
	}
}
 
Example 2
Source File: BootstrapInserter.java    From manifold with Apache License 2.0 6 votes vote down vote up
private boolean skipForOtherReasons( JCTree.JCClassDecl tree )
{
  if( (tree.getModifiers().flags & Flags.ANNOTATION) != 0 )
  {
    // don't bootstrap from an annotation class,
    // many tools do not handle the presence of the <clinit> method well
    return true;
  }

  if( tree.implementing != null )
  {
    for( JCTree.JCExpression iface : tree.implementing )
    {
      if( iface.toString().contains( "ManifoldHost" ) )
      {
        // Don't insert bootstrap in a IManifoldHost impl
        return true;
      }
    }
  }

  return false;
}
 
Example 3
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 4
Source File: HandleSetter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateSetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelSetter) {
	if (checkForTypeLevelSetter) {
		if (hasAnnotation(Setter.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("@Setter 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 fields.
		if ((fieldDecl.mods.flags & Flags.FINAL) != 0) continue;
		
		generateSetterForField(field, errorNode, level);
	}
}
 
Example 5
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 6
Source File: HandleFieldDefaults.java    From EasyMPermission with MIT License 5 votes vote down vote up
public boolean generateFieldDefaultsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean makeFinal, boolean checkForTypeLevelFieldDefaults) {
	if (checkForTypeLevelFieldDefaults) {
		if (hasAnnotation(FieldDefaults.class, typeNode)) {
			//The annotation will make it happen, so we can skip it.
			return true;
		}
	}
	
	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)) != 0;
	
	if (typeDecl == null || notAClass) {
		errorNode.addError("@FieldDefaults is only supported on a class or an enum.");
		return false;
	}
	
	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;
		
		setFieldDefaultsForField(field, errorNode.get(), level, makeFinal);
	}
	
	return true;
}
 
Example 7
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 8
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void validateAnnotationType(DiagnosticPosition pos, Type type) {
    if (type.isPrimitive()) return;
    if (types.isSameType(type, syms.stringType)) return;
    if ((type.tsym.flags() & Flags.ENUM) != 0) return;
    if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return;
    if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return;
    if (types.isArray(type) && !types.isArray(types.elemtype(type))) {
        validateAnnotationType(pos, types.elemtype(type));
        return;
    }
    log.error(pos, Errors.InvalidAnnotationMemberType);
}
 
Example 9
Source File: TreePruner.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static boolean isFinal(JCClassDecl enclClass, JCVariableDecl tree) {
  if ((tree.mods.flags & Flags.FINAL) == Flags.FINAL) {
    return true;
  }
  if (enclClass != null && (enclClass.mods.flags & (Flags.ANNOTATION | Flags.INTERFACE)) != 0) {
    // Fields in annotation declarations and interfaces are implicitly final
    return true;
  }
  return false;
}
 
Example 10
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.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: TreeUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**Checks whether the given tree represents an interface.
 * @deprecated since 0.67, <code>Tree.getKind() == Kind.INTERFACE</code> should be used instead.
 */
@Deprecated
public boolean isInterface(ClassTree tree) {
    final long flags = ((JCTree.JCModifiers) tree.getModifiers()).flags;
    return (flags & Flags.INTERFACE) != 0 && (flags & Flags.ANNOTATION) == 0;
}
 
Example 12
Source File: TreeUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**Checks whether the given tree represents an annotation.
 * @deprecated since 0.67, <code>Tree.getKind() == Kind.ANNOTATION_TYPE</code> should be used instead.
 */
@Deprecated
public boolean isAnnotation(ClassTree tree) {
    return (((JCTree.JCModifiers)tree.getModifiers()).flags & Flags.ANNOTATION) != 0;
}
 
Example 13
Source File: ClassDocImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is a ClassSymbol an annotation type?
 */
static boolean isAnnotationType(ClassSymbol clazz) {
    return (getFlags(clazz) & Flags.ANNOTATION) != 0;
}
 
Example 14
Source File: ClassDocImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is a ClassSymbol an annotation type?
 */
static boolean isAnnotationType(ClassSymbol clazz) {
    return (getFlags(clazz) & Flags.ANNOTATION) != 0;
}
 
Example 15
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 16
Source File: TreeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ClassTree AnnotationType(ModifiersTree modifiers, 
         CharSequence simpleName,
         List<? extends Tree> memberDecls) {
    long flags = getBitFlags(modifiers.getFlags()) | Flags.ANNOTATION;
    return Class(flags, (com.sun.tools.javac.util.List<JCAnnotation>) modifiers.getAnnotations(), simpleName, Collections.<TypeParameterTree>emptyList(), null, Collections.<ExpressionTree>emptyList(), memberDecls);
}
 
Example 17
Source File: ClassDocImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is a ClassSymbol an annotation type?
 */
static boolean isAnnotationType(ClassSymbol clazz) {
    return (getFlags(clazz) & Flags.ANNOTATION) != 0;
}
 
Example 18
Source File: ClassDocImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is a ClassSymbol an annotation type?
 */
static boolean isAnnotationType(ClassSymbol clazz) {
    return (getFlags(clazz) & Flags.ANNOTATION) != 0;
}
 
Example 19
Source File: ClassDocImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is a ClassSymbol an annotation type?
 */
static boolean isAnnotationType(ClassSymbol clazz) {
    return (getFlags(clazz) & Flags.ANNOTATION) != 0;
}
 
Example 20
Source File: ClassDocImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Is a ClassSymbol an annotation type?
 */
static boolean isAnnotationType(ClassSymbol clazz) {
    return (getFlags(clazz) & Flags.ANNOTATION) != 0;
}