Example usage for org.objectweb.asm Opcodes ACC_SYNTHETIC

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

Introduction

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

Prototype

int ACC_SYNTHETIC

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

Click Source Link

Usage

From source file:org.apache.tika.parser.asm.XHTMLClassVisitor.java

License:Apache License

/**
 * Visits a field./*  w w w  .  j  a v a 2  s  . co  m*/
 */
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    if (!isSet(access, Opcodes.ACC_SYNTHETIC)) {
        try {
            xhtml.characters("    ");
            writeAccess(access);
            writeType(Type.getType(desc));
            writeSpace();
            writeIdentifier(name);

            if (isSet(access, Opcodes.ACC_STATIC) && value != null) {
                xhtml.characters(" = ");
                xhtml.characters(value.toString());
            }

            writeSemicolon();
            writeNewline();
        } catch (SAXException e) {
            throw new RuntimeException(e);
        }
    }

    return null;
}

From source file:org.apache.tika.parser.asm.XHTMLClassVisitor.java

License:Apache License

/**
 * Visits a method.//from  ww w .  j  av a2 s. com
 */
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (!isSet(access, Opcodes.ACC_SYNTHETIC)) {
        try {
            xhtml.characters("    ");
            writeAccess(access);
            writeType(Type.getReturnType(desc));
            writeSpace();
            if ("<init>".equals(name)) {
                writeType(type);
            } else {
                writeIdentifier(name);
            }

            xhtml.characters("(");
            String separator = "";
            for (Type arg : Type.getArgumentTypes(desc)) {
                xhtml.characters(separator);
                writeType(arg);
                separator = ", ";
            }
            xhtml.characters(")");

            if (exceptions != null && exceptions.length > 0) {
                writeSpace();
                writeKeyword("throws");
                separator = " ";
                for (String exception : exceptions) {
                    xhtml.characters(separator);
                    writeType(Type.getObjectType(exception));
                    separator = ", ";
                }
            }

            writeSemicolon();
            writeNewline();
        } catch (SAXException e) {
            throw new RuntimeException(e);
        }
    }

    return null;
}

From source file:org.bundlemaker.core.parser.bytecode.asm.ArtefactAnalyserClassVisitor.java

License:Open Source License

