Example usage for org.objectweb.asm Opcodes ACC_INTERFACE

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

Introduction

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

Prototype

int ACC_INTERFACE

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

Click Source Link

Usage

From source file:org.apache.sling.metrics.impl.MetricsWeavingHook.java

License:Apache License

@Override
public void weave(@Nonnull WovenClass wovenClass) {
    if (foreignBundle(wovenClass)) {
        ClassReader cr = new ClassReader(wovenClass.getBytes());
        String[] ancestors = toStringArray(loadAncestors(cr, new HashSet<String>()));
        if (activator.getMetricsConfig().addMetrics(wovenClass.getClassName(), ancestors)) {
            activator.log(LogService.LOG_DEBUG, "Adding Metrics to class " + wovenClass.getClassName());
            try {
                if ((cr.getAccess() & Opcodes.ACC_INTERFACE) != Opcodes.ACC_INTERFACE) {
                    ClassWriter cw = new OSGiFriendlyClassWriter(
                            ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES,
                            wovenClass.getBundleWiring().getClassLoader(), activator, wovenClass.getClassName(),
                            activator.getMetricsConfig().dumpClass(wovenClass.getClassName()));

                    MetricsClassVisitor mcv = new MetricsClassVisitor(cw, wovenClass.getClassName(), ancestors,
                            activator.getMetricsConfig(), activator);
                    cr.accept(mcv, ClassReader.SKIP_FRAMES);
                    if (mcv.isWoven()) {
                        wovenClass.setBytes(cw.toByteArray());
                        if (mcv.additionalImportRequired())
                            wovenClass.getDynamicImports().add(addedImport);
                    }/*from w w w.  j a  v a  2 s.  c  om*/
                    mcv.finish();
                } else {
                    activator.log(LogService.LOG_DEBUG,
                            "Not weaving interface, no non abstract methods on " + wovenClass.getClassName());
                }

            } catch (Exception e) {
                activator.log(LogService.LOG_DEBUG,
                        "Unable to weave class " + wovenClass.getClassName() + " cause " + e.getMessage());
            }
        }

    }
}

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

License:Apache License

public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from w  ww  .  ja  va 2s  .co  m
    type = Type.getObjectType(name);

    String className = type.getClassName();
    int dot = className.lastIndexOf('.');
    if (dot != -1) {
        packageName = className.substring(0, dot);
        className = className.substring(dot + 1);
    }

    metadata.set(TikaCoreProperties.TITLE, className);
    metadata.set(Metadata.RESOURCE_NAME_KEY, className + ".class");

    try {
        xhtml.startDocument();
        xhtml.startElement("pre");

        if (packageName != null) {
            writeKeyword("package");
            xhtml.characters(" " + packageName + ";\n");
        }

        writeAccess(access);
        if (isSet(access, Opcodes.ACC_INTERFACE)) {
            writeKeyword("interface");
            writeSpace();
            writeType(type);
            writeSpace();
            writeInterfaces("extends", interfaces);
        } else if (isSet(access, Opcodes.ACC_ENUM)) {
            writeKeyword("enum");
            writeSpace();
            writeType(type);
            writeSpace();
        } else {
            writeKeyword("class");
            writeSpace();
            writeType(type);
            writeSpace();
            if (superName != null) {
                Type superType = Type.getObjectType(superName);
                if (!superType.getClassName().equals("java.lang.Object")) {
                    writeKeyword("extends");
                    writeSpace();
                    writeType(superType);
                    writeSpace();
                }
            }
            writeInterfaces("implements", interfaces);
        }
        xhtml.characters("{\n");
    } catch (SAXException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.tuscany.sdo.codegen.BytecodeInterfaceGenerator.java

License:Apache License

public void visitType(Type type) {
    String name = type.getName();
    int lastDot = name.lastIndexOf('.');
    if (lastDot != -1) {
        name = name.replace('.', '/');
    } else {/*from w  w  w. j a  v a2s . com*/
        name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
    }

    List baseTypes = type.getBaseTypes();
    String[] interfaces = new String[baseTypes.size()];
    for (int i = 0; i < baseTypes.size(); i++) {
        Type baseType = (Type) baseTypes.get(i);
        interfaces[i] = baseType.getInstanceClass().getName().replace('.', '/');
    }

    cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, name, null,
            "java/lang/Object", interfaces);
}

From source file:org.ballerinalang.compiler.backend.jvm.ClassVerifier.java

License:Open Source License

/**
 * This method is an extension of//from  w w  w  . j  ava2s  . c o  m
 * {@code jdk.internal.org.objectweb.asm.util.CheckClassAdapter#verify(ClassReader, boolean, java.io.PrintWriter)}.
 * 
 * @param bytes Bytes stream of the class to be verified.
 * @return An optional error, if there are verification errors.
 */
private static Optional<ErrorValue> verify(byte[] bytes, ClassLoader classLoader) {
    ClassReader classReader = new ClassReader(bytes);
    ClassNode classNode = new ClassNode();
    classReader.accept(new CheckClassAdapter(Opcodes.ASM7, classNode, false) {
    }, ClassReader.SKIP_DEBUG);

    Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName);
    List<MethodNode> methods = classNode.methods;

    List<Type> interfaces = new ArrayList<>();
    for (String interfaceName : classNode.interfaces) {
        interfaces.add(Type.getObjectType(interfaceName));
    }

    for (MethodNode method : methods) {
        SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(classNode.name), syperType, interfaces,
                (classNode.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> analyzer = new Analyzer<>(verifier);
        if (classLoader != null) {
            verifier.setClassLoader(classLoader);
        }
        try {
            analyzer.analyze(classNode.name, method);
        } catch (AnalyzerException e) {
            return Optional.of(BallerinaErrors.createError(e.getMessage()));
        }
    }

    return Optional.empty();
}

From source file:org.boretti.drools.integration.drools5.DroolsClassVisitor.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from   w w w .  j ava2  s  .  com
    if (version < Opcodes.V1_6) {
        allowed = false;
        logger.warn("Version of the class " + name + " is not enough to be supported");
    } else if ((access & Opcodes.ACC_INTERFACE) > 0) {
        allowed = false;
    }
    me = name;
    super.visit(version, access, name, signature, superName, interfaces);
}

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

License:Open Source License

/**
 * @inheritDoc/*from w w  w . 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();// w ww.j a  va  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.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();//from   w  w w .j  a va  2  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

private boolean isAnInterface() {
    return classNode != null && (classNode.getModifiers() & Opcodes.ACC_INTERFACE) > 0;
}

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);
                }/*from w ww.  jav a 2s .  c  o m*/
            }).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;
}