Example usage for org.objectweb.asm Opcodes ACC_FINAL

List of usage examples for org.objectweb.asm Opcodes ACC_FINAL

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_FINAL.

Prototype

int ACC_FINAL

To view the source code for org.objectweb.asm Opcodes ACC_FINAL.

Click Source Link

Usage

From source file:graph.Modifier.java

License:Apache License

/**
 * Returns an integer bit field for the EnumSet, where the bit values are
 * defined as in the class file format.//from   www . jav a2 s  . c  om
 *
 * @param  set   Set of modifiers to convert to a bit field.
 * @return       Integer bit field.
 */
public static int getBitField(EnumSet<Modifier> set) {
    int access = 0;

    if (set.contains(PUBLIC)) {
        access |= Opcodes.ACC_PUBLIC;
    }

    if (set.contains(PROTECTED)) {
        access |= Opcodes.ACC_PROTECTED;
    }

    if (set.contains(PRIVATE)) {
        access |= Opcodes.ACC_PRIVATE;
    }

    if (set.contains(STATIC)) {
        access |= Opcodes.ACC_STATIC;
    }

    if (set.contains(FINAL)) {
        access |= Opcodes.ACC_FINAL;
    }

    if (set.contains(SUPER)) {
        access |= Opcodes.ACC_SUPER;
    }

    if (set.contains(INTERFACE)) {
        access |= Opcodes.ACC_INTERFACE;
    }

    if (set.contains(ABSTRACT)) {
        access |= Opcodes.ACC_ABSTRACT;
    }

    if (set.contains(SYNTHETIC)) {
        access |= Opcodes.ACC_SYNTHETIC;
    }

    if (set.contains(ANNOTATION)) {
        access |= Opcodes.ACC_ANNOTATION;
    }

    if (set.contains(ENUM)) {
        access |= Opcodes.ACC_ENUM;
    }

    if (set.contains(VOLATILE)) {
        access |= Opcodes.ACC_VOLATILE;
    }

    if (set.contains(TRANSIENT)) {
        access |= Opcodes.ACC_TRANSIENT;
    }

    if (set.contains(SYNCHRONIZED)) {
        access |= Opcodes.ACC_SYNCHRONIZED;
    }

    if (set.contains(BRIDGE)) {
        access |= Opcodes.ACC_BRIDGE;
    }

    if (set.contains(VARARGS)) {
        access |= Opcodes.ACC_VARARGS;
    }

    if (set.contains(NATIVE)) {
        access |= Opcodes.ACC_NATIVE;
    }

    return access;
}

From source file:graph.Modifier.java

License:Apache License

/**
 * Returns an EnumSet of the modifiers, based on the given bit field (where
 * the bit values are defined as in the class file format).
 *
 * @param access Integer bit field giving access modifiers.
 * @return       Set of modifiers./*  w  ww . j a v a  2 s.  com*/
 */
public static EnumSet<Modifier> getSet(int access) {
    EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);

    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        modifiers.add(Modifier.PUBLIC);
    }

    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        modifiers.add(Modifier.PROTECTED);
    }

    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        modifiers.add(Modifier.PRIVATE);
    }

    if ((access & Opcodes.ACC_STATIC) != 0) {
        modifiers.add(Modifier.STATIC);
    }

    if ((access & Opcodes.ACC_FINAL) != 0) {
        modifiers.add(Modifier.FINAL);
    }

    if ((access & Opcodes.ACC_SUPER) != 0) {
        modifiers.add(Modifier.SUPER);
    }

    if ((access & Opcodes.ACC_INTERFACE) != 0) {
        modifiers.add(Modifier.INTERFACE);
    }

    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        modifiers.add(Modifier.ABSTRACT);
    }

    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        modifiers.add(Modifier.SYNTHETIC);
    }

    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        modifiers.add(Modifier.ANNOTATION);
    }

    if ((access & Opcodes.ACC_ENUM) != 0) {
        modifiers.add(Modifier.ENUM);
    }

    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        modifiers.add(Modifier.VOLATILE);
    }

    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        modifiers.add(Modifier.TRANSIENT);
    }

    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        modifiers.add(Modifier.SYNCHRONIZED);
    }

    if ((access & Opcodes.ACC_BRIDGE) != 0) {
        modifiers.add(Modifier.BRIDGE);
    }

    if ((access & Opcodes.ACC_VARARGS) != 0) {
        modifiers.add(Modifier.VARARGS);
    }

    if ((access & Opcodes.ACC_NATIVE) != 0) {
        modifiers.add(Modifier.NATIVE);
    }

    if ((access & Opcodes.ACC_STRICT) != 0) {
        modifiers.add(Modifier.STRICT);
    }

    return modifiers;
}

