Example usage for org.objectweb.asm Opcodes ACC_ABSTRACT

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

Introduction

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

Prototype

int ACC_ABSTRACT

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

Click Source Link

Usage

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

License:Open Source License

public static boolean isAbstract(int accessFlags) {
    return (accessFlags & Opcodes.ACC_ABSTRACT) != 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   w w  w.  j  a  v a 2s.c  om
@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);
}

From source file:org.sonatype.guice.bean.scanners.QualifiedTypeVisitor.java

License:Open Source License

@Override
public void visit(final int version, final int access, final String name, final String signature,
        final String superName, final String[] interfaces) {
    if ((access & (Opcodes.ACC_INTERFACE | access & Opcodes.ACC_ABSTRACT | Opcodes.ACC_SYNTHETIC)) == 0) {
        clazzName = name; // concrete type
    }//from ww  w  . j  ava2s  . c om
}

From source file:org.sonatype.guice.nexus.scanners.NexusTypeVisitor.java

License:Open Source License

@Override
public void visit(final int version, final int access, final String name, final String signature,
        final String superName, final String[] interfaces) {
    final String clazz = name.replace('/', '.');
    nexusTypeListener.hear(clazz);/* w  ww  . java  2 s  .c o m*/

    if ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_SYNTHETIC)) == 0) {
        scanForNexusMarkers(clazz, interfaces);
    }
    plexusTypeVisitor.visit(version, access, name, signature, superName, interfaces);
}

From source file:org.sonatype.guice.plexus.scanners.PlexusTypeVisitor.java

License:Open Source License

@Override
public void visit(final int version, final int access, final String name, final String signature,
        final String superName, final String[] interfaces) {
    if ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_SYNTHETIC)) == 0) {
        implementation = name.replace('/', '.');
    }/*w  w w. ja v a  2 s  .co  m*/
    qualifiedTypeVisitor.visit(version, access, name, signature, superName, interfaces);
}

From source file:org.spockframework.buildsupport.SpecClassFileVisitor.java

License:Apache License

public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from  w  ww  .  j  av  a2s  .  c  om
    isAbstract = (access & Opcodes.ACC_ABSTRACT) != 0;
}

From source file:org.spongepowered.asm.mixin.transformer.MixinTransformer.java

License:MIT License

/**
 * Mixin methods from the mixin class into the target class
 * //from   w ww.j  a va2  s. co m
 * @param targetClass
 * @param mixin
 */
private void applyMixinMethods(ClassNode targetClass, MixinTargetContext mixin) {
    for (MethodNode mixinMethod : mixin.getClassNode().methods) {
        // Reparent all mixin methods into the target class
        mixin.transformMethod(mixinMethod);

        boolean isShadow = ASMHelper.getVisibleAnnotation(mixinMethod, Shadow.class) != null;
        boolean isOverwrite = ASMHelper.getVisibleAnnotation(mixinMethod, Overwrite.class) != null;
        boolean isAbstract = MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_ABSTRACT);

        if (isShadow || isAbstract) {
            // For shadow (and abstract, which can be used as a shorthand for Shadow) methods, we just check they're present
            MethodNode target = this.findTargetMethod(targetClass, mixinMethod);
            if (target == null) {
                throw new InvalidMixinException(mixin, String
                        .format("Shadow method %s was not located in the target class", mixinMethod.name));
            }
        } else if (!mixinMethod.name.startsWith("<")) {
            if (MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_STATIC)
                    && !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_PRIVATE)
                    && !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_SYNTHETIC) && !isOverwrite) {
                throw new InvalidMixinException(mixin,
                        String.format("Mixin classes cannot contain visible static methods or fields, found %s",
                                mixinMethod.name));
            }

            this.mergeMethod(targetClass, mixin, mixinMethod, isOverwrite);
        } else if (MixinTransformer.CLINIT.equals(mixinMethod.name)) {
            // Class initialiser insns get appended
            this.appendInsns(targetClass, mixinMethod.name, mixinMethod);
        }
    }
}

From source file:org.spongepowered.mod.asm.transformers.MixinTransformer.java

License:MIT License

/**
 * Mixin methods from the mixin class into the target class
 * /*from  w  w  w . j av a 2s.c o m*/
 * @param targetClass
 * @param mixin
 */
