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.commons.weaver.privilizer.BlueprintingVisitor.java
License:Apache License
private String importMethod(final Pair<Type, Method> key) { if (importedMethods.containsKey(key)) { return importedMethods.get(key); }//from w w w .java2s. c om final String result = new StringBuilder(key.getLeft().getInternalName().replace('/', '_')).append("$$") .append(key.getRight().getName()).toString(); importedMethods.put(key, result); privilizer().env.debug("importing %s#%s as %s", key.getLeft().getClassName(), key.getRight(), result); final int access = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC; final MethodNode source = typeInfo(key.getLeft()).methods.get(key.getRight()); final String[] exceptions = source.exceptions.toArray(ArrayUtils.EMPTY_STRING_ARRAY); // non-public fields accessed final Set<FieldAccess> fieldAccesses = new LinkedHashSet<>(); source.accept(new MethodVisitor(Privilizer.ASM_VERSION) { @Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { final FieldAccess fieldAccess = fieldAccess(Type.getObjectType(owner), name); super.visitFieldInsn(opcode, owner, name, desc); if (!Modifier.isPublic(fieldAccess.access)) { fieldAccesses.add(fieldAccess); } } }); final MethodNode withAccessibleAdvice = new MethodNode(access, result, source.desc, source.signature, exceptions); // spider own methods: MethodVisitor mv = new NestedMethodInvocationHandler(withAccessibleAdvice, key); //NOPMD if (!fieldAccesses.isEmpty()) { mv = new AccessibleAdvisor(mv, access, result, source.desc, new ArrayList<>(fieldAccesses)); } source.accept(mv); // private can only be called by other privileged methods, so no need to mark as privileged if (!Modifier.isPrivate(source.access)) { withAccessibleAdvice.visitAnnotation(Type.getType(Privileged.class).getDescriptor(), false).visitEnd(); } withAccessibleAdvice.accept(this.cv); return result; }
From source file:org.apache.commons.weaver.privilizer.PrivilizingVisitor.java
License:Apache License
@Override public void visitEnd() { annotate();/*from w w w . j a v a 2 s .co m*/ if (privilizer().policy == Policy.ON_INIT) { final String fieldName = privilizer().generateName("hasSecurityManager"); visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, fieldName, Type.BOOLEAN_TYPE.getDescriptor(), null, null).visitEnd(); final GeneratorAdapter mgen = new GeneratorAdapter(Opcodes.ACC_STATIC, new Method("<clinit>", "()V"), null, Privilizer.EMPTY_TYPE_ARRAY, this); checkSecurityManager(mgen); mgen.putStatic(target, fieldName, Type.BOOLEAN_TYPE); mgen.returnValue(); mgen.endMethod(); } super.visitEnd(); }
From source file:org.apache.cxf.jaxb.JAXBUtils.java
License:Apache License
private static Class<?> createNamespaceWrapperInternal(ASMHelper helper, ClassWriter cw) { String className = "org.apache.cxf.jaxb.NamespaceMapperInternal"; FieldVisitor fv;//from w w w . j a v a 2 s .c o m MethodVisitor mv; cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, "org/apache/cxf/jaxb/NamespaceMapperInternal", null, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", null); cw.visitSource("NamespaceMapper.java", null); fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", null); fv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(30, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", "<init>", "()V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(31, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref", "Ljava/util/Map;"); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(32, l2); mv.visitInsn(Opcodes.RETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l3, 0); mv.visitLocalVariable("nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", l0, l3, 1); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreferredPrefix", "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;", null, null); mv.visitCode(); l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(38, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref", "Ljava/util/Map;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String"); mv.visitVarInsn(Opcodes.ASTORE, 4); l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(39, l1); mv.visitVarInsn(Opcodes.ALOAD, 4); l2 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l2); l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(40, l3); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l2); mv.visitLineNumber(42, l2); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitInsn(Opcodes.ARETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l4, 0); mv.visitLocalVariable("namespaceUri", "Ljava/lang/String;", null, l0, l4, 1); mv.visitLocalVariable("suggestion", "Ljava/lang/String;", null, l0, l4, 2); mv.visitLocalVariable("requirePrefix", "Z", null, l0, l4, 3); mv.visitLocalVariable("prefix", "Ljava/lang/String;", null, l1, l4, 4); mv.visitMaxs(2, 5); mv.visitEnd(); cw.visitEnd(); byte bts[] = cw.toByteArray(); return helper.loadClass(className, JAXBUtils.class, bts); }
From source file:org.apache.cxf.jaxws.WrapperClassGenerator.java
License:Apache License
private void generateMessagePart(ClassWriter cw, MessagePartInfo mpi, Method method, String className) { if (Boolean.TRUE.equals(mpi.getProperty(ReflectionServiceFactoryBean.HEADER))) { return;//from w ww . java 2 s. c o m } String classFileName = periodToSlashes(className); String name = mpi.getName().getLocalPart(); Class clz = mpi.getTypeClass(); Object obj = mpi.getProperty(ReflectionServiceFactoryBean.RAW_CLASS); if (obj != null) { clz = (Class) obj; } Type genericType = (Type) mpi.getProperty(ReflectionServiceFactoryBean.GENERIC_TYPE); if (genericType instanceof ParameterizedType) { ParameterizedType tp = (ParameterizedType) genericType; if (tp.getRawType() instanceof Class && Holder.class.isAssignableFrom((Class) tp.getRawType())) { genericType = tp.getActualTypeArguments()[0]; } } String classCode = getClassCode(clz); String fieldDescriptor = null; if (genericType instanceof ParameterizedType) { if (Collection.class.isAssignableFrom(clz) || clz.isArray()) { ParameterizedType ptype = (ParameterizedType) genericType; Type[] types = ptype.getActualTypeArguments(); // TODO: more complex Parameterized type if (types.length > 0) { if (types[0] instanceof Class) { fieldDescriptor = getClassCode(genericType); } else if (types[0] instanceof GenericArrayType) { fieldDescriptor = getClassCode(genericType); } else if (types[0] instanceof ParameterizedType) { classCode = getClassCode(((ParameterizedType) types[0]).getRawType()); fieldDescriptor = getClassCode(genericType); } } } else { classCode = getClassCode(((ParameterizedType) genericType).getRawType()); fieldDescriptor = getClassCode(genericType); } } String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name) : name; FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, classCode, fieldDescriptor, null); AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true); av0.visit("name", name); if (factory.isWrapperPartQualified(mpi)) { av0.visit("namespace", mpi.getConcreteName().getNamespaceURI()); } if (factory.isWrapperPartNillable(mpi)) { av0.visit("nillable", Boolean.TRUE); } if (factory.getWrapperPartMinOccurs(mpi) == 1) { av0.visit("required", Boolean.TRUE); } av0.visitEnd(); List<Annotation> jaxbAnnos = getJaxbAnnos(mpi); addJAXBAnnotations(fv, jaxbAnnos); fv.visitEnd(); String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode, fieldDescriptor == null ? null : "()" + fieldDescriptor, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode); mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN)); mv.visitMaxs(0, 0); mv.visitEnd(); methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V", fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V", null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode); mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1); mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.apache.deltaspike.partialbean.impl.proxy.AsmProxyClassGenerator.java
License:Apache License
private static void defineInvocationHandlerField(ClassWriter cw, Type invocationHandlerType) { // generates/*from w w w. j a v a 2s . c o m*/ // private MyPartialBeanInvocationHandler __handler; cw.visitField(Opcodes.ACC_PRIVATE, FIELDNAME_HANDLER, invocationHandlerType.getDescriptor(), null, null) .visitEnd(); }
From source file:org.apache.deltaspike.proxy.impl.AsmDeltaSpikeProxyClassGenerator.java
License:Apache License
private static void defineDeltaSpikeProxyFields(ClassWriter cw) { // generates//from w w w. j a va 2 s . c o m // private DeltaSpikeProxyInvocationHandler invocationHandler; cw.visitField(Opcodes.ACC_PRIVATE, FIELDNAME_INVOCATION_HANDLER, TYPE_DELTA_SPIKE_PROXY_INVOCATION_HANDLER.getDescriptor(), null, null).visitEnd(); // generates // private MyInvocationHandler delegateInvocationHandler; cw.visitField(Opcodes.ACC_PRIVATE, FIELDNAME_DELEGATE_INVOCATION_HANDLER, TYPE_INVOCATION_HANDLER.getDescriptor(), null, null).visitEnd(); // generates // private Method[] delegateMethods; cw.visitField(Opcodes.ACC_PRIVATE, FIELDNAME_DELEGATE_METHODS, TYPE_METHOD_ARRAY.getDescriptor(), null, null).visitEnd(); }
From source file:org.apache.deltaspike.proxy.impl.AsmProxyClassGenerator.java
License:Apache License
private static void defineInvocationHandlerField(ClassWriter cw, Type delegateInvocationHandlerType) { // generates//from w w w. ja v a 2s . c o m // private MyInvocationHandler delegateInvocationHandler; cw.visitField(Opcodes.ACC_PRIVATE, FIELDNAME_DELEGATE_INVOCATION_HANDLER, delegateInvocationHandlerType.getDescriptor(), null, null).visitEnd(); }
From source file:org.apache.deltaspike.proxy.util.AsmProxyClassGenerator.java
License:Apache License
private static void defineInvocationHandlerField(ClassWriter cw, Type invocationHandlerType) { // generates/*www . ja v a2 s . c o m*/ // private MyInvocationHandler delegateInvocationHandler; cw.visitField(Opcodes.ACC_PRIVATE, FIELDNAME_DELEGATE_INVOCATION_HANDLER, invocationHandlerType.getDescriptor(), null, null).visitEnd(); }
From source file:org.apache.drill.exec.compile.InnerClassAccessStripper.java
License:Apache License
@Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { /*/*from w w w .j av a2 s. c o m*/ * Record the original access bits so we can restore them before the next * link in the visitor chain. */ originalClassAccess = access; accessCaptured = true; // If we're checking an inner class, suppress access bits that ASM chokes on. int checkClassAccess = access; if (name.indexOf('$') >= 0) { checkClassAccess &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC); } super.visit(version, checkClassAccess, name, signature, superName, interfaces); }
From source file:org.apache.felix.ipojo.composite.service.provides.POJOWriter.java
License:Apache License
/** * Inject field in the current class.//from w w w . ja v a 2s . c o m * @param cw : class writer. * @param fields : list of field to inject. */ private static void injectFields(ClassWriter cw, List fields) { // Inject fields for (int i = 0; i < fields.size(); i++) { FieldMetadata field = (FieldMetadata) fields.get(i); if (field.isUseful()) { SpecificationMetadata spec = field.getSpecification(); String fieldName = field.getName(); String desc = ""; if (field.isAggregate()) { desc = "[L" + spec.getName().replace('.', '/') + ";"; } else { desc = "L" + spec.getName().replace('.', '/') + ";"; } cw.visitField(Opcodes.ACC_PRIVATE, fieldName, desc, null, null); } } }