Example usage for org.objectweb.asm Opcodes ACC_PRIVATE

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

Introduction

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

Prototype

int ACC_PRIVATE

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

Click Source Link

Usage

From source file:org.coldswap.asm.field.PrivateStaticFieldReplacer.java

License:Open Source License

public byte[] replace() {
    final ClassNode cn = new ClassNode(Opcodes.ASM5);
    ClassReader cr = new ClassReader(bytes);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES);
    cr.accept(cn, 0);/* ww  w . jav a 2s .c  o m*/
    // get a list of public/protected/package/private fields but exclude
    // inherited fields.
    Field[] refFields = aClass.getDeclaredFields();
    List asmFields = cn.fields;
    Iterator iterator = asmFields.iterator();
    while (iterator.hasNext()) {
        final FieldNode fNode = (FieldNode) iterator.next();
        int privateStatic = Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE;
        // search only for private static fields
        if ((fNode.access == privateStatic)) {
            // check if this field exist in the old loaded class
            // and if not proceed with the trick.
            boolean foundIt = false;
            for (Field refField : refFields) {
                if (fNode.name.equals(refField.getName())) {
                    if (fNode.desc.equals(Type.getType(refField.getType()).getDescriptor())) {
                        foundIt = true;
                        break;
                    }
                }
            }
            if (!foundIt) {
                String contClass = cn.name.substring(cn.name.lastIndexOf("/") + 1);
                String className = TransformerNameGenerator.getPrivateStaticFieldClassName(contClass,
                        fNode.name);
                // remove the static reference from <clinit>
                InsnList insnList = cleanClInit(cn, fNode);
                // create a new class that contains the field
                // before anything change the field access to public static so that it can be referenced
                // from other classes.
                fNode.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
                byte[] newBClass = ByteCodeGenerator.newFieldClass(cn, fNode, insnList,
                        classPackage + className);
                try {
                    String cp = ClassUtil.getClassPath(aClass);
                    ByteCodeClassWriter.setClassPath(cp);
                    ByteCodeClassWriter.writeClass(className, newBClass);
                } catch (IOException e) {
                    logger.warning(e.toString());
                }

                iterator.remove();
                // replace every reference
                replaceReferences(cn, fNode);
            }
        }
    }
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddImplicitActivationAdapter.java

License:Open Source License

private boolean isCandidateForImplicitActivation(String methName, String methDesc, int accessFlags) {
    if (clazz.isTeam()) {
        if ((accessFlags & Opcodes.ACC_PRIVATE) != 0)
            return false;
    } else if (clazz.isRole()) {
        if (clazz.isProtected() || (accessFlags & Opcodes.ACC_PUBLIC) == 0)
            return false;
    } else {//from  www.  ja  v  a  2s  . c  o m
        return false;
    }
    switch (implicitActivationMode) {
    case NEVER:
        return false;
    case ANNOTATED:
        if (!clazz.hasMethodImplicitActivation(methName + methDesc))
            return false;
        //$FALL-THROUGH$
    case ALWAYS:
        // TODO: respect RoleClassMethodModifiers attribute
        return canImplicitlyActivate(accessFlags, methName, methDesc);
    }
    return false;
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddInterfaceAdapter.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from ww  w  .  j a v a  2  s  . co m
    String[] newInterfaces = new String[interfaces.length + 1];
    System.arraycopy(interfaces, 0, newInterfaces, 0, interfaces.length);
    newInterfaces[interfaces.length] = interfaceName;
    // Assumption: when it should potentially be a bound baseclass it may have to be public, too:
    access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);
    access |= Opcodes.ACC_PUBLIC;
    super.visit(version, access, name, signature, superName, newInterfaces);
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddThreadNotificationAdapter.java

License:Open Source License