private void applyMixinMethods(ClassNode targetClass, MixinData mixin) {
    for (MethodNode mixinMethod : mixin.getClassNode().methods) {
        // Reparent all mixin methods into the target class
        this.transformMethod(mixinMethod, mixin.getClassNode().name, targetClass.name);

        boolean isShadow = ASMHelper.getVisibleAnnotation(mixinMethod, Shadow.class) != null;
        boolean isOverwrite = ASMHelper.getVisibleAnnotation(mixinMethod, Overwrite.class) != null;
        boolean isAbstract = MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_ABSTRACT);

        if (isShadow || isAbstract) {
            // For shadow (and abstract, which can be used as a shorthand for Shadow) methods, we just check they're present
            MethodNode target = this.findTargetMethod(targetClass, mixinMethod);
            if (target == null) {
                throw new InvalidMixinException(String
                        .format("Shadow method %s was not located in the target class", mixinMethod.name));
            }
        } else if (!mixinMethod.name.startsWith("<")) {
            if (MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_STATIC)
                    && !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_PRIVATE) && !isOverwrite) {
                throw new InvalidMixinException(
                        String.format("Mixin classes cannot contain visible static methods or fields, found %s",
                                mixinMethod.name));
            }

            MethodNode target = this.findTargetMethod(targetClass, mixinMethod);
            if (target != null) {
                targetClass.methods.remove(target);
            } else if (isOverwrite) {
                throw new InvalidMixinException(String
                        .format("Overwrite target %s was not located in the target class", mixinMethod.name));
            }
            targetClass.methods.add(mixinMethod);
        } else if ("<clinit>".equals(mixinMethod.name)) {
            // Class initialiser insns get appended
            this.appendInsns(targetClass, mixinMethod.name, mixinMethod);
        }
    }
}

From source file:org.springframework.core.type.classreading.ClassMetadataReadingVisitor.java

License:Apache License

public void visit(int version, int access, String name, String signature, String supername,
        String[] interfaces) {//from   w w w .j  a  v a2  s .  c om
    this.className = ClassUtils.convertResourcePathToClassName(name);
    this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
    this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
    this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
    if (supername != null) {
        this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
    }
    this.interfaces = new String[interfaces.length];
    for (int i = 0; i < interfaces.length; i++) {
        this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
    }
}

From source file:org.springframework.ide.eclipse.aop.core.internal.model.builder.AnnotationAspectDefinitionBuilder.java

License:Open Source License

private boolean validateAspect(String className) throws Throwable {

    ClassReader classReader = getClassReader(className);
    if (classReader == null) {
        return false;
    }/*  ww  w  .ja v a2  s. com*/
    AspectAnnotationVisitor v = new AspectAnnotationVisitor();
    classReader.accept(v, false);

    if (!v.getClassInfo().hasAspectAnnotation()) {
        return false;
    } else {
        // we know it's an aspect, but we don't know whether it is an
        // @AspectJ aspect or a code style aspect.
        // This is an *unclean* test whilst waiting for AspectJ to
        // provide us with something better
        for (String m : v.getClassInfo().getMethodNames()) {
            if (m.startsWith(AJC_MAGIC)) {
                // must be a code style aspect
                return false;
            }
        }
        // validate supported instantiation models
        if (v.getClassInfo().getAspectAnnotation().getValue() != null) {
            if (v.getClassInfo().getAspectAnnotation().getValue().toUpperCase()
                    .equals(PerClauseKind.PERCFLOW.toString())) {
                return false;
            }
            if (v.getClassInfo().getAspectAnnotation().getValue().toUpperCase().toString()
                    .equals(PerClauseKind.PERCFLOWBELOW.toString())) {
                return false;
            }
        }

        // check if super class is Aspect as well and abstract
        if (v.getClassInfo().getSuperType() != null) {
            classReader = getClassReader(v.getClassInfo().getSuperType());
            if (classReader == null) {
                return false;
            }

            AspectAnnotationVisitor sv = new AspectAnnotationVisitor();
            classReader.accept(sv, false);

            if (sv.getClassInfo().getAspectAnnotation() != null
                    && !((sv.getClassInfo().getModifier() & Opcodes.ACC_ABSTRACT) != 0)) {
                return false;
            }
        }
        return true;
    }
}