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:ca.weblite.mirah.ant.mirrors.ClassReaderTest.java
@Test public void testParseClass() throws IOException { ClassNode node = new ClassNode(); ResourceLoader loader = new ResourceLoader(); System.out.println(System.getProperties()); loader.setClassPath(System.getProperty("sun.boot.class.path") + File.pathSeparator + System.getProperty("java.class.path")); loader.setJavaSourcePath("test"); File file = new File("test/ca/weblite/mirah/ant/mirrors/SampleJavaClass.java"); loader.fillIndex();/*from w ww.ja v a 2 s .c o m*/ assertTrue("java.util.Map not found", loader.find("java.util.Map") != null); ClassReader reader = new ClassReader(node, file, loader); reader.parse(); assertEquals("Class name is incorrect", "ca/weblite/mirah/ant/mirrors/SampleJavaClass", node.name); boolean foundSomeField = false; boolean foundObjField = false; boolean foundPrivateField = false; boolean foundPublicField = false; boolean foundProtectedField = false; for (Object o : node.fields) { FieldNode n = (FieldNode) o; System.out.println("Field " + n.name + " desc " + n.desc); if ("someField".equals(n.name) && "I".equals(n.desc)) { foundSomeField = true; } if ("someObjField".equals(n.name) && "Ljava/lang/Object;".equals(n.desc)) { foundObjField = true; assertTrue("someObjeField is not public", ((n.access & Opcodes.ACC_PUBLIC) == 0)); assertTrue("someObjeField is not private", ((n.access & Opcodes.ACC_PRIVATE) == 0)); assertTrue("someObjeField is not protected", ((n.access & Opcodes.ACC_PROTECTED) == 0)); assertTrue("someObjeField is not abstract", ((n.access & Opcodes.ACC_ABSTRACT) == 0)); assertTrue("someObjeField is not static", ((n.access & Opcodes.ACC_STATIC) == 0)); } if ("privateField".equals(n.name) && "Ljava/lang/Object;".equals(n.desc)) { foundPrivateField = true; assertTrue("privateField is not public", ((n.access & Opcodes.ACC_PUBLIC) == 0)); assertTrue("privateField should be private", ((n.access & Opcodes.ACC_PRIVATE) != 0)); assertTrue("privateField is not protected", ((n.access & Opcodes.ACC_PROTECTED) == 0)); assertTrue("privateField is not abstract", ((n.access & Opcodes.ACC_ABSTRACT) == 0)); assertTrue("privateField is not static", ((n.access & Opcodes.ACC_STATIC) == 0)); } if ("protectedField".equals(n.name) && "Ljava/lang/Object;".equals(n.desc)) { foundProtectedField = true; assertTrue("protectedField should not public", ((n.access & Opcodes.ACC_PUBLIC) == 0)); assertTrue("protectedField should not be private", ((n.access & Opcodes.ACC_PRIVATE) == 0)); assertTrue("protectedField should be protected", ((n.access & Opcodes.ACC_PROTECTED) != 0)); assertTrue("protectedField should not be abstract", ((n.access & Opcodes.ACC_ABSTRACT) == 0)); assertTrue("protectedField should not static", ((n.access & Opcodes.ACC_STATIC) == 0)); } if ("publicField".equals(n.name) && "Ljava/lang/Object;".equals(n.desc)) { foundPublicField = true; assertTrue("publicField should be public", ((n.access & Opcodes.ACC_PUBLIC) != 0)); assertTrue("publicField should not be private", ((n.access & Opcodes.ACC_PRIVATE) == 0)); assertTrue("publicField should not be protected", ((n.access & Opcodes.ACC_PROTECTED) == 0)); assertTrue("publicField should not be abstract", ((n.access & Opcodes.ACC_ABSTRACT) == 0)); assertTrue("publicField should not static", ((n.access & Opcodes.ACC_STATIC) == 0)); } } assertTrue("someField was not found", foundSomeField); assertTrue("object field was not found", foundObjField); assertTrue("private field was not found", foundPrivateField); assertTrue("public field was not found", foundPublicField); assertTrue("protected field was not found", foundProtectedField); }
From source file:ch.sourcepond.utils.podescoin.internal.Access.java
License:Apache License
public static boolean isPrivate(final int access) { return (access & Opcodes.ACC_PRIVATE) != 0; }
From source file:cl.inria.stiq.instrumenter.BCIUtils.java
License:Open Source License
public static boolean isPrivate(int access) { return (access & Opcodes.ACC_PRIVATE) != 0; }
From source file:Client.JClassPatcher.java
License:Open Source License
private String decodeAccess(int access) { String res = ""; if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) res += "public "; if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) res += "private "; if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) res += "protected "; if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) res += "static "; if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) res += "final "; if ((access & Opcodes.ACC_VOLATILE) == Opcodes.ACC_VOLATILE) res += "protected "; if ((access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED) res += "synchronized "; if ((access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) res += "abstract "; if ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE) res += "interface "; return res;/*from www . j av a 2 s.c o m*/ }
From source file:co.cask.cdap.internal.app.runtime.service.http.HttpHandlerGenerator.java
License:Apache License
/** * Generates a static Logger field for logging and a static initialization block to initialize the logger. *///from ww w. j av a2 s. c o m private void generateLogger(Type classType, ClassWriter classWriter) { // private static final Logger LOG = LoggerFactory.getLogger(classType); classWriter.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "LOG", Type.getType(Logger.class).getDescriptor(), null, null); Method init = Methods.getMethod(void.class, "<clinit>"); GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_STATIC, init, null, null, classWriter); mg.visitLdcInsn(classType); mg.invokeStatic(Type.getType(LoggerFactory.class), Methods.getMethod(Logger.class, "getLogger", Class.class)); mg.putStatic(classType, "LOG", Type.getType(Logger.class)); mg.returnValue(); mg.endMethod(); }
From source file:co.cask.cdap.internal.io.DatumWriterGenerator.java
License:Apache License
/** * Generates a {@link DatumWriter} class for encoding data of the given output type with the given schema. * @param outputType Type information of the output data type. * @param schema Schema of the output data type. * @return A {@link co.cask.cdap.internal.asm.ClassDefinition} that contains generated class information. *//* w w w .j a va2 s . c o m*/ ClassDefinition generate(TypeToken<?> outputType, Schema schema) { classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); preservedClasses = Lists.newArrayList(); TypeToken<?> interfaceType = getInterfaceType(outputType); // Generate the class String className = getClassName(interfaceType, schema); classType = Type.getObjectType(className); classWriter.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, className, Signatures.getClassSignature(interfaceType), Type.getInternalName(Object.class), new String[] { Type.getInternalName(interfaceType.getRawType()) }); // Static schema hash field, for verification classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "SCHEMA_HASH", Type.getDescriptor(String.class), null, schema.getSchemaHash().toString()).visitEnd(); // Schema field classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "schema", Type.getDescriptor(Schema.class), null, null).visitEnd(); // Encode method generateEncode(outputType, schema); // Constructor generateConstructor(); ClassDefinition classDefinition = new ClassDefinition(classWriter.toByteArray(), className, preservedClasses); // DEBUG block. Uncomment for debug // co.cask.cdap.internal.asm.Debugs.debugByteCode(classDefinition, new java.io.PrintWriter(System.out)); // End DEBUG block return classDefinition; }
From source file:co.cask.cdap.internal.io.DatumWriterGenerator.java
License:Apache License
/** * Generates the constructor. The constructor generated has signature {@code (Schema, FieldAccessorFactory)}. *///from w w w. j a v a2 s.c o m private void generateConstructor() { Method constructor = getMethod(void.class, "<init>", Schema.class, FieldAccessorFactory.class); // Constructor(Schema schema, FieldAccessorFactory accessorFactory) GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, constructor, null, null, classWriter); // super(); // Calling Object constructor mg.loadThis(); mg.invokeConstructor(Type.getType(Object.class), getMethod(void.class, "<init>")); // if (!SCHEMA_HASH.equals(schema.getSchemaHash().toString())) { throw IllegalArgumentException } mg.getStatic(classType, "SCHEMA_HASH", Type.getType(String.class)); mg.loadArg(0); mg.invokeVirtual(Type.getType(Schema.class), getMethod(SchemaHash.class, "getSchemaHash")); mg.invokeVirtual(Type.getType(SchemaHash.class), getMethod(String.class, "toString")); mg.invokeVirtual(Type.getType(String.class), getMethod(boolean.class, "equals", Object.class)); Label hashEquals = mg.newLabel(); mg.ifZCmp(GeneratorAdapter.NE, hashEquals); mg.throwException(Type.getType(IllegalArgumentException.class), "Schema not match."); mg.mark(hashEquals); // this.schema = schema; mg.loadThis(); mg.loadArg(0); mg.putField(classType, "schema", Type.getType(Schema.class)); // For each record field that needs an accessor, get the accessor and store it in field. for (Map.Entry<TypeToken<?>, String> entry : fieldAccessorRequests.entries()) { String fieldAccessorName = getFieldAccessorName(entry.getKey(), entry.getValue()); classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, fieldAccessorName, Type.getDescriptor(FieldAccessor.class), null, null); // this.fieldAccessorName // = accessorFactory.getFieldAccessor(TypeToken.of(Class.forName("className")), "fieldName"); mg.loadThis(); mg.loadArg(1); mg.push(entry.getKey().getRawType().getName()); mg.invokeStatic(Type.getType(Class.class), getMethod(Class.class, "forName", String.class)); mg.invokeStatic(Type.getType(TypeToken.class), getMethod(TypeToken.class, "of", Class.class)); mg.push(entry.getValue()); mg.invokeInterface(Type.getType(FieldAccessorFactory.class), getMethod(FieldAccessor.class, "getFieldAccessor", TypeToken.class, String.class)); mg.putField(classType, fieldAccessorName, Type.getType(FieldAccessor.class)); } mg.returnValue(); mg.endMethod(); }
From source file:co.cask.cdap.internal.io.DatumWriterGenerator.java
License:Apache License
/** * Returns the encode method for the given type and schema. The same method will be returned if the same * type and schema has been passed to the method before. * * @param outputType Type information of the data type for output * @param schema Schema to use for output. * @return A method for encoding the given output type and schema. *//*from w w w. j a v a 2 s .c o m*/ private Method getEncodeMethod(TypeToken<?> outputType, Schema schema) { String key = String.format("%s%s", normalizeTypeName(outputType), schema.getSchemaHash()); Method method = encodeMethods.get(key); if (method != null) { return method; } // Generate the encode method (value, encoder, schema, set) TypeToken<?> callOutputType = getCallTypeToken(outputType, schema); String methodName = String.format("encode%s", key); method = getMethod(void.class, methodName, callOutputType.getRawType(), Encoder.class, Schema.class, Set.class); // Put the method into map first before generating the body in order to support recursive data type. encodeMethods.put(key, method); String methodSignature = Signatures.getMethodSignature(method, callOutputType, null, null, new TypeToken<Set<Object>>() { }); GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE, method, methodSignature, new Type[] { Type.getType(IOException.class) }, classWriter); generateEncodeBody(mg, schema, outputType, 0, 1, 2, 3); mg.returnValue(); mg.endMethod(); return method; }
From source file:co.cask.cdap.internal.io.FieldAccessorGenerator.java
License:Apache License
private void generateConstructor(Field field) { if (isPrivate) { classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "field", Type.getDescriptor(Field.class), null, null).visitEnd(); }/*from w w w . jav a 2 s .co m*/ // Constructor(Type classType) Method constructor = getMethod(void.class, "<init>", java.lang.reflect.Type.class); GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, constructor, null, new Type[0], classWriter); mg.loadThis(); mg.loadArg(0); mg.invokeConstructor(Type.getType(AbstractFieldAccessor.class), constructor); if (isPrivate) { initializeReflectionField(mg, field); } mg.returnValue(); mg.endMethod(); }
From source file:co.cask.common.internal.io.DatumWriterGenerator.java
License:Apache License
/** * Generates a {@link DatumWriter} class for encoding data of the given output type with the given schema. * @param outputType Type information of the output data type. * @param schema Schema of the output data type. * @return A {@link co.cask.common.internal.asm.ClassDefinition} that contains generated class information. *///from w ww . j ava 2 s. c om ClassDefinition generate(TypeToken<?> outputType, Schema schema) { classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); preservedClasses = Lists.newArrayList(); TypeToken<?> interfaceType = getInterfaceType(outputType); // Generate the class String className = getClassName(interfaceType, schema); classType = Type.getObjectType(className); classWriter.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, className, Signatures.getClassSignature(interfaceType), Type.getInternalName(Object.class), new String[] { Type.getInternalName(interfaceType.getRawType()) }); // Static schema hash field, for verification classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "SCHEMA_HASH", Type.getDescriptor(String.class), null, schema.getSchemaHash().toString()).visitEnd(); // Schema field classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "schema", Type.getDescriptor(Schema.class), null, null).visitEnd(); // Encode method generateEncode(outputType, schema); // Constructor generateConstructor(); ClassDefinition classDefinition = new ClassDefinition(classWriter.toByteArray(), className, preservedClasses); // DEBUG block. Uncomment for debug // co.cask.common.internal.asm.Debugs.debugByteCode(classDefinition, new java.io.PrintWriter(System.out)); // End DEBUG block return classDefinition; }