@Override
public void visitEnd() {
    cv.visitField(Opcodes.ACC_PRIVATE, CREATION_THREAD, THREAD_DESC, null, null);
    super.visitEnd();
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AsmClassVisitor.java

License:Open Source License

/**
 * Parses the methods of the class//from   w  w w.ja  v a  2 s. co m
 */
@Override
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature,
        String[] exceptions) {
    clazz.addMethod(name, desc, (access & Opcodes.ACC_STATIC) != 0,
            (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)));
    if (clazz.isTeam() || clazz.isRole())
        // check for method annotation ImplicitTeamActivation:
        return new MethodVisitor(this.api) {
            @Override
            public AnnotationVisitor visitAnnotation(String annDesc, boolean visible) {
                if (annDesc.equals(AddImplicitActivationAdapter.ANNOTATION_IMPLICIT_ACTIVATION))
                    clazz.registerMethodForImplicitActivation(name + desc);
                return super.visitAnnotation(annDesc, visible);
            }
        };
    return super.visitMethod(access, name, desc, signature, exceptions);
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AsmClassVisitor.java

License:Open Source License

/**
 * Parses the fields of the class//from  ww w  .ja v  a 2 s  .c  om
 */
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    clazz.addField(name, desc, (access & Opcodes.ACC_STATIC) != 0,
            (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)));
    return super.visitField(access, name, desc, signature, value);
}

From source file:org.eclipse.objectteams.otredyn.bytecode.Member.java

License:Open Source License

public boolean isPrivate() {
    return (this.accessFlags & Opcodes.ACC_PRIVATE) != 0;
}

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

License:Open Source License

public static boolean isDefault(int accessFlags) {
    // none of the private, protected or public bit is set
    return (accessFlags & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0;
}

From source file:org.eclipse.virgo.bundlor.support.asm.ArtifactAnalyzerClassVisitor.java

License:Open Source License

/**
 * @inheritDoc//from w  ww .  j  a va  2  s  . c o m
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    VisitorUtils.recordReferencedTypes(this.partialManifest, Type.getArgumentTypes(desc));
    VisitorUtils.recordReferencedTypes(this.partialManifest, Type.getReturnType(desc));
    if (exceptions != null) {
        for (String exception : exceptions) {
            VisitorUtils.recordReferencedTypes(this.partialManifest, Type.getObjectType(exception));
        }
    }
    if (access != Opcodes.ACC_PRIVATE) {
        VisitorUtils.recordUses(this.partialManifest, this.type, Type.getArgumentTypes(desc));
        VisitorUtils.recordUses(this.partialManifest, this.type, Type.getReturnType(desc));
        if (exceptions != null) {
            for (String exception : exceptions) {
                VisitorUtils.recordUses(this.partialManifest, this.type, Type.getObjectType(exception));
            }
        }
    }
    return new ArtifactAnalyzerMethodVisitor(this.partialManifest, this.type);
}

From source file:org.eclipse.virgo.ide.bundlor.internal.core.asm.ArtefactAnalyserClassVisitor.java

License:Open Source License

/**
 * @inheritDoc/*from  w  ww . ja va2  s .co m*/
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    VisitorUtils.recordReferencedTypes(this.partialManifest, Type.getArgumentTypes(desc));
    VisitorUtils.recordReferencedTypes(this.partialManifest, Type.getReturnType(desc));
    if (exceptions != null) {
        for (String exception : exceptions) {
            VisitorUtils.recordReferencedTypes(this.partialManifest, Type.getObjectType(exception));
        }
    }
    if (access != Opcodes.ACC_PRIVATE) {
        VisitorUtils.recordUses(this.partialManifest, this.type, Type.getArgumentTypes(desc));
        VisitorUtils.recordUses(this.partialManifest, this.type, Type.getReturnType(desc));
        if (exceptions != null) {
            for (String exception : exceptions) {
                VisitorUtils.recordUses(this.partialManifest, this.type, Type.getObjectType(exception));
            }
        }
    }
    return new ArtefactAnalyserMethodVisitor(this.partialManifest, this.type);
}