Example usage for org.objectweb.asm Opcodes ACC_ANNOTATION

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

Introduction

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

Prototype

int ACC_ANNOTATION

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

Click Source Link

Usage

From source file:org.apache.felix.ipojo.manipulator.metadata.annotation.ClassMetadataCollector.java

License:Apache License

/**
 * End of the visit : compute final elements.
 *
 * @see org.objectweb.asm.ClassVisitor#visitEnd()
 *///  w ww.j  a  v  a2  s .  c  om
@Override
public void visitEnd() {
    // Only process real class (no annotations, no interfaces)
    if (!(is(Opcodes.ACC_ANNOTATION) || is(Opcodes.ACC_INTERFACE) || is(Opcodes.ACC_ABSTRACT))) {
        if (workbench.getRoot() == null) {
            // No 'top-level' element has been contributed

            if (workbench.ignore()) {
                // Ignore this class.
                return;
            }

            if (!workbench.getElements().isEmpty()) {
                // There are other annotation's contribution on this type (additional handler declaration/configuration)
                // That means that there is a missing 'component type' annotation

                reporter.warn(
                        "Class %s has not been marked as a component type (no @Component, @Handler, "
                                + "...). It will be ignored by the iPOJO manipulator.",
                        workbench.getType().getClassName());
                return;
            } // else: no root and no elements
            return;
        }

        componentMetadata = workbench.build();
        instanceMetadata = workbench.getInstance();

        // If we have an instance declared and the component metadata has a name, we update the component's attribute
        // of the instance (https://issues.apache.org/jira/browse/FELIX-4052).
        if (componentMetadata != null && componentMetadata.containsAttribute("name")
                && instanceMetadata != null) {
            // Update the component attribute
            instanceMetadata.addAttribute(new Attribute("component", componentMetadata.getAttribute("name")));
        }

    }
}

From source file:org.apache.groovy.parser.antlr4.AstBuilder.java

License:Apache License

@Override
public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) {
    String packageName = moduleNode.getPackageName();
    packageName = null != packageName ? packageName : "";

    List<ModifierNode> modifierNodeList = ctx.getNodeMetaData(TYPE_DECLARATION_MODIFIERS);
    Objects.requireNonNull(modifierNodeList, "modifierNodeList should not be null");

    ModifierManager modifierManager = new ModifierManager(this, modifierNodeList);
    int modifiers = modifierManager.getClassModifiersOpValue();

    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;

    final ClassNode outerClass = classNodeStack.peek();
    ClassNode classNode;// w ww  .  ja  va 2  s .  c o  m
    String className = this.visitIdentifier(ctx.identifier());

    if (VAR_STR.equals(className)) {
        throw createParsingFailedException("var cannot be used for type declarations", ctx.identifier());
    }

    if (asBoolean(ctx.ENUM())) {
        classNode = EnumHelper.makeEnumNode(asBoolean(outerClass) ? className : packageName + className,
                modifiers, null, outerClass);
    } else {
        if (asBoolean(outerClass)) {
            classNode = new InnerClassNode(outerClass, outerClass.getName() + "$" + className,
                    modifiers | (outerClass.isInterface() ? Opcodes.ACC_STATIC : 0), ClassHelper.OBJECT_TYPE);
        } else {
            classNode = new ClassNode(packageName + className, modifiers, ClassHelper.OBJECT_TYPE);
        }
    }

    configureAST(classNode, ctx);
    classNode.putNodeMetaData(CLASS_NAME, className);
    classNode.setSyntheticPublic(syntheticPublic);

    if (asBoolean(ctx.TRAIT())) {
        attachTraitAnnotation(classNode);
    }
    classNode.addAnnotations(modifierManager.getAnnotations());
    classNode.setGenericsTypes(this.visitTypeParameters(ctx.typeParameters()));

    boolean isInterface = asBoolean(ctx.INTERFACE()) && !asBoolean(ctx.AT());
    boolean isInterfaceWithDefaultMethods = false;

    // declaring interface with default method
    if (isInterface && this.containsDefaultMethods(ctx)) {
        isInterfaceWithDefaultMethods = true;
        attachTraitAnnotation(classNode);
        classNode.putNodeMetaData(IS_INTERFACE_WITH_DEFAULT_METHODS, true);
    }

    if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()) || isInterfaceWithDefaultMethods) { // class OR trait OR interface with default methods
        classNode.setSuperClass(this.visitType(ctx.sc));
        classNode.setInterfaces(this.visitTypeList(ctx.is));

        this.initUsingGenerics(classNode);
    } else if (isInterface) { // interface(NOT annotation)
        classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT);

        classNode.setSuperClass(ClassHelper.OBJECT_TYPE);
        classNode.setInterfaces(this.visitTypeList(ctx.scs));

        this.initUsingGenerics(classNode);

        this.hackMixins(classNode);
    } else if (asBoolean(ctx.ENUM())) { // enum
        classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL);

        classNode.setInterfaces(this.visitTypeList(ctx.is));

        this.initUsingGenerics(classNode);
    } else if (asBoolean(ctx.AT())) { // annotation
        classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT
                | Opcodes.ACC_ANNOTATION);

        classNode.addInterface(ClassHelper.Annotation_TYPE);

        this.hackMixins(classNode);
    } else {
        throw createParsingFailedException("Unsupported class declaration: " + ctx.getText(), ctx);
    }

    // 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
    if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())) {
        classNodeList.add(classNode);
    }

    classNodeStack.push(classNode);
    ctx.classBody().putNodeMetaData(CLASS_DECLARATION_CLASS_NODE, classNode);
    this.visitClassBody(ctx.classBody());
    classNodeStack.pop();

    if (!(asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()))) {
        classNodeList.add(classNode);
    }

    groovydocManager.handle(classNode, ctx);

    return classNode;
}

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

