List of usage examples for org.objectweb.asm Opcodes ACC_PRIVATE
int ACC_PRIVATE
To view the source code for org.objectweb.asm Opcodes ACC_PRIVATE.
Click Source Link
From source file:org.apache.felix.ipojo.manipulation.ClassManipulator.java
License:Apache License
/** * Visit a Field./*w w w. ja v a 2s. c o m*/ * This field access is replaced by an invocation to the getter method or to the setter method. * (except for static field). * Inject the getter and the setter method for this field. * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object) * @param access : access modifier * @param name : name of the field * @param desc : description of the field * @param signature : signature of the field * @param value : value of the field * @return FieldVisitor : null */ public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) { if ((access & ACC_STATIC) == 0) { FieldVisitor flag = cv.visitField(Opcodes.ACC_PRIVATE, FIELD_FLAG_PREFIX + name, "Z", null, null); flag.visitEnd(); Type type = Type.getType(desc); if (type.getSort() == Type.ARRAY) { String gDesc = "()" + desc; createArrayGetter(name, gDesc); // Generates setter method String sDesc = "(" + desc + ")V"; createArraySetter(name, sDesc); } else { // Generate the getter method String gDesc = "()" + desc; createSimpleGetter(name, gDesc, type); // Generates setter method String sDesc = "(" + desc + ")V"; createSimpleSetter(name, sDesc, type); } } return cv.visitField(access, name, desc, signature, value); }
From source file:org.apache.felix.ipojo.manipulation.MethodCreator.java
License:Apache License
/** * A method is visited./*from w ww . ja v a 2s . c o m*/ * This method does not manipulate clinit and class$ methods. * In the case of a constructor, this method will generate a constructor with the instance manager * and will adapt the current constructor to call this constructor. * For standard method, this method will create method header, rename the current method and adapt it. * @param access : access flag. * @param name : name of the method * @param desc : method descriptor * @param signature : signature * @param exceptions : declared exceptions. * @return the MethodVisitor wich will visit the method code. * @see org.objectweb.asm.ClassAdapter#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[]) */ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { // Avoid manipulating special methods if (name.equals("<clinit>") || name.equals("class$")) { return super.visitMethod(access, name, desc, signature, exceptions); } // The constructor is manipulated separately if (name.equals("<init>")) { MethodDescriptor md = getMethodDescriptor("$init", desc); // 1) change the constructor descriptor (add a component manager arg as first argument) String newDesc = desc.substring(1); newDesc = "(Lorg/apache/felix/ipojo/InstanceManager;" + newDesc; Type[] args = Type.getArgumentTypes(desc); if (args.length == 0) { generateEmptyConstructor(access, signature, exceptions, md.getAnnotations()); // No parameters, so no annotations parameters m_foundSuitableConstructor = true; } else if (args.length == 1 && args[0].getClassName().equals("org.osgi.framework.BundleContext")) { generateBCConstructor(access, signature, exceptions, md.getAnnotations()); // One parameter, so no annotations parameters m_foundSuitableConstructor = true; } else { // Do nothing, the constructor does not match. return cv.visitMethod(access, name, desc, signature, exceptions); } // Insert the new constructor MethodVisitor mv = super.visitMethod(ACC_PRIVATE, "<init>", newDesc, signature, exceptions); return new ConstructorCodeAdapter(mv, m_owner, m_fields, ACC_PRIVATE, name, newDesc, m_superclass); } if ((access & ACC_SYNTHETIC) == ACC_SYNTHETIC && name.startsWith("access$")) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new MethodCodeAdapter(mv, m_owner, access, name, desc, m_fields); } if ((access & ACC_STATIC) == ACC_STATIC) { return super.visitMethod(access, name, desc, signature, exceptions); } MethodDescriptor md = getMethodDescriptor(name, desc); if (md == null) { generateMethodHeader(access, name, desc, signature, exceptions, new ArrayList(0), new HashMap()); } else { generateMethodHeader(access, name, desc, signature, exceptions, md.getAnnotations(), md.getParameterAnnotations()); } String id = generateMethodFlag(name, desc); if (!m_methodFlags.contains(id)) { FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE, id, "Z", null, null); flagField.visitEnd(); m_methodFlags.add(id); } MethodVisitor mv = super.visitMethod(ACC_PRIVATE, PREFIX + name, desc, signature, exceptions); return new MethodCodeAdapter(mv, m_owner, ACC_PRIVATE, PREFIX + name, desc, m_fields); }
From source file:org.apache.felix.ipojo.manipulation.MethodCreator.java
License:Apache License
/** * Visit a Field.//w w w . jav a2 s . c o m * This field access is replaced by an invocation to the getter method or to the setter method. * (except for static field). * Inject the getter and the setter method for this field. * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object) * @param access : access modifier * @param name : name of the field * @param desc : description of the field * @param signature : signature of the field * @param value : value of the field * @return FieldVisitor : null */ public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) { if ((access & ACC_STATIC) == 0) { FieldVisitor flag = cv.visitField(Opcodes.ACC_PRIVATE, FIELD_FLAG_PREFIX + name, "Z", null, null); flag.visitEnd(); Type type = Type.getType(desc); if (type.getSort() == Type.ARRAY) { String gDesc = "()" + desc; createArrayGetter(name, gDesc, type); // Generates setter method String sDesc = "(" + desc + ")V"; createArraySetter(name, sDesc, type); } else { // Generate the getter method String gDesc = "()" + desc; createSimpleGetter(name, gDesc, type); // Generates setter method String sDesc = "(" + desc + ")V"; createSimpleSetter(name, sDesc, type); } } return cv.visitField(access, name, desc, signature, value); }
From source file:org.apache.groovy.parser.antlr4.AstBuilder.java
License:Apache License
private MethodNode createScriptMethodNode(ModifierManager modifierManager, String methodName, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code) { MethodNode methodNode;/*from w w w . j a v a 2 s. c o m*/ methodNode = new MethodNode(methodName, modifierManager.containsAny(PRIVATE) ? Opcodes.ACC_PRIVATE : Opcodes.ACC_PUBLIC, returnType, parameters, exceptions, code); modifierManager.processMethodNode(methodNode); return methodNode; }
From source file:org.apache.groovy.parser.antlr4.AstBuilder.java
License:Apache License
private void declareProperty(VariableDeclarationContext ctx, ModifierManager modifierManager, ClassNode variableType, ClassNode classNode, int i, VariableExpression variableExpression, String fieldName, int modifiers, Expression initialValue) { if (classNode.hasProperty(fieldName)) { throw createParsingFailedException("The property '" + fieldName + "' is declared multiple times", ctx); }/* w ww.j a v a2 s .c o m*/ PropertyNode propertyNode; FieldNode fieldNode = classNode.getDeclaredField(fieldName); if (fieldNode != null && !classNode.hasProperty(fieldName)) { classNode.getFields().remove(fieldNode); propertyNode = new PropertyNode(fieldNode, modifiers | Opcodes.ACC_PUBLIC, null, null); classNode.addProperty(propertyNode); } else { propertyNode = classNode.addProperty(fieldName, modifiers | Opcodes.ACC_PUBLIC, variableType, initialValue, null, null); fieldNode = propertyNode.getField(); } fieldNode.setModifiers(modifiers & ~Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE); fieldNode.setSynthetic(!classNode.isInterface()); modifierManager.attachAnnotations(fieldNode); groovydocManager.handle(fieldNode, ctx); groovydocManager.handle(propertyNode, ctx); if (0 == i) { configureAST(fieldNode, ctx, initialValue); configureAST(propertyNode, ctx, initialValue); } else { configureAST(fieldNode, variableExpression, initialValue); configureAST(propertyNode, variableExpression, initialValue); } }
From source file:org.apache.groovy.parser.antlr4.ModifierManager.java
License:Apache License
public int clearVisibilityModifiers(int modifiers) { return modifiers & ~Opcodes.ACC_PUBLIC & ~Opcodes.ACC_PROTECTED & ~Opcodes.ACC_PRIVATE; }
From source file:org.apache.maven.diagrams.connectors.classes.model.ModifierModel.java
License:Apache License
/** * Transforms maps of com.sun.org.apache.bcel.internal.Opcodes.ACC_... modifiers into the EnumSet. * //from www. j a v a2 s. c o m * @param access - * combination of modifier's Opcodes * @return */ public static EnumSet<ModifierModel> accessContantsToModifiers(int access) { EnumSet<ModifierModel> result = EnumSet.noneOf(ModifierModel.class); if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) result.add(PRIVATE); if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) result.add(PUBLIC); if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) result.add(PROTECTED); if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) result.add(STATIC); return result; }
From source file:org.apache.tika.parser.asm.XHTMLClassVisitor.java
License:Apache License
private void writeAccess(int access) throws SAXException { writeAccess(access, Opcodes.ACC_PRIVATE, "private"); writeAccess(access, Opcodes.ACC_PROTECTED, "protected"); writeAccess(access, Opcodes.ACC_PUBLIC, "public"); writeAccess(access, Opcodes.ACC_STATIC, "static"); writeAccess(access, Opcodes.ACC_FINAL, "final"); writeAccess(access, Opcodes.ACC_ABSTRACT, "abstract"); writeAccess(access, Opcodes.ACC_SYNCHRONIZED, "synchronized"); writeAccess(access, Opcodes.ACC_TRANSIENT, "transient"); writeAccess(access, Opcodes.ACC_VOLATILE, "volatile"); writeAccess(access, Opcodes.ACC_NATIVE, "native"); }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
/** * Returns the enhanced class bytecode.// ww w. j a v a 2 s . com * * @param clazz * the class to enhance * @return the enhanced class * @throws Exception * thrown in case of an error * * @since 2.0.0 */ //@formatter:off public static byte[] create(Class<?> clazz) throws Exception { final String enhancingClassName = Type.getInternalName(clazz); final String enhancedClassName = enhancingClassName + Enhancer.SUFFIX_ENHANCED; final String descEnhancer = Enhancer.makeClassDesc(enhancedClassName); final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, enhancedClassName, null, enhancingClassName, new String[] { Type.getInternalName(EnhancedInstance.class) }); // Field: serialVersionUID cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, Enhancer.FIELD_SERIAL_VERSION_UID, Type.getDescriptor(Long.TYPE), null, Long.valueOf(1L)) .visitEnd(); // Container fields cw.visitField(Opcodes.ACC_PRIVATE, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN, null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN, null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_ID, Enhancer.DESCRIPTOR_OBJECT, null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_TYPE, Enhancer.DESCRIPTOR_CLASS, null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION, null, null).visitEnd(); cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE, Enhancer.DESCRIPTOR_MANAGED_INSTANCE, null, null).visitEnd(); // Constructors Enhancer.createNoArgConstructor(enhancingClassName, enhancedClassName, descEnhancer, cw); Enhancer.createContainerConstructor(enhancingClassName, enhancedClassName, descEnhancer, cw); Enhancer.createMethodIsInitialized(enhancedClassName, descEnhancer, cw); Enhancer.createMethodSetInitialized(enhancedClassName, descEnhancer, cw); Enhancer.createMethodCheck(enhancedClassName, descEnhancer, cw); Enhancer.createMethodGetManagedInstance(enhancedClassName, descEnhancer, cw); Enhancer.createMethodSetManagedInstance(enhancedClassName, descEnhancer, cw); Enhancer.createMethodSetInternal(enhancedClassName, descEnhancer, cw); final Map<String, Method> methods = Maps.newHashMap(); Class<?> currentClass = clazz; while (currentClass != Object.class) { // we are not interested in Object.class for (final Method method : currentClass.getDeclaredMethods()) { int modifiers = method.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers) || Modifier.isPrivate(modifiers) || method.isSynthetic() || method.isBridge()) { continue; } // Filter out the details that we are not interested modifiers &= Modifier.ABSTRACT; modifiers &= Modifier.FINAL; modifiers &= Modifier.NATIVE; modifiers &= Modifier.PRIVATE; modifiers &= Modifier.PROTECTED; modifiers &= Modifier.STATIC; modifiers &= Modifier.STRICT; if ((modifiers == Modifier.PUBLIC) || (modifiers == 0)) { // we are not interested in the return type to omit the overridden methods final String desc = method.getName() + Enhancer.makeDescription(Void.TYPE, method.getParameterTypes()); if (methods.get(desc) == null) { methods.put(desc, method); } } } currentClass = currentClass.getSuperclass(); } for (final Method method : methods.values()) { if (!Enhancer.IGNORED_METHODS.contains(method.getName())) { Enhancer.createOverrriddenMethod(enhancingClassName, enhancedClassName, descEnhancer, cw, method); } } cw.visitEnd(); return cw.toByteArray(); }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static void createMethodCheck(final String enhancedClassName, final String descEnhancer, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PRIVATE, Enhancer.METHOD_ENHANCED_CHECK, Enhancer.makeDescription(Void.TYPE), null, null); mv.visitCode();/*from w ww. j a va 2s. c o m*/ final Label lCheckInternal = new Label(); final Label lCheckInitialized = new Label(); final Label lReturn = new Label(); final Label lFind = new Label(); final Label lInitialized = new Label(); final Label lChanged = new Label(); final Label lOut = new Label(); // if (!this.__enhanced__$$__internal) { return } mv.visitLabel(lCheckInternal); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitJumpInsn(Opcodes.IFEQ, lCheckInitialized); mv.visitInsn(Opcodes.RETURN); // if (!this.__enhanced__$$__initialized) { mv.visitLabel(lCheckInitialized); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitJumpInsn(Opcodes.IFNE, lChanged); // if (this.__enhanced_$$__session == null) mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitJumpInsn(Opcodes.IFNONNULL, lFind); // throw new PersistenceException("No session to initialize the instance"); mv.visitTypeInsn(Opcodes.NEW, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("No session to initialize the instance"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION, Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE, String.class)); mv.visitInsn(Opcodes.ATHROW); // this.__enhanced_$$__session.getEntityManager().find(this.__enhanced_$$__type, this.__enhanced__$$__id); mv.visitLabel(lFind); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_SESSION, Enhancer.METHOD_GET_ENTITY_MANAGER, Enhancer.makeDescription(EntityManagerImpl.class)); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_TYPE, Enhancer.DESCRIPTOR_CLASS); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_ID, Enhancer.DESCRIPTOR_OBJECT); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_ENTITY_MANAGER, Enhancer.METHOD_FIND, Enhancer.makeDescription(Object.class, Class.class, Object.class)); mv.visitInsn(Opcodes.POP); // this.__enhanced__$$__initialized = true; mv.visitLabel(lInitialized); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_1); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); // if (this.__enhanced_$$__session != null) mv.visitLabel(lChanged); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitJumpInsn(Opcodes.IFNULL, lReturn); // this.__enhanced__$$__managedInstance.changed(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE, Enhancer.DESCRIPTOR_MANAGED_INSTANCE); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_MANAGED_INSTANCE, Enhancer.METHOD_CHANGED, Enhancer.makeDescription(Void.TYPE)); // return; mv.visitLabel(lReturn); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(lOut); mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, lCheckInternal, lOut, 0); mv.visitMaxs(0, 0); mv.visitEnd(); }