From source file:groovy.beans.BindableASTTransformation.java

License:Apache License

/**
 * Handles the bulk of the processing, mostly delegating to other methods.
 *
 * @param nodes   the ast nodes/*from w  ww .jav a  2s. co m*/
 * @param source  the source unit for the nodes
 */
public void visit(ASTNode[] nodes, SourceUnit source) {
    if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }
    AnnotationNode node = (AnnotationNode) nodes[0];
    AnnotatedNode parent = (AnnotatedNode) nodes[1];

    if (VetoableASTTransformation.hasVetoableAnnotation(parent)) {
        // VetoableASTTransformation will handle both @Bindable and @Vetoable
        return;
    }

    ClassNode declaringClass = parent.getDeclaringClass();
    if (parent instanceof FieldNode) {
        if ((((FieldNode) parent).getModifiers() & Opcodes.ACC_FINAL) != 0) {
            source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException(
                    "@groovy.beans.Bindable cannot annotate a final property.", node.getLineNumber(),
                    node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
        }

        if (VetoableASTTransformation.hasVetoableAnnotation(parent.getDeclaringClass())) {
            // VetoableASTTransformation will handle both @Bindable and @Vetoable
            return;
        }
        addListenerToProperty(source, node, declaringClass, (FieldNode) parent);
    } else if (parent instanceof ClassNode) {
        addListenerToClass(source, (ClassNode) parent);
    }
}

From source file:groovy.beans.BindableASTTransformation.java

License:Apache License

private void addListenerToClass(SourceUnit source, ClassNode classNode) {
    if (needsPropertyChangeSupport(classNode, source)) {
        addPropertyChangeSupport(classNode);
    }//w  ww .  j a v a  2  s.  c  o m
    for (PropertyNode propertyNode : classNode.getProperties()) {
        FieldNode field = propertyNode.getField();
        // look to see if per-field handlers will catch this one...
        if (hasBindableAnnotation(field) || ((field.getModifiers() & Opcodes.ACC_FINAL) != 0)
                || field.isStatic() || VetoableASTTransformation.hasVetoableAnnotation(field)) {
            // explicitly labeled properties are already handled,
            // don't transform final properties
            // don't transform static properties
            // VetoableASTTransformation will handle both @Bindable and @Vetoable
            continue;
        }
        createListenerSetter(classNode, propertyNode);
    }
}

From source file:groovy.beans.VetoableASTTransformation.java

License:Apache License

/**
 * Handles the bulk of the processing, mostly delegating to other methods.
 *
 * @param nodes   the AST nodes/*  w  w  w.j a v a2 s . c  om*/
 * @param source  the source unit for the nodes
 */
public void visit(ASTNode[] nodes, SourceUnit source) {
    if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }
    AnnotationNode node = (AnnotationNode) nodes[0];

    if (nodes[1] instanceof ClassNode) {
        addListenerToClass(source, (ClassNode) nodes[1]);
    } else {
        if ((((FieldNode) nodes[1]).getModifiers() & Opcodes.ACC_FINAL) != 0) {
            source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException(
                    "@groovy.beans.Vetoable cannot annotate a final property.", node.getLineNumber(),
                    node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
        }

        addListenerToProperty(source, node, (AnnotatedNode) nodes[1]);
    }
}

From source file:groovyx.javafx.beans.FXBindableASTTransformation.java

License:Apache License

/**
 * This ASTTransformation method is called when the compiler encounters our annotation.
 * @param nodes An array of nodes.  Index 0 is the annotation that triggered the call, index 1
 *              is the annotated node./*w ww .  ja  v a 2  s  . c  o m*/
 * @param sourceUnit The SourceUnit describing the source code in which the annotation was placed.
 */