License:Open Source License

/**
 * @inheritDoc// w ww.j a  v  a 2 s .c o m
 */
@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {

    // get the type
    _type = Type.getObjectType(name);

    // get the abstract flag
    boolean abstractType = ((access & Opcodes.ACC_ABSTRACT) != 0);

    // get the type type
    TypeEnum typeEnum = null;
    if ((access & Opcodes.ACC_ENUM) != 0) {
        typeEnum = TypeEnum.ENUM;
    } else if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        typeEnum = TypeEnum.ANNOTATION;
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        typeEnum = TypeEnum.INTERFACE;
        abstractType = true;
    } else {
        typeEnum = TypeEnum.CLASS;
    }

    // get the fully qualified name
    String fullyQualifiedName = VisitorUtils.getFullyQualifiedTypeName(_type);

    // record the contained type
    _recorder.recordContainedType(fullyQualifiedName, typeEnum, abstractType);

    if (_analyzeReferences) {

        // super type
        // TODO: USES
        Type superType = Type.getObjectType(superName);
        VisitorUtils.recordReferencedTypes(_recorder, true, false, false, superType);
        //
        for (String interfaceName : interfaces) {

            // implemented interfaces
            // TODO: USES
            Type implementsType = Type.getObjectType(interfaceName);
            VisitorUtils.recordReferencedTypes(_recorder, false, true, false, implementsType);
        }
    }
}

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();//  ww w. j  av a  2 s .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.parser.antlr4.ASTBuilder.java

License:Apache License

