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

The following examples show how to use com.sun.tools.javac.code.Flags#ABSTRACT . 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: TreeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static long modifiersToFlags(Set<Modifier> flagset) {
    long flags = 0L;
    for (Modifier mod : flagset)
        switch (mod) {
            case PUBLIC: flags |= Flags.PUBLIC; break;
            case PROTECTED: flags |= Flags.PROTECTED; break;
            case PRIVATE: flags |= Flags.PRIVATE; break;
            case ABSTRACT: flags |= Flags.ABSTRACT; break;
            case STATIC: flags |= Flags.STATIC; break;
            case FINAL: flags |= Flags.FINAL; break;
            case TRANSIENT: flags |= Flags.TRANSIENT; break;
            case VOLATILE: flags |= Flags.VOLATILE; break;
            case SYNCHRONIZED: flags |= Flags.SYNCHRONIZED; break;
            case NATIVE: flags |= Flags.NATIVE; break;
            case STRICTFP: flags |= Flags.STRICTFP; break;
            case DEFAULT: flags |= Flags.DEFAULT; break;
            default:
                throw new AssertionError("Unknown Modifier: " + mod); //NOI18N
        }
    return flags;
}
 
Example 2
Source File: TreeMaker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ModifiersTree addModifiersModifier(ModifiersTree modifiers, Modifier modifier) {
    long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR;
    switch (modifier) {
        case ABSTRACT: c = c | Flags.ABSTRACT; break;
        case FINAL: c = c | Flags.FINAL; break;
        case NATIVE: c = c | Flags.NATIVE; break;
        case PRIVATE: c = c | Flags.PRIVATE; break;
        case PROTECTED: c = c | Flags.PROTECTED; break;
        case PUBLIC: c = c | Flags.PUBLIC; break;
        case STATIC: c = c | Flags.STATIC; break;
        case STRICTFP: c = c | Flags.STRICTFP; break;
        case SYNCHRONIZED: c = c | Flags.SYNCHRONIZED; break;
        case TRANSIENT: c = c | Flags.TRANSIENT; break;
        case VOLATILE: c = c | Flags.VOLATILE; break;
        case DEFAULT: c = c | Flags.DEFAULT; break;
        default:
            break;
    }
    return Modifiers(c, modifiers.getAnnotations());
}
 
Example 3
Source File: TreeMaker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ModifiersTree removeModifiersModifier(ModifiersTree modifiers, Modifier modifier) {
    long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR;
    switch (modifier) {
        case ABSTRACT: c = c & ~Flags.ABSTRACT; break;
        case FINAL: c = c & ~Flags.FINAL; break;
        case NATIVE: c = c & ~Flags.NATIVE; break;
        case PRIVATE: c = c & ~Flags.PRIVATE; break;
        case PROTECTED: c = c & ~Flags.PROTECTED; break;
        case PUBLIC: c = c & ~Flags.PUBLIC; break;
        case STATIC: c = c & ~Flags.STATIC; break;
        case STRICTFP: c = c & ~Flags.STRICTFP; break;
        case SYNCHRONIZED: c = c & ~Flags.SYNCHRONIZED; break;
        case TRANSIENT: c = c & ~Flags.TRANSIENT; break;
        case VOLATILE: c = c & ~Flags.VOLATILE; break;
        case DEFAULT: c = c & ~Flags.DEFAULT; break;
        default:
            break;
    }
    return Modifiers(c, modifiers.getAnnotations());
}
 
Example 4
Source File: PackageGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
long getFlagByName(String modifierName) {
    switch (modifierName) {
        case "public":
            return Flags.PUBLIC;
        case "private":
            return Flags.PRIVATE;
        case "protected":
            return Flags.PROTECTED;
        case "static":
            return Flags.STATIC;
        case "final":
            return Flags.FINAL;
        case "abstract":
            return Flags.ABSTRACT;
        case "strictfp":
            return Flags.STRICTFP;
        default:
            return 0;
    }
}
 
Example 5
Source File: T6889255.java    From jdk8u60 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 6
Source File: HandleSneakyThrows.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void handleMethod(JavacNode annotation, JCMethodDecl method, Collection<String> exceptions) {
	JavacNode methodNode = annotation.up();
	
	if ( (method.mods.flags & Flags.ABSTRACT) != 0) {
		annotation.addError("@SneakyThrows can only be used on concrete methods.");
		return;
	}
	
	if (method.body == null || method.body.stats.isEmpty()) {
		generateEmptyBlockWarning(methodNode, annotation, false);
		return;
	}
	
	final JCStatement constructorCall = method.body.stats.get(0);
	final boolean isConstructorCall = isConstructorCall(constructorCall);
	List<JCStatement> contents = isConstructorCall ? method.body.stats.tail : method.body.stats;
	
	if (contents == null || contents.isEmpty()) {
		generateEmptyBlockWarning(methodNode, annotation, true);
		return;
	}
	
	for (String exception : exceptions) {
		contents = List.of(buildTryCatchBlock(methodNode, contents, exception, annotation.get()));
	}
	
	method.body.stats = isConstructorCall ? List.of(constructorCall).appendList(contents) : contents;
	methodNode.rebuild();
}
 
