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.javaweb.utils.ClassUtils.java

License:Apache License

/**
 * ??/*from   w w w. j  a v  a 2s  .c o  m*/
 *
 * @param cr
 * @return
 */
public static boolean isInterface(ClassReader cr) {
    return (cr.getAccess() & Opcodes.ACC_INTERFACE) != 0;
}

From source file:org.jboss.byteman.agent.check.ClassStructureAdapter.java

License:Open Source License

public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//w  w  w.j ava  2 s.c o m
    this.isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    this.interfaces = interfaces;
    this.superName = superName;
}

From source file:org.kantega.dogmaticmvc.instrumentation.MaxLineNumberClassVisitor.java

License:Apache License

public boolean isInterface() {
    return (access & Opcodes.ACC_INTERFACE) != 0;
}

From source file:org.kantega.notsoserial.ReadObjectClassVisitor.java

License:Apache License

private boolean isInterface() {
    return (access & Opcodes.ACC_INTERFACE) != 0;
}

From source file:org.mbte.groovypp.compiler.TraitASTTransform.java

License:Apache License

public void visit(ASTNode[] nodes, final SourceUnit source) {
    ModuleNode module = (ModuleNode) nodes[0];
    List<ClassNode> toProcess = new LinkedList<ClassNode>();
    final boolean forceTyped = source.getName().endsWith(".gpp");
    AnnotationNode pkgTypedAnn = getTypedAnnotation(module.getPackage());
    for (ClassNode classNode : module.getClasses()) {
        boolean process = false;
        boolean typed = false;
        for (AnnotationNode ann : classNode.getAnnotations()) {
            final String withoutPackage = ann.getClassNode().getNameWithoutPackage();
            if (withoutPackage.equals("Trait")) {
                process = true;//from  ww w  .j av a2 s .co m
            }
            if (withoutPackage.equals("Typed")) {
                typed = true;
                ann.getClassNode().setRedirect(TypeUtil.TYPED);
            }
        }

        if (forceTyped && !typed) {
            typed = true;
            classNode.addAnnotation(pkgTypedAnn != null ? pkgTypedAnn : new AnnotationNode(TypeUtil.TYPED));
        }

        if (process) {
            toProcess.add(classNode);
            if (!typed) {
                classNode.addAnnotation(pkgTypedAnn != null ? pkgTypedAnn : new AnnotationNode(TypeUtil.TYPED));
            }
        }
    }

    for (ClassNode classNode : toProcess) {
        if (classNode.isInterface() || classNode.isEnum() || classNode.isAnnotationDefinition()) {
            source.addError(new SyntaxException("@Trait can be applied only to <class>",
                    classNode.getLineNumber(), classNode.getColumnNumber()));
            continue;
        }

        if (classNode.getDeclaredConstructors().size() > 0) {
            ConstructorNode constructor = classNode.getDeclaredConstructors().get(0);
            source.addError(new SyntaxException("Constructors are not allowed in traits",
                    constructor.getLineNumber(), constructor.getColumnNumber()));
            continue;
        }

        if (classNode.getObjectInitializerStatements().size() > 0) {
            Statement initializer = classNode.getObjectInitializerStatements().get(0);
            source.addError(new SyntaxException("Object initializers are not allowed in traits",
                    initializer.getLineNumber(), initializer.getColumnNumber()));
            continue;
        }

        int mod = classNode.getModifiers();
        mod &= ~Opcodes.ACC_FINAL;
        mod |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE;
        classNode.setModifiers(mod);

        String name = classNode.getNameWithoutPackage() + "$TraitImpl";
        String fullName = ASTHelper.dot(classNode.getPackageName(), name);

        InnerClassNode innerClassNode = new InnerClassNode(classNode, fullName,
                ACC_PUBLIC | ACC_STATIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE, new ClassNode[] { classNode },
                null);
        AnnotationNode typedAnn = new AnnotationNode(TypeUtil.TYPED);
        final Expression member = getTypedAnnotation(classNode).getMember("debug");
        if (member != null && member instanceof ConstantExpression
                && ((ConstantExpression) member).getValue().equals(Boolean.TRUE))
            typedAnn.addMember("debug", ConstantExpression.TRUE);
        innerClassNode.addAnnotation(typedAnn);

        innerClassNode.setGenericsTypes(classNode.getGenericsTypes());

        ClassNode superClass = classNode.getSuperClass();
        if (!ClassHelper.OBJECT_TYPE.equals(superClass)) {
            ClassNode[] ifaces = classNode.getInterfaces();
            ClassNode[] newIfaces = new ClassNode[ifaces.length + 1];
            newIfaces[0] = superClass;
            System.arraycopy(ifaces, 0, newIfaces, 1, ifaces.length);
            classNode.setSuperClass(ClassHelper.OBJECT_TYPE);
            classNode.setInterfaces(newIfaces);
        }

        classNode.getModule().addClass(innerClassNode);

        innerClassNode.addMethod("getMetaClass", ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.METACLASS_TYPE,
                Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null);
        innerClassNode.addMethod("setMetaClass", ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.VOID_TYPE,
                new Parameter[] { new Parameter(ClassHelper.METACLASS_TYPE, "value") }, ClassNode.EMPTY_ARRAY,
                null);
        innerClassNode.addMethod("getProperty", ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE,
                new Parameter[] { new Parameter(ClassHelper.STRING_TYPE, "name") }, ClassNode.EMPTY_ARRAY,
                null);
        innerClassNode.addMethod("setProperty", ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.VOID_TYPE,
                new Parameter[] { new Parameter(ClassHelper.STRING_TYPE, "name"),
                        new Parameter(ClassHelper.OBJECT_TYPE, "value") },
                ClassNode.EMPTY_ARRAY, null);
        innerClassNode.addMethod("invokeMethod", ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE,
                new Parameter[] { new Parameter(ClassHelper.STRING_TYPE, "name"),
                        new Parameter(ClassHelper.OBJECT_TYPE, "args") },
                ClassNode.EMPTY_ARRAY, null);

        for (FieldNode fieldNode : classNode.getFields()) {
            //                if (fieldNode.isStatic())
            //                    continue;

            final String getterName = "get" + Verifier.capitalize(fieldNode.getName());
            MethodNode getter = classNode.getGetterMethod(getterName);
            if (getter == null) {
                getter = classNode.addMethod(getterName, ACC_PUBLIC | ACC_ABSTRACT, fieldNode.getType(),
                        Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null);
                addFieldAnnotation(innerClassNode, fieldNode, getter);
            }

            // We need the second getter (and setter) to compile non-synthetic first one referring to the field.
            // The references inside the first one will be retargeted to the second one.
            final MethodNode realGetter = classNode.addMethod("get$" + fieldNode.getName(),
                    ACC_PUBLIC | ACC_ABSTRACT, fieldNode.getType(), Parameter.EMPTY_ARRAY,
                    ClassNode.EMPTY_ARRAY, null);
            addFieldAnnotation(innerClassNode, fieldNode, realGetter);

            final String setterName = "set" + Verifier.capitalize(fieldNode.getName());
            Parameter valueParam = new Parameter(fieldNode.getType(), "$value");
            MethodNode setter = classNode.getSetterMethod(setterName);
            if (setter == null) {
                setter = classNode.addMethod(setterName, ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.VOID_TYPE,
                        new Parameter[] { valueParam }, ClassNode.EMPTY_ARRAY, null);
                addFieldAnnotation(innerClassNode, fieldNode, setter);
            }

            final MethodNode realSetter = classNode.addMethod("set$" + fieldNode.getName(),
                    ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.VOID_TYPE, new Parameter[] { valueParam },
                    ClassNode.EMPTY_ARRAY, null);
            addFieldAnnotation(innerClassNode, fieldNode, realSetter);

            if (fieldNode.hasInitialExpression()) {
                final Expression initial = fieldNode.getInitialValueExpression();
                fieldNode.setInitialValueExpression(null);

                final MethodNode initMethod = innerClassNode.addMethod("__init_" + fieldNode.getName(),
                        ACC_PUBLIC | ACC_STATIC, ClassHelper.VOID_TYPE,
                        new Parameter[] { new Parameter(classNode, "$self") }, ClassNode.EMPTY_ARRAY,
                        new BlockStatement());

                final PropertyExpression prop = new PropertyExpression(new VariableExpression("$self"),
                        fieldNode.getName());
                prop.setSourcePosition(fieldNode);
                final CastExpression cast = new CastExpression(fieldNode.getType(), initial);
                cast.setSourcePosition(initial);
                final BinaryExpression assign = new BinaryExpression(prop,
                        Token.newSymbol(Types.ASSIGN, -1, -1), cast);
                assign.setSourcePosition(initial);
                final ExpressionStatement assignExpr = new ExpressionStatement(assign);
                assignExpr.setSourcePosition(initial);
                ((BlockStatement) initMethod.getCode()).addStatement(assignExpr);
            }

            innerClassNode.addField(fieldNode);
        }

        classNode.getFields().clear();
        classNode.getProperties().clear();

        for (MethodNode methodNode : classNode.getMethods()) {
            if (methodNode.getCode() == null)
                continue;

            if (methodNode.isStatic()) {
                source.addError(new SyntaxException("Static methods are not allowed in traits",
                        methodNode.getLineNumber(), methodNode.getColumnNumber()));
            }

            if (!methodNode.isPublic()) {
                source.addError(new SyntaxException("Non-public methods are not allowed in traits",
                        methodNode.getLineNumber(), methodNode.getColumnNumber()));
            }

            mod = methodNode.getModifiers();
            mod &= ~(Opcodes.ACC_FINAL | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
            mod |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_PUBLIC;
            methodNode.setModifiers(mod);

            Parameter[] parameters = methodNode.getParameters();

            Parameter[] newParameters = new Parameter[parameters.length + 1];
            final Parameter self = new Parameter(classNode, "$self");
            newParameters[0] = self;
            System.arraycopy(parameters, 0, newParameters, 1, parameters.length);

            MethodNode newMethod = innerClassNode.addMethod(methodNode.getName(), ACC_PUBLIC,
                    methodNode.getReturnType(), newParameters, ClassNode.EMPTY_ARRAY, methodNode.getCode());
            ArrayList<GenericsType> gt = new ArrayList<GenericsType>();
            if (classNode.getGenericsTypes() != null)
                for (int i = 0; i < classNode.getGenericsTypes().length; i++) {
                    GenericsType genericsType = classNode.getGenericsTypes()[i];
                    gt.add(genericsType);
                }
            if (methodNode.getGenericsTypes() != null)
                for (int i = 0; i < methodNode.getGenericsTypes().length; i++) {
                    GenericsType genericsType = methodNode.getGenericsTypes()[i];
                    gt.add(genericsType);
                }

            if (!gt.isEmpty())
                newMethod.setGenericsTypes(gt.toArray(new GenericsType[gt.size()]));

            AnnotationNode annotationNode = new AnnotationNode(TypeUtil.HAS_DEFAULT_IMPLEMENTATION);
            annotationNode.addMember("value", new ClassExpression(innerClassNode));
            methodNode.addAnnotation(annotationNode);

            methodNode.setCode(null);
        }
    }
}

From source file:org.openspotlight.bundle.language.java.asm.TypeExtractorVisitor.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w w w.j  a  v  a2s .  c  o  m*/
 */
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {
    type = new TypeDefinition();

    Pair<String, String> packageAndTypeName = getPackageAndTypeNames(name);
    type.setPackageName(packageAndTypeName.getK1());
    type.setTypeName(packageAndTypeName.getK2());

    if ((access & Opcodes.ACC_INTERFACE) > 0) {
        type.setType(JavaTypes.INTERFACE);
    } else if ((access & Opcodes.ACC_ENUM) > 0) {
        type.setType(JavaTypes.ENUM);
    } else if ((access & Opcodes.ACC_ANNOTATION) > 0) {
        type.setType(JavaTypes.ANNOTATION);
    } else {
        type.setType(JavaTypes.CLASS);
    }
    type.setAccess(access);

    if ((access & Opcodes.ACC_PRIVATE) > 0) {
        type.setPrivate(true);
    }

    if (superName != null) {
        Pair<String, String> superPackageAndTypeName = getPackageAndTypeNames(superName);
        SimpleTypeReference superType = new SimpleTypeReference(superPackageAndTypeName.getK1(),
                superPackageAndTypeName.getK2());
        type.setExtendsDef(superType);
    }

    for (String interfaceName : interfaces) {
        Pair<String, String> interfacePackageAndTypeName = getPackageAndTypeNames(interfaceName);
        SimpleTypeReference interfaceType = new SimpleTypeReference(interfacePackageAndTypeName.getK1(),
                interfacePackageAndTypeName.getK2());
        type.getImplementsDef().add(interfaceType);
    }
}

From source file:org.pitest.classinfo.ClassInfo.java

License:Apache License

public boolean isInterface() {
    return (this.access & Opcodes.ACC_INTERFACE) != 0;
}

From source file:org.rascalmpl.library.lang.java.m3.internal.JarConverter.java

License:Open Source License

@SuppressWarnings("unchecked")
public void convert(ISourceLocation jarLoc, IEvaluatorContext ctx) {

    this.loc = jarLoc;
    this.jarFile = extractJarName(jarLoc);
    this.ClassFile = extractClassName(jarLoc);
    this.LogPath = this.ClassFile.replace(".class", "");
    String packageName;/*from w  ww .  j a  v a  2  s  . c  o  m*/

    // System.out.println(this.ClassFile);
    packageName = LogPath.substring(0, LogPath.lastIndexOf("/"));
    if (this.LogPath.contains("$")) {
        this.LogPath = LogPath.replace("$", "/");
    }
    try {
        ClassReader cr = new ClassReader(URIResolverRegistry.getInstance().getInputStream(jarLoc));
        ClassNode cn = new ClassNode();

        cr.accept(cn, ClassReader.SKIP_DEBUG);

        this.className = cn.name.replace("$", "/");
        classIsEnum = false;
        if ((cn.access & Opcodes.ACC_INTERFACE) != 0)
            classScheme = "java+interface";
        else if ((cn.access & Opcodes.ACC_ENUM) != 0) {
            classScheme = "java+enum";
            classIsEnum = true;
        } else
            this.classScheme = "java+class";

        this.insert(this.containment, values.sourceLocation(classScheme, "", "/" + className),
                values.sourceLocation("java+compilationUnit", "", "/jar:///" + jarFile));
        this.insert(this.containment, values.sourceLocation("java+package", "", "/" + packageName),
                values.sourceLocation("java+compilationUnit", "", "/jar:///" + jarFile));
        this.insert(this.containment, values.sourceLocation("java+compilationUnit", "", "/jar:///" + jarFile),
                values.sourceLocation("java+class", "", "/" + LogPath));

        // <|java+package:///Main|,|java+compilationUnit:///src/Main/BaseInt.java|>,

        this.insert(this.declarations, values.sourceLocation(classScheme, "", "/" + className),
                values.sourceLocation(jarFile + "!" + ClassFile));

        if (cn.superName != null && !(cn.superName.equalsIgnoreCase("java/lang/Object")
                || cn.superName.equalsIgnoreCase("java/lang/Enum"))) {
            this.insert(this.extendsRelations, values.sourceLocation(classScheme, "", "/" + className),
                    values.sourceLocation(classScheme, "", cn.superName));
        }

        for (int fs = 0; fs < 15; fs++) {
            if ((cn.access & (0x0001 << fs)) != 0) {
                IConstructor cons = mapFieldAccesCode(0x0001 << fs, CLASSE);
                if (cons != null)
                    this.insert(this.modifiers, values.sourceLocation(classScheme, "", "/" + className), cons);
            }
        }

        // Deprecated method emit type annotation dependency Deprecated.
        if ((cn.access & 0x20000) == 0x20000)
            this.insert(this.annotations, values.sourceLocation(classScheme, "", "/" + className),
                    values.sourceLocation("java+interface", "", "/java/lang/Deprecated"));

        // @implements={<|java+class:///m3startv2/viaInterface|,|java+interface:///m3startv2/m3Interface|>},
        for (int i = 0; i < cn.interfaces.size(); ++i) {
            String iface = (String) cn.interfaces.get(i);
            // System.out.println(iface);
            this.insert(this.implementsRelations, values.sourceLocation(classScheme, "", "/" + className),
                    values.sourceLocation("java+interface", "", "/" + iface));
        }

        for (int fs = 0; fs < cn.innerClasses.size(); fs++) {
            InnerClassNode a = (InnerClassNode) cn.innerClasses.get(fs);
            String parsedName = a.name.replace("$", "/");
            this.insert(this.containment, values.sourceLocation(classScheme, "", "/" + className),
                    values.sourceLocation(classScheme, "", "/" + parsedName));
        }

        emitMethods(cn.methods);
        emitFields(cn.fields);

    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        throw new RuntimeException("Should not happen", e);
    }
}

From source file:org.sonar.java.bytecode.asm.AsmAccessFlags.java

License:Open Source License

public static boolean isInterface(int accessFlags) {
    return (accessFlags & Opcodes.ACC_INTERFACE) != 0;
}

From source file:org.sonar.java.resolve.FlagsTest.java

License:Open Source License

/**
 * Flags can be easily loaded from class-files into symbols.
 *///from  www. j a  v  a2 s. c  o  m
@Test
public void flags_match_asm_opcodes() {
    assertThat(Flags.PUBLIC).isEqualTo(Opcodes.ACC_PUBLIC);
    assertThat(Flags.PRIVATE).isEqualTo(Opcodes.ACC_PRIVATE);
    assertThat(Flags.PROTECTED).isEqualTo(Opcodes.ACC_PROTECTED);
    assertThat(Flags.STATIC).isEqualTo(Opcodes.ACC_STATIC);
    assertThat(Flags.FINAL).isEqualTo(Opcodes.ACC_FINAL);
    assertThat(Flags.SYNCHRONIZED).isEqualTo(Opcodes.ACC_SYNCHRONIZED);
    assertThat(Flags.VOLATILE).isEqualTo(Opcodes.ACC_VOLATILE);
    assertThat(Flags.TRANSIENT).isEqualTo(Opcodes.ACC_TRANSIENT);
    assertThat(Flags.NATIVE).isEqualTo(Opcodes.ACC_NATIVE);
    assertThat(Flags.INTERFACE).isEqualTo(Opcodes.ACC_INTERFACE);
    assertThat(Flags.ABSTRACT).isEqualTo(Opcodes.ACC_ABSTRACT);
    assertThat(Flags.STRICTFP).isEqualTo(Opcodes.ACC_STRICT);
    assertThat(Flags.SYNTHETIC).isEqualTo(Opcodes.ACC_SYNTHETIC);
    assertThat(Flags.ANNOTATION).isEqualTo(Opcodes.ACC_ANNOTATION);
    assertThat(Flags.ENUM).isEqualTo(Opcodes.ACC_ENUM);
}