/**
 * @inheritDoc//from ww w  .j  a va  2  s . c o  m
 */
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {

    //
    if (!_analyzeReferences) {
        return null;
    }

    Type t = Type.getType(desc);
    if ((access & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC) {
        if (Class.class.getName().equals(t.getClassName())) {
            if (name != null && name.startsWith(CLASS_NAME_PREFIX)) {
                name = name.substring(CLASS_NAME_PREFIX.length());
                name = name.replace('$', '.');
                int lastDotIndex = name.lastIndexOf('.');

                for (int i = 0; i < lastDotIndex; i++) {
                    if (Character.isUpperCase(name.charAt(i))) {
                        if (i == 0) {
                            return null;
                        }
                        if (name.charAt(i - 1) == '.') {
                            name = name.substring(0, i) + name.substring(i).replace('.', '$');
                            break;
                        }
                    }
                }
                if (Character.isJavaIdentifierStart(name.charAt(0))) {
                    // no uses
                    VisitorUtils.recordReferencedTypes(_recorder, false, false, false, name);
                }
            }
        }
    }

    // no uses
    VisitorUtils.recordReferencedTypes(_recorder, false, false, false, t);

    //
    return new ArtefactAnalyserFieldVisitor(_recorder);
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void annotationDef(AST classDef) {
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = classDef.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(classDef, "Annotation Definition", modifiers, Opcodes.ACC_SYNCHRONIZED,
                "synchronized");
        node = node.getNextSibling();/*from ww  w.ja va 2s. c o  m*/
    }
    modifiers |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_ANNOTATION;

    String name = identifier(node);
    node = node.getNextSibling();
    ClassNode superClass = ClassHelper.OBJECT_TYPE;

    GenericsType[] genericsType = null;
    if (isType(TYPE_PARAMETERS, node)) {
        genericsType = makeGenericsType(node);
        node = node.getNextSibling();
    }

    ClassNode[] interfaces = ClassNode.EMPTY_ARRAY;
    if (isType(EXTENDS_CLAUSE, node)) {
        interfaces = interfaces(node);
        node = node.getNextSibling();
    }

    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, null);
    classNode.setSyntheticPublic(syntheticPublic);
    classNode.addAnnotations(annotations);
    classNode.setGenericsTypes(genericsType);
    classNode.addInterface(ClassHelper.Annotation_TYPE);
    configureAST(classNode, classDef);

    assertNodeType(OBJBLOCK, node);
    objectBlock(node);
    output.addClass(classNode);
    classNode = null;
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void innerInterfaceDef(AST classDef) {
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = classDef.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(classDef, "Interface", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized");
        node = node.getNextSibling();/*  w w w .  j  a  va2  s  .  co m*/
    }
    modifiers |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE;

    String name = identifier(node);
    node = node.getNextSibling();
    ClassNode superClass = ClassHelper.OBJECT_TYPE;

    GenericsType[] genericsType = null;
    if (isType(TYPE_PARAMETERS, node)) {
        genericsType = makeGenericsType(node);
        node = node.getNextSibling();
    }

    ClassNode[] interfaces = ClassNode.EMPTY_ARRAY;
    if (isType(EXTENDS_CLAUSE, node)) {
        interfaces = interfaces(node);
        node = node.getNextSibling();
    }

    ClassNode outerClass = classNode;
    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    if (classNode != null) {
        name = classNode.getNameWithoutPackage() + "$" + name;
        String fullName = dot(classNode.getPackageName(), name);
        classNode = new InnerClassNode(classNode, fullName, modifiers, superClass, interfaces, null);
    } else {
        classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, null);
    }
    classNode.setSyntheticPublic(syntheticPublic);
    classNode.addAnnotations(annotations);
    classNode.setGenericsTypes(genericsType);
    configureAST(classNode, classDef);

    assertNodeType(OBJBLOCK, node);
    objectBlock(node);
    output.addClass(classNode);

    classNode = outerClass;
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void innerClassDef(AST classDef) {
    List<AnnotationNode> annotations = new ArrayList<>();

    if (isType(TRAIT_DEF, classDef)) {
        annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
    }/*w w  w.  j av  a 2  s.  co m*/

    AST node = classDef.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(classDef, "Class", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized");
        node = node.getNextSibling();
    }

    String name = identifier(node);
    node = node.getNextSibling();

    GenericsType[] genericsType = null;
    if (isType(TYPE_PARAMETERS, node)) {
        genericsType = makeGenericsType(node);
        node = node.getNextSibling();
    }

    ClassNode superClass = null;
    if (isType(EXTENDS_CLAUSE, node)) {
        superClass = makeTypeWithArguments(node);
        node = node.getNextSibling();
    }

    ClassNode[] interfaces = ClassNode.EMPTY_ARRAY;
    if (isType(IMPLEMENTS_CLAUSE, node)) {
        interfaces = interfaces(node);
        node = node.getNextSibling();
    }

    // TODO read mixins
    MixinNode[] mixins = {};
    ClassNode outerClass = classNode;
    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    if (classNode != null) {
        name = classNode.getNameWithoutPackage() + "$" + name;
        String fullName = dot(classNode.getPackageName(), name);
        if (classNode.isInterface()) {
            modifiers |= Opcodes.ACC_STATIC;
        }
        classNode = new InnerClassNode(classNode, fullName, modifiers, superClass, interfaces, mixins);
    } else {
        classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, mixins);
    }
    classNode.addAnnotations(annotations);
    classNode.setGenericsTypes(genericsType);
    classNode.setSyntheticPublic(syntheticPublic);
    configureAST(classNode, classDef);

    // we put the class already in output to avoid the most inner classes
    // will be used as first class later in the loader. The first class
    // there determines what GCL#parseClass for example will return, so we
    // have here to ensure it won't be the inner class
    output.addClass(classNode);

    assertNodeType(OBJBLOCK, node);
    objectBlock(node);

    classNode = outerClass;
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void enumDef(AST enumNode) {
    assertNodeType(ENUM_DEF, enumNode);/*from ww w . j av  a 2s .co m*/
    List<AnnotationNode> annotations = new ArrayList<>();

    AST node = enumNode.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        node = node.getNextSibling();
    }

    String name = identifier(node);
    node = node.getNextSibling();

    ClassNode[] interfaces = interfaces(node);
    node = node.getNextSibling();

    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    String enumName = (classNode != null ? name : dot(getPackageName(), name));
    ClassNode enumClass = EnumHelper.makeEnumNode(enumName, modifiers, interfaces, classNode);
    enumClass.setSyntheticPublic(syntheticPublic);
    enumClass.addAnnotations(annotations);
    configureAST(enumClass, enumNode);

    ClassNode oldNode = classNode;
    classNode = enumClass;
    assertNodeType(OBJBLOCK, node);
    objectBlock(node);
    classNode = oldNode;

    output.addClass(enumClass);
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void methodDef(AST methodDef) {
    MethodNode oldNode = methodNode;//from w  ww  . j av a 2 s  .  c  om
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = methodDef.getFirstChild();

    GenericsType[] generics = null;
    if (isType(TYPE_PARAMETERS, node)) {
        generics = makeGenericsType(node);
        node = node.getNextSibling();
    }

    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(methodDef, "Method", modifiers, Opcodes.ACC_VOLATILE, "volatile");
        node = node.getNextSibling();
    }

    if (isAnInterface()) {
        modifiers |= Opcodes.ACC_ABSTRACT;
    }

    ClassNode returnType = null;
    if (isType(TYPE, node)) {
        returnType = makeTypeWithArguments(node);
        node = node.getNextSibling();
    }

    String name = identifier(node);
    if (classNode != null && !classNode.isAnnotationDefinition()) {
        if (classNode.getNameWithoutPackage().equals(name)) {
            if (isAnInterface()) {
                throw new ASTRuntimeException(methodDef, "Constructor not permitted within an interface.");
            }
            throw new ASTRuntimeException(methodDef, "Invalid constructor format. Remove '"
                    + returnType.getName()
                    + "' as the return type if you want a constructor, or use a different name if you want a method.");
        }
    }
    node = node.getNextSibling();

    Parameter[] parameters = Parameter.EMPTY_ARRAY;
    ClassNode[] exceptions = ClassNode.EMPTY_ARRAY;

    if (classNode == null || !classNode.isAnnotationDefinition()) {
        assertNodeType(PARAMETERS, node);
        parameters = parameters(node);
        if (parameters == null)
            parameters = Parameter.EMPTY_ARRAY;
        node = node.getNextSibling();

        if (isType(LITERAL_throws, node)) {
            AST throwsNode = node.getFirstChild();
            List<ClassNode> exceptionList = new ArrayList<>();
            throwsList(throwsNode, exceptionList);
            exceptions = exceptionList.toArray(exceptions);
            node = node.getNextSibling();
        }
    }

    boolean hasAnnotationDefault = false;
    Statement code = null;
    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    methodNode = new MethodNode(name, modifiers, returnType, parameters, exceptions, code);
    if ((modifiers & Opcodes.ACC_ABSTRACT) == 0) {
        if (node == null) {
            throw new ASTRuntimeException(methodDef,
                    "You defined a method without a body. Try adding a body, or declare it abstract.");
        } else {
            assertNodeType(SLIST, node);
            code = statementList(node);
        }
    } else if (node != null) {
        if (classNode != null && classNode.isAnnotationDefinition()) {
            code = statement(node);
            hasAnnotationDefault = true;
        } else {
            throw new ASTRuntimeException(methodDef, "Abstract methods do not define a body.");
        }
    }
    methodNode.setCode(code);
    methodNode.addAnnotations(annotations);
    methodNode.setGenericsTypes(generics);
    methodNode.setAnnotationDefault(hasAnnotationDefault);
    methodNode.setSyntheticPublic(syntheticPublic);
    configureAST(methodNode, methodDef);

    if (classNode != null) {
        classNode.addMethod(methodNode);
    } else {
        output.addMethod(methodNode);
    }
    methodNode = oldNode;
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void constructorDef(AST constructorDef) {
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = constructorDef.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(constructorDef, "Constructor", modifiers, Opcodes.ACC_STATIC, "static");
        checkNoInvalidModifier(constructorDef, "Constructor", modifiers, Opcodes.ACC_FINAL, "final");
        checkNoInvalidModifier(constructorDef, "Constructor", modifiers, Opcodes.ACC_ABSTRACT, "abstract");
        checkNoInvalidModifier(constructorDef, "Constructor", modifiers, Opcodes.ACC_NATIVE, "native");
        node = node.getNextSibling();//ww  w .ja  va 2 s  . c  om
    }

    assertNodeType(PARAMETERS, node);
    Parameter[] parameters = parameters(node);
    if (parameters == null)
        parameters = Parameter.EMPTY_ARRAY;
    node = node.getNextSibling();

    ClassNode[] exceptions = ClassNode.EMPTY_ARRAY;
    if (isType(LITERAL_throws, node)) {
        AST throwsNode = node.getFirstChild();
        List<ClassNode> exceptionList = new ArrayList<>();
        throwsList(throwsNode, exceptionList);
        exceptions = exceptionList.toArray(exceptions);
        node = node.getNextSibling();
    }

    assertNodeType(SLIST, node);
    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    ConstructorNode constructorNode = classNode.addConstructor(modifiers, parameters, exceptions, null);
    MethodNode oldMethod = methodNode;
    methodNode = constructorNode;
    Statement code = statementList(node);
    methodNode = oldMethod;
    constructorNode.setCode(code);
    constructorNode.setSyntheticPublic(syntheticPublic);
    constructorNode.addAnnotations(annotations);
    configureAST(constructorNode, constructorDef);
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected int modifiers(AST modifierNode, List<AnnotationNode> annotations, int defaultModifiers) {
    assertNodeType(MODIFIERS, modifierNode);

    boolean access = false;
    int answer = 0;

    for (AST node = modifierNode.getFirstChild(); node != null; node = node.getNextSibling()) {
        int type = node.getType();
        switch (type) {
        case STATIC_IMPORT:
            // ignore
            break;

        // annotations
        case ANNOTATION:
            annotations.add(annotation(node));
            break;

        // core access scope modifiers
        case LITERAL_private:
            answer = setModifierBit(node, answer, Opcodes.ACC_PRIVATE);
            access = setAccessTrue(node, access);
            break;

        case LITERAL_protected:
            answer = setModifierBit(node, answer, Opcodes.ACC_PROTECTED);
            access = setAccessTrue(node, access);
            break;

        case LITERAL_public:
            answer = setModifierBit(node, answer, Opcodes.ACC_PUBLIC);
            access = setAccessTrue(node, access);
            break;

        // other modifiers
        case ABSTRACT:
            answer = setModifierBit(node, answer, Opcodes.ACC_ABSTRACT);
            break;

        case FINAL:
            answer = setModifierBit(node, answer, Opcodes.ACC_FINAL);
            break;

        case LITERAL_native:
            answer = setModifierBit(node, answer, Opcodes.ACC_NATIVE);
            break;

        case LITERAL_static:
            answer = setModifierBit(node, answer, Opcodes.ACC_STATIC);
            break;

        case STRICTFP:
            answer = setModifierBit(node, answer, Opcodes.ACC_STRICT);
            break;

        case LITERAL_synchronized:
            answer = setModifierBit(node, answer, Opcodes.ACC_SYNCHRONIZED);
            break;

        case LITERAL_transient:
            answer = setModifierBit(node, answer, Opcodes.ACC_TRANSIENT);
            break;

        case LITERAL_volatile:
            answer = setModifierBit(node, answer, Opcodes.ACC_VOLATILE);
            break;

        default://  w w w . j  a v a 2  s.  c  o  m
            unknownAST(node);
        }
    }
    if (!access) {
        answer |= defaultModifiers;
        // ACC_SYNTHETIC isn't used here, use it as a special flag
        if (defaultModifiers == Opcodes.ACC_PUBLIC)
            answer |= Opcodes.ACC_SYNTHETIC;
    }
    return answer;
}