Example 7
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void removeImplicitModifiersForInterfaceMembers(List<JCTree> defs) {
	for (JCTree def :defs) {
		if (def instanceof JCVariableDecl) {
			((JCVariableDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.STATIC | Flags.FINAL);
		}
		if (def instanceof JCMethodDecl) {
			((JCMethodDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.ABSTRACT);
		}
		if (def instanceof JCClassDecl) {
			((JCClassDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.STATIC);
		}
	}
}
 
Example 8
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 9
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 10
Source File: T6889255.java    From hottub 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 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: 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 13
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createInfoClass(List<JCAnnotation> annots, ClassSymbol c) {
    long flags = Flags.ABSTRACT | Flags.INTERFACE;
    JCClassDecl infoClass =
            make.ClassDef(make.Modifiers(flags, annots),
                c.name, List.nil(),
                null, List.nil(), List.nil());
    infoClass.sym = c;
    translated.append(infoClass);
}
 
Example 14
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitPackageDef(JCPackageDecl tree) {
    if (!needPackageInfoClass(tree))
                    return;

    long flags = Flags.ABSTRACT | Flags.INTERFACE;
    // package-info is marked SYNTHETIC in JDK 1.6 and later releases
    flags = flags | Flags.SYNTHETIC;
    ClassSymbol c = tree.packge.package_info;
    c.setAttributes(tree.packge);
    c.flags_field |= flags;
    ClassType ctype = (ClassType) c.type;
    ctype.supertype_field = syms.objectType;
    ctype.interfaces_field = List.nil();
    createInfoClass(tree.annotations, c);
}
 
Example 15
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 16
Source File: T6889255.java    From TencentKona-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 17
Source File: ElementsService.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean hasImplementation(MethodSymbol msym) {
    long f = msym.flags();
    return ((f & Flags.DEFAULT) != 0) || ((f & Flags.ABSTRACT) == 0);
}
 
Example 18
Source File: HandleSynchronized.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public void handle(AnnotationValues<Synchronized> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.SYNCHRONIZED_FLAG_USAGE, "@Synchronized");
	
	if (inNetbeansEditor(annotationNode)) return;
	
	deleteAnnotationIfNeccessary(annotationNode, Synchronized.class);
	JavacNode methodNode = annotationNode.up();
	
	if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof JCMethodDecl)) {
		annotationNode.addError("@Synchronized is legal only on methods.");
		
		return;
	}
	
	JCMethodDecl method = (JCMethodDecl)methodNode.get();
	
	if ((method.mods.flags & Flags.ABSTRACT) != 0) {
		annotationNode.addError("@Synchronized is legal only on concrete methods.");
		
		return;
	}
	boolean isStatic = (method.mods.flags & Flags.STATIC) != 0;
	String lockName = annotation.getInstance().value();
	boolean autoMake = false;
	if (lockName.length() == 0) {
		autoMake = true;
		lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
	}
	
	JavacTreeMaker maker = methodNode.getTreeMaker().at(ast.pos);
	Context context = methodNode.getContext();
	
	if (fieldExists(lockName, methodNode) == MemberExistsResult.NOT_EXISTS) {
		if (!autoMake) {
			annotationNode.addError("The field " + lockName + " does not exist.");
			return;
		}
		JCExpression objectType = genJavaLangTypeRef(methodNode, ast.pos, "Object");
		//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
		JCNewArray newObjectArray = maker.NewArray(genJavaLangTypeRef(methodNode, ast.pos, "Object"),
				List.<JCExpression>of(maker.Literal(CTC_INT, 0)), null);
		JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
				maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
				methodNode.toName(lockName), objectType, newObjectArray), ast, context);
		injectFieldAndMarkGenerated(methodNode.up(), fieldDecl);
	}
	
	if (method.body == null) return;
	
	JCExpression lockNode;
	if (isStatic) {
		lockNode = chainDots(methodNode, ast.pos, methodNode.up().getName(), lockName);
	} else {
		lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName));
	}
	
	recursiveSetGeneratedBy(lockNode, ast, context);
	method.body = setGeneratedBy(maker.Block(0, List.<JCStatement>of(setGeneratedBy(maker.Synchronized(lockNode, method.body), ast, context))), ast, context);
	
	methodNode.rebuild();
}