@Override
public void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
    if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }

    AnnotationNode node = (AnnotationNode) nodes[0];
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    ClassNode declaringClass = parent.getDeclaringClass();

    if (parent instanceof FieldNode) {
        int modifiers = ((FieldNode) parent).getModifiers();
        if ((modifiers & Opcodes.ACC_FINAL) != 0) {
            String msg = "@groovyfx.beans.FXBindable cannot annotate a final property.";
            generateSyntaxErrorMessage(sourceUnit, node, msg);
        }
        addJavaFXProperty(sourceUnit, node, declaringClass, (FieldNode) parent);
    } else {
        addJavaFXPropertyToClass(sourceUnit, node, (ClassNode) parent);
    }
}

From source file:groovyx.javafx.beans.FXBindableASTTransformation.java

License:Apache License

/**
 * Iterate through the properties of the class and convert each eligible property to a JavaFX property.
 * /*from   w  ww  . java 2 s . com*/
 * @param source The SourceUnit
 * @param node The AnnotationNode
 * @param classNode The declaring class
 */
private void addJavaFXPropertyToClass(SourceUnit source, AnnotationNode node, ClassNode classNode) {
    for (PropertyNode propertyNode : classNode.getProperties()) {
        FieldNode field = propertyNode.getField();
        // look to see if per-field handlers will catch this one...
        if (hasBindableAnnotation(field) || ((field.getModifiers() & Opcodes.ACC_FINAL) != 0)
                || field.isStatic()) {
            // explicitly labeled properties are already handled,
            // don't transform final properties
            // don't transform static properties
            // VetoableASTTransformation will handle both @Bindable and @Vetoable
            continue;
        }
        createPropertyGetterSetter(classNode, propertyNode);
    }
}

From source file:groovyx.javafx.beans.FXBindableASTTransformation.java

License:Apache License

/**
 * Creates a setter method and adds it to the declaring class.  The setter has the form:
 *
 *     void <setter>(<type> fieldName)
 *
 * @param declaringClass The class to which the method is added
 * @param propertyNode The property node being accessed by this setter
 * @param setterName The name of the setter method
 * @param setterBlock The code body of the method
 *///w  ww .  j  a  v  a2 s.co m
protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName,
        Statement setterBlock) {
    Parameter[] setterParameterTypes = { new Parameter(propertyNode.getType(), "value") };
    int mod = propertyNode.getModifiers() | Opcodes.ACC_FINAL;

    MethodNode setter = new MethodNode(setterName, mod, ClassHelper.VOID_TYPE, setterParameterTypes,
            ClassNode.EMPTY_ARRAY, setterBlock);
    setter.setSynthetic(true);
    declaringClass.addMethod(setter);
}

From source file:groovyx.javafx.beans.FXBindableASTTransformation.java

License:Apache License

/**
 * Creates a getter method and adds it to the declaring class.
 *
 * @param declaringClass The class to which the method is added
 * @param propertyNode The property node being accessed by this getter
 * @param getterName The name of the getter method
 * @param getterBlock The code body of the method
 */// w  w  w  .ja va 2  s .c  o  m
protected void createGetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String getterName,
        Statement getterBlock) {
    int mod = propertyNode.getModifiers() | Opcodes.ACC_FINAL;
    MethodNode getter = new MethodNode(getterName, mod, propertyNode.getType(), Parameter.EMPTY_ARRAY,
            ClassNode.EMPTY_ARRAY, getterBlock);
    getter.setSynthetic(true);
    declaringClass.addMethod(getter);
}

From source file:jaspex.speculation.Cache.java

License:Open Source License

public static void saveClass(final Type className, byte[] classBytes) {
    new File(CACHE_DIR).mkdir();
    try {//from ww  w  . j a  v a 2 s.  c  om
        ClassReader cr = new ClassReader(classBytes);
        ClassWriter cw = new ClassWriter(cr, 0);

        cr.accept(new ClassVisitor(Opcodes.ASM4, cw) {
            @Override
            public void visitEnd() {
                visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_HASH_FIELD,
                        asmlib.Type.STRING.bytecodeName(), null, hashClass(className));
                cv.visitEnd();
            }
        }, 0);

        FileOutputStream fos = new FileOutputStream(CACHE_DIR + className.commonName() + ".class");
        fos.write(cw.toByteArray());
        fos.close();
    } catch (IOException e) {
        throw new Error(e);
    }
}