public ClassNode parseClassDeclaration(final GroovyLangParser.ClassDeclarationContext ctx) {
    boolean isEnum = asBoolean(ctx.KW_ENUM());

    final ClassNode outerClass = asBoolean(classNodeStack) ? classNodeStack.peek() : null;
    ClassNode[] interfaces = asBoolean(ctx.implementsClause())
            ? collect(ctx.implementsClause().genericClassNameExpression(), new Closure<ClassNode>(this, this) {
                public ClassNode doCall(GroovyLangParser.GenericClassNameExpressionContext it) {
                    return parseExpression(it);
                }/*w  w w.  jav a 2  s.c  om*/
            }).toArray(new ClassNode[0])
            : new ClassNode[0];

    ClassNode classNode;
    String packageName = moduleNode.getPackageName();
    packageName = packageName != null && asBoolean(packageName) ? packageName : "";

    if (isEnum) {
        classNode = EnumHelper.makeEnumNode(
                asBoolean(outerClass) ? ctx.IDENTIFIER().getText() : packageName + ctx.IDENTIFIER().getText(),
                Modifier.PUBLIC, interfaces, outerClass);
    } else {
        if (outerClass != null) {
            String name = outerClass.getName() + "$" + String.valueOf(ctx.IDENTIFIER());
            classNode = new InnerClassNode(outerClass, name, Modifier.PUBLIC, ClassHelper.OBJECT_TYPE);
        } else {
            classNode = new ClassNode(packageName + String.valueOf(ctx.IDENTIFIER()), Modifier.PUBLIC,
                    ClassHelper.OBJECT_TYPE);
        }
    }

    setupNodeLocation(classNode, ctx);

    if (asBoolean(ctx.KW_TRAIT())) {
        attachTraitTransformAnnotation(classNode);
    }

    attachAnnotations(classNode, ctx.annotationClause());

    //        moduleNode.addClass(classNode);
    classes.add(classNode);
    if (asBoolean(ctx.extendsClause())) {
        if (asBoolean(ctx.KW_INTERFACE()) && !asBoolean(ctx.AT())) { // interface(NOT annotation)
            List<ClassNode> interfaceList = new LinkedList<ClassNode>();
            for (GroovyLangParser.GenericClassNameExpressionContext genericClassNameExpressionContext : ctx
                    .extendsClause().genericClassNameExpression()) {
                interfaceList.add(parseExpression(genericClassNameExpressionContext));
            }
            (classNode).setInterfaces(interfaceList.toArray(new ClassNode[0]));
            (classNode).setSuperClass(ClassHelper.OBJECT_TYPE);
        } else {
            (classNode).setSuperClass(parseExpression(ctx.extendsClause().genericClassNameExpression(0)));
        }

    }

    if (asBoolean(ctx.implementsClause())) {
        (classNode).setInterfaces(interfaces);
    }

    if (!isEnum) {
        (classNode).setGenericsTypes(parseGenericDeclaration(ctx.genericDeclarationList()));
        (classNode).setUsingGenerics(
                (classNode.getGenericsTypes() != null && classNode.getGenericsTypes().length != 0)
                        || (classNode).getSuperClass().isUsingGenerics() || DefaultGroovyMethods
                                .any(classNode.getInterfaces(), new Closure<Boolean>(this, this) {
                                    public Boolean doCall(ClassNode it) {
                                        return it.isUsingGenerics();
                                    }
                                }));
    }

    classNode.setModifiers(
            parseClassModifiers(ctx.classModifier()) | (isEnum ? (Opcodes.ACC_ENUM | Opcodes.ACC_FINAL)
                    : ((asBoolean(ctx.KW_INTERFACE()) ? Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT : 0))));

    classNode.setSyntheticPublic((classNode.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0);
    classNode.setModifiers(classNode.getModifiers() & ~Opcodes.ACC_SYNTHETIC);// FIXME Magic with synthetic modifier.

    if (asBoolean(ctx.AT())) {
        classNode.addInterface(ClassHelper.Annotation_TYPE);
        classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ANNOTATION);
    }

    classNodeStack.add(classNode);
    parseClassBody(classNode, ctx.classBody());
    classNodeStack.pop();

    if (classNode.isInterface()) { // FIXME why interface has null mixin
        try {
            // FIXME Hack with visibility.
            Field field = ClassNode.class.getDeclaredField("mixins");
            field.setAccessible(true);
            field.set(classNode, null);
        } catch (IllegalAccessException e) {
            log.warning(createExceptionMessage(e));
        } catch (NoSuchFieldException e) {
            log.warning(createExceptionMessage(e));
        }
    }

    this.attachDocCommentAsMetaData(classNode, ctx);

    return classNode;
}

From source file:org.eclipse.pde.api.tools.internal.model.ApiType.java

License:Open Source License

@Override
public boolean isAnnotation() {
    return (getModifiers() & Opcodes.ACC_ANNOTATION) != 0;
}

From source file:org.eclipse.pde.api.tools.internal.model.ApiType.java

License:Open Source License

@Override
public boolean isClass() {
    return (getModifiers() & (Opcodes.ACC_ANNOTATION | Opcodes.ACC_ENUM | Opcodes.ACC_INTERFACE)) == 0;
}

From source file:org.eclipse.pde.api.tools.internal.util.Util.java

License:Open Source License

/**
 * Returns if the flags are for a class/*from w w w.ja  v  a  2 s.c o  m*/
 * 
 * @param accessFlags the given access flags
 * @return
 */
public static boolean isClass(int accessFlags) {
    return (accessFlags & (Opcodes.ACC_ENUM | Opcodes.ACC_ANNOTATION | Opcodes.ACC_INTERFACE)) == 0;
}

From source file:org.evosuite.symbolic.instrument.AccessFlags.java

License:Open Source License

static boolean isAnnotation(int access) {
    return is(access, Opcodes.ACC_ANNOTATION);
}

From source file:org.freud.analysed.classbytecode.parser.asm.AsmClassByteCode.java

License:Apache License

@Override
public boolean isAnnotation() {
    return isAccessModifier(Opcodes.ACC_ANNOTATION);
}