List of usage examples for org.objectweb.asm Opcodes ACC_PROTECTED
int ACC_PROTECTED
To view the source code for org.objectweb.asm Opcodes ACC_PROTECTED.
Click Source Link
From source file:org.coldswap.asm.field.ProtectedStaticFieldReplacer.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);/*from ww w. ja v a 2 s . com*/ // get a list of public/protected fields. Field[] refFields = aClass.getDeclaredFields(); List asmFields = getFields(cn); Iterator iterator = asmFields.iterator(); while (iterator.hasNext()) { final FieldNode fNode = (FieldNode) iterator.next(); int protectedStatic = Opcodes.ACC_STATIC | Opcodes.ACC_PROTECTED; // search only for protected static fields if ((fNode.access == protectedStatic)) { // 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) { // register a public static reference replacer String contClass = cn.name.substring(cn.name.lastIndexOf("/") + 1); String className = TransformerNameGenerator.getProtectedStaticFieldClassName(contClass, fNode.name); // make field access as public static fNode.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC; replacerManager.registerFieldReferenceReplacer(new ProtectedStaticFieldReferenceReplacer( contClass, fNode, classPackage + className, contClass)); // remove the static reference from <clinit> InsnList insnList = cleanClInit(cn, fNode, true); // because the field might be inherited from superclass we need to copy // the initializer from the parent. if ((insnList == null) || (insnList.size() > 0)) { insnList = inheritedInitCode.get(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.coldswap.asm.field.ProtectedStaticFieldReplacer.java
License:Open Source License
/** * Returns an array of fields that where declared in this class. In * addition there are also the protected fields that were inherited. * * @param classNode {@link ClassNode} containing the new class version. * @return a list of all fields including the inherited fields. *//* w w w .java 2 s . c om*/ private List<FieldNode> getFields(ClassNode classNode) { List<FieldNode> toRet = classNode.fields; // get inherited package fields try { String superName = classNode.superName; // filter superclasses for (String pack : ClassUtil.skipTransforming) { if (superName.startsWith(pack)) { return toRet; } } Class<?> c = Class.forName(superName); String path = ClassUtil.getClassPath(c); path = path + ClassUtil.fileSeparator + superName + ".class"; byte[] clazz = ByteCodeClassLoader.loadClassBytes(path); ClassNode cNode = new ClassNode(Opcodes.ASM5); ClassReader cr = new ClassReader(clazz); cr.accept(cNode, 0); List<FieldNode> superFields = cNode.fields; for (FieldNode fieldNode : superFields) { if (fieldNode.access == (Opcodes.ACC_STATIC | Opcodes.ACC_PROTECTED)) { toRet.add(fieldNode); InsnList code = cleanClInit(cNode, fieldNode, false); inheritedInitCode.put(fieldNode, code); } } } catch (ClassNotFoundException e) { logger.warning(e.toString()); } return toRet; }
From source file:org.eclipse.objectteams.otredyn.bytecode.AbstractBoundClass.java
License:Open Source License
public boolean isProtected() { return (this.modifiers & Opcodes.ACC_PROTECTED) != 0; }
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 .ja v a 2s .c o 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.AsmClassVisitor.java
License:Open Source License
/** * Parses the methods of the class// w w w . j a v a2s . c om */ @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. j a v a 2s. c o m */ @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.pde.api.tools.internal.builder.ReferenceExtractor.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (fIsVisitMembers) { IApiMember member = this.getMember(); IApiType owner = null;//from w w w . ja v a 2s. c o m if (member instanceof IApiType) { owner = (IApiType) member; } else { try { owner = member.getEnclosingType(); } catch (CoreException e) { // should not happen for field or method ApiPlugin.log(e.getStatus()); } } if (owner == null) { return null; } IApiMethod method = owner.getMethod(name, desc); if (method == null) { ApiPlugin.log(new Status(IStatus.WARNING, ApiPlugin.PLUGIN_ID, NLS.bind(BuilderMessages.ReferenceExtractor_failed_to_lookup_method, new String[] { name, desc, Signatures.getQualifiedTypeSignature(owner) }))); // if we can't find the method there is no point trying to // process it return null; } this.enterMember(method); // record potential method override reference if ((access & (Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) > 0) { try { IApiType def = null; if (fVersion >= Opcodes.V1_8) { // See if we are overriding a default interface method def = getDefaultDefined(owner, name, desc, true); } if (def != null) { addReference(Reference.methodReference(method, def.getName(), method.getName(), method.getSignature(), IReference.REF_OVERRIDE, IReference.F_DEFAULT_METHOD)); } else if (!this.fSuperStack.isEmpty()) { String superTypeName = this.fSuperStack.peek(); addReference(Reference.methodReference(method, superTypeName, method.getName(), method.getSignature(), IReference.REF_OVERRIDE)); } } catch (CoreException e) { // Do nothing, skip this reference } } int argumentcount = 0; if ((access & Opcodes.ACC_SYNTHETIC) == 0) { if (signature != null) { this.processSignature(name, signature, IReference.REF_PARAMETERIZED_METHODDECL, METHOD); argumentcount = this.signaturevisitor.argumentcount; } else { Type[] arguments = Type.getArgumentTypes(desc); for (int i = 0; i < arguments.length; i++) { Type type = arguments[i]; this.addTypeReference(type, IReference.REF_PARAMETER); argumentcount += type.getSize(); } this.addTypeReference(Type.getReturnType(desc), IReference.REF_RETURNTYPE); if (exceptions != null) { for (int i = 0; i < exceptions.length; i++) { this.addTypeReference(Type.getObjectType(exceptions[i]), IReference.REF_THROWS); } } } } MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (mv != null && ((access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0)) { return new ClassFileMethodVisitor(mv, name, argumentcount); } } return null; }
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.evosuite.classpath.ResourceList.java
License:Open Source License
/** * Returns {@code true} if there is at least one public method in the class; returns {@code false} otherwise. * //from w w w .j a v a2 s . c o m * @param input the input stream * @return {@code true} if there is at least one public method in the class, {@code false} otherwise * @throws IOException if an error occurs while reading the input stream */ private static boolean isClassTestable(InputStream input) throws IOException { try { ClassReader reader = new ClassReader(input); ClassNode cn = new ClassNode(); reader.accept(cn, ClassReader.SKIP_FRAMES); @SuppressWarnings("unchecked") List<MethodNode> l = cn.methods; for (MethodNode m : l) { if ((m.access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC || (m.access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED || (m.access & Opcodes.ACC_PRIVATE) == 0 /* default */ ) { return true; } } return false; } finally { input.close(); //VERY IMPORTANT, as ASM does not close the stream } }
From source file:org.evosuite.instrumentation.AccessibleClassAdapter.java
License:Open Source License
/** * {@inheritDoc}// w w w .ja v a2 s.c o m * * Change subclasses to public */ @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { if (!exclude && (access & Opcodes.ACC_PRIVATE) != Opcodes.ACC_PRIVATE && (access & Opcodes.ACC_PROTECTED) != Opcodes.ACC_PROTECTED) { access = access | Opcodes.ACC_PUBLIC; // access = access & ~Opcodes.ACC_PROTECTED; } super.visit(version, access, name, signature, superName, interfaces); }