List of usage examples for org.objectweb.asm Opcodes ACC_ABSTRACT
int ACC_ABSTRACT
To view the source code for org.objectweb.asm Opcodes ACC_ABSTRACT.
Click Source Link
From source file:erjang.EFun.java
License:Apache License
static byte[] gen_fun_class_data(int arity) { String self_type = EFUN_TYPE.getInternalName() + arity; ClassWriter cw = new ClassWriter(true); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, self_type, null, EFUN_TYPE.getInternalName(), null); make_invoke_method(cw, self_type, arity); CompilerVisitor.make_invoketail_method(cw, self_type, arity, 0); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "arity", "()I", null, null); mv.visitCode();/*from w ww . jav a 2 s.c o m*/ mv.visitLdcInsn(new Integer(arity)); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "invoke", "(" + EPROC_TYPE.getDescriptor() + EOBJECT_ARR_TYPE.getDescriptor() + ")" + EOBJECT_TYPE.getDescriptor(), null, PAUSABLE_EX); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); // load this mv.visitVarInsn(Opcodes.ALOAD, 1); // load proc for (int i = 0; i < arity; i++) { mv.visitVarInsn(Opcodes.ALOAD, 2); push_int(mv, i); mv.visitInsn(Opcodes.AALOAD); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, self_type, "invoke", EUtil.getSignature(arity, true)); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(arity + 2, arity + 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "()V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, EFUN_TYPE.getInternalName(), "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); make_cast_method(cw, arity); cw.visitEnd(); byte[] data = cw.toByteArray(); return data; }
From source file:erjang.EFun.java
License:Apache License
static byte[] get_exported_fun_class_data(int arity) { /* Code template:// w w w. j a v a2 s . co m * public abstract class EFun{arity}Exported extends EFun{arity} { * protected final EAtom module_name, function_name; * protected EFun{arity}Exported(String m, String f) { * module_name = EAtom.intern(m); * function_name = EAtom.intern(f); * } * } */ ensure(arity); // Ensure presence of superclass. String super_type = EFUN_TYPE.getInternalName() + arity; String self_type = super_type + "Exported"; ClassWriter cw = new ClassWriter(true); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, self_type, null, super_type, null); cw.visitField(ACC_PROTECTED | ACC_FINAL, "module_name", EATOM_TYPE.getDescriptor(), null, null).visitEnd(); cw.visitField(ACC_PROTECTED | ACC_FINAL, "function_name", EATOM_TYPE.getDescriptor(), null, null) .visitEnd(); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, super_type, "<init>", "()V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern", "(Ljava/lang/String;)Lerjang/EAtom;"); mv.visitFieldInsn(Opcodes.PUTFIELD, self_type, "module_name", EATOM_DESC); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern", "(Ljava/lang/String;)Lerjang/EAtom;"); mv.visitFieldInsn(Opcodes.PUTFIELD, self_type, "function_name", EATOM_DESC); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(3, 3); mv.visitEnd(); make_encode_method_for_exported(cw, self_type, arity); cw.visitEnd(); byte[] data = cw.toByteArray(); return data; }
From source file:graph.Modifier.java
License:Apache License
/** * Returns an integer bit field for the EnumSet, where the bit values are * defined as in the class file format.//from ww w. j av a2 s . c o m * * @param set Set of modifiers to convert to a bit field. * @return Integer bit field. */ public static int getBitField(EnumSet<Modifier> set) { int access = 0; if (set.contains(PUBLIC)) { access |= Opcodes.ACC_PUBLIC; } if (set.contains(PROTECTED)) { access |= Opcodes.ACC_PROTECTED; } if (set.contains(PRIVATE)) { access |= Opcodes.ACC_PRIVATE; } if (set.contains(STATIC)) { access |= Opcodes.ACC_STATIC; } if (set.contains(FINAL)) { access |= Opcodes.ACC_FINAL; } if (set.contains(SUPER)) { access |= Opcodes.ACC_SUPER; } if (set.contains(INTERFACE)) { access |= Opcodes.ACC_INTERFACE; } if (set.contains(ABSTRACT)) { access |= Opcodes.ACC_ABSTRACT; } if (set.contains(SYNTHETIC)) { access |= Opcodes.ACC_SYNTHETIC; } if (set.contains(ANNOTATION)) { access |= Opcodes.ACC_ANNOTATION; } if (set.contains(ENUM)) { access |= Opcodes.ACC_ENUM; } if (set.contains(VOLATILE)) { access |= Opcodes.ACC_VOLATILE; } if (set.contains(TRANSIENT)) { access |= Opcodes.ACC_TRANSIENT; } if (set.contains(SYNCHRONIZED)) { access |= Opcodes.ACC_SYNCHRONIZED; } if (set.contains(BRIDGE)) { access |= Opcodes.ACC_BRIDGE; } if (set.contains(VARARGS)) { access |= Opcodes.ACC_VARARGS; } if (set.contains(NATIVE)) { access |= Opcodes.ACC_NATIVE; } return access; }
From source file:graph.Modifier.java
License:Apache License
/** * Returns an EnumSet of the modifiers, based on the given bit field (where * the bit values are defined as in the class file format). * * @param access Integer bit field giving access modifiers. * @return Set of modifiers./*w w w.j a va 2s. co m*/ */ public static EnumSet<Modifier> getSet(int access) { EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); if ((access & Opcodes.ACC_PUBLIC) != 0) { modifiers.add(Modifier.PUBLIC); } if ((access & Opcodes.ACC_PROTECTED) != 0) { modifiers.add(Modifier.PROTECTED); } if ((access & Opcodes.ACC_PRIVATE) != 0) { modifiers.add(Modifier.PRIVATE); } if ((access & Opcodes.ACC_STATIC) != 0) { modifiers.add(Modifier.STATIC); } if ((access & Opcodes.ACC_FINAL) != 0) { modifiers.add(Modifier.FINAL); } if ((access & Opcodes.ACC_SUPER) != 0) { modifiers.add(Modifier.SUPER); } if ((access & Opcodes.ACC_INTERFACE) != 0) { modifiers.add(Modifier.INTERFACE); } if ((access & Opcodes.ACC_ABSTRACT) != 0) { modifiers.add(Modifier.ABSTRACT); } if ((access & Opcodes.ACC_SYNTHETIC) != 0) { modifiers.add(Modifier.SYNTHETIC); } if ((access & Opcodes.ACC_ANNOTATION) != 0) { modifiers.add(Modifier.ANNOTATION); } if ((access & Opcodes.ACC_ENUM) != 0) { modifiers.add(Modifier.ENUM); } if ((access & Opcodes.ACC_VOLATILE) != 0) { modifiers.add(Modifier.VOLATILE); } if ((access & Opcodes.ACC_TRANSIENT) != 0) { modifiers.add(Modifier.TRANSIENT); } if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) { modifiers.add(Modifier.SYNCHRONIZED); } if ((access & Opcodes.ACC_BRIDGE) != 0) { modifiers.add(Modifier.BRIDGE); } if ((access & Opcodes.ACC_VARARGS) != 0) { modifiers.add(Modifier.VARARGS); } if ((access & Opcodes.ACC_NATIVE) != 0) { modifiers.add(Modifier.NATIVE); } if ((access & Opcodes.ACC_STRICT) != 0) { modifiers.add(Modifier.STRICT); } return modifiers; }
From source file:interactivespaces.workbench.project.test.JunitTestClassVisitor.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {// w w w. ja v a2 s. c o m abstractClass = (access & Opcodes.ACC_ABSTRACT) != 0; this.className = name; this.superClassName = superName; }
From source file:io.awacs.plugin.stacktrace.FilteredClassTransformer.java
License:Apache License
/** * /*from w ww .j a v a 2s . c o m*/ * (!?)&&(!)&&(!)&&(!?)&&(!?)&&(!main) */ @Override protected boolean filterMethod(ClassNode cn, MethodNode mn) { return ((cn.access & Opcodes.ACC_INTERFACE) != Opcodes.ACC_INTERFACE && (cn.access & Opcodes.ACC_ABSTRACT) != Opcodes.ACC_ABSTRACT && (mn.access & Opcodes.ACC_NATIVE) != Opcodes.ACC_NATIVE && (mn.access & Opcodes.ACC_ABSTRACT) != Opcodes.ACC_ABSTRACT && !isConstructor(mn) && !isMainMethod(mn)); }
From source file:jp.co.dgic.testing.common.virtualmock.asm2x.AsmClassVisitor2x.java
License:Open Source License
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { boolean isStatic = false; if ((access & Opcodes.ACC_STATIC) > 0) { isStatic = true;// w w w .j av a 2s.c o m } InternalMockObjectManager.printConsole("#################################################################"); InternalMockObjectManager.printConsole("#################################################################"); InternalMockObjectManager .printConsole("### " + access + (isStatic ? " static " : " ") + name + " " + signature); InternalMockObjectManager.printConsole("#################################################################"); InternalMockObjectManager.printConsole("#################################################################"); MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); // is abstract or native if ((access & Opcodes.ACC_ABSTRACT) > 0) return mv; if ((access & Opcodes.ACC_NATIVE) > 0) return mv; if ((access & Opcodes.ACC_BRIDGE) > 0) return mv; int maxLocals = acc.getMaxLocals(name, desc); return createMethodVisitor(mv, name, desc, signature, isStatic, exceptions, maxLocals); }
From source file:kilim.analysis.MethodFlow.java
License:Open Source License
public boolean isAbstract() { return ((this.access & Opcodes.ACC_ABSTRACT) != 0); }
From source file:net.enilink.composition.asm.ExtendedClassNode.java
License:Open Source License
@SuppressWarnings("unchecked") public ExtendedMethod addExtendedMethod(Method method, ClassDefiner definer) throws Exception { Object key = getKey(method);//w ww . ja v a 2s .co m ExtendedMethod extendedMethod = extendedMethods.get(key); if (extendedMethod == null) { extendedMethod = new ExtendedMethod(this, method); MethodNode faceNode = AsmUtils.getClassInfo(method.getDeclaringClass().getName(), definer) .getMethod(org.objectweb.asm.commons.Method.getMethod(method)); faceNode.accept(extendedMethod); methods.add(extendedMethod); extendedMethods.put(key, extendedMethod); extendedMethod.access &= ~Opcodes.ACC_ABSTRACT; } return extendedMethod; }
From source file:net.sf.cglib.proxy.TestEnhancer.java
License:Apache License
public void testBridgeParameterCheckcast() throws Exception { // If the compiler used for Z omits the bridge method, and X is compiled with javac, // javac will generate an invokespecial bridge in X. // public interface I<A, B> { // public A f(B b); // }//from w ww. j a v a 2 s.com // public abstract class Z<U extends Number> implements I<U, Long> { // public U f(Long id) { // return null; // } // } // public class X extends Z<Integer> {} final Map<String, byte[]> classes = new HashMap<String, byte[]>(); { ClassWriter cw = new ClassWriter(0); cw.visit(49, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE, "I", "<A:Ljava/lang/Object;B:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null); { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "f", "(Ljava/lang/Object;)Ljava/lang/Object;", "(TB;)TA;", null); mv.visitEnd(); } cw.visitEnd(); classes.put("I.class", cw.toByteArray()); } { ClassWriter cw = new ClassWriter(0); cw.visit(49, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_ABSTRACT, "Z", "<U:Ljava/lang/Number;>Ljava/lang/Object;LI<TU;Ljava/lang/String;>;", "java/lang/Object", new String[] { "I" }); { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "f", "(Ljava/lang/String;)Ljava/lang/Number;", "(Ljava/lang/String;)TU;", null); mv.visitCode(); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(1, 2); mv.visitEnd(); } cw.visitEnd(); classes.put("Z.class", cw.toByteArray()); } { ClassWriter cw = new ClassWriter(0); cw.visit(49, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, "X", "LZ<Ljava/lang/Integer;>;", "Z", null); { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "Z", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_SYNTHETIC, "f", "(Ljava/lang/Object;)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "Z", "f", "(Ljava/lang/String;)Ljava/lang/Number;", false); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 2); mv.visitEnd(); } cw.visitEnd(); classes.put("X.class", cw.toByteArray()); } ClassLoader classLoader = new ClassLoader(getClass().getClassLoader()) { @Override public InputStream getResourceAsStream(String name) { InputStream is = super.getResourceAsStream(name); if (is != null) { return is; } if (classes.containsKey(name)) { return new ByteArrayInputStream(classes.get(name)); } return null; } public Class findClass(String name) throws ClassNotFoundException { byte[] ba = classes.get(name.replace('.', '/') + ".class"); if (ba != null) { return defineClass(name, ba, 0, ba.length); } throw new ClassNotFoundException(name); } }; List<Class> retTypes = new ArrayList<Class>(); List<Class> paramTypes = new ArrayList<Class>(); Interceptor interceptor = new Interceptor(retTypes, paramTypes); Enhancer e = new Enhancer(); e.setClassLoader(classLoader); e.setSuperclass(classLoader.loadClass("X")); e.setCallback(interceptor); Object c = e.create(); for (Method m : c.getClass().getDeclaredMethods()) { if (m.getName().equals("f") && m.getReturnType().equals(Object.class)) { m.invoke(c, new Object[] { null }); } } // f(Object)Object should bridge to f(Number)String assertEquals(Arrays.asList(Object.class, Number.class), retTypes); assertEquals(Arrays.asList(Object.class, String.class), paramTypes); }