use of org.objectweb.asm.commons.Method in project Payara by payara.
the class EjbOptionalIntfGenerator method generateNonAccessibleMethod.
private static void generateNonAccessibleMethod(ClassVisitor cv, java.lang.reflect.Method m) {
String methodName = m.getName();
Type returnType = Type.getReturnType(m);
Type[] argTypes = Type.getArgumentTypes(m);
Method asmMethod = new Method(methodName, returnType, argTypes);
// Only called for non-static Protected or Package access
int access = ACC_PUBLIC;
GeneratorAdapter mg = new GeneratorAdapter(access, asmMethod, null, getExceptionTypes(m), cv);
mg.throwException(Type.getType(javax.ejb.EJBException.class), "Illegal non-business method access on no-interface view");
mg.returnValue();
mg.endMethod();
}
use of org.objectweb.asm.commons.Method in project jacoco by jacoco.
the class RuntimeTestBase method generateAndInstantiateClass.
/**
* Creates a new class with the given id, loads this class and instantiates
* it. The constructor of the generated class will request the probe array
* from the runtime under test.
*/
private ITarget generateAndInstantiateClass(int classid) throws InstantiationException, IllegalAccessException {
final String className = "org/jacoco/test/targets/RuntimeTestTarget_" + classid;
Type classType = Type.getObjectType(className);
final ClassWriter writer = new ClassWriter(0);
writer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", new String[] { Type.getInternalName(ITarget.class) });
writer.visitField(InstrSupport.DATAFIELD_ACC, InstrSupport.DATAFIELD_NAME, InstrSupport.DATAFIELD_DESC, null, null);
// Constructor
GeneratorAdapter gen = new GeneratorAdapter(writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]), Opcodes.ACC_PUBLIC, "<init>", "()V");
gen.visitCode();
gen.loadThis();
gen.invokeConstructor(Type.getType(Object.class), new Method("<init>", "()V"));
gen.loadThis();
final int size = runtime.generateDataAccessor(classid, className, 2, gen);
gen.putStatic(classType, InstrSupport.DATAFIELD_NAME, Type.getObjectType(InstrSupport.DATAFIELD_DESC));
gen.returnValue();
gen.visitMaxs(size + 1, 0);
gen.visitEnd();
// get()
gen = new GeneratorAdapter(writer.visitMethod(Opcodes.ACC_PUBLIC, "get", "()[Z", null, new String[0]), Opcodes.ACC_PUBLIC, "get", "()[Z");
gen.visitCode();
gen.getStatic(classType, InstrSupport.DATAFIELD_NAME, Type.getObjectType(InstrSupport.DATAFIELD_DESC));
gen.returnValue();
gen.visitMaxs(1, 0);
gen.visitEnd();
// a()
gen = new GeneratorAdapter(writer.visitMethod(Opcodes.ACC_PUBLIC, "a", "()V", null, new String[0]), Opcodes.ACC_PUBLIC, "a", "()V");
gen.visitCode();
gen.getStatic(classType, InstrSupport.DATAFIELD_NAME, Type.getObjectType(InstrSupport.DATAFIELD_DESC));
gen.push(0);
gen.push(1);
gen.arrayStore(Type.BOOLEAN_TYPE);
gen.returnValue();
gen.visitMaxs(3, 0);
gen.visitEnd();
// b()
gen = new GeneratorAdapter(writer.visitMethod(Opcodes.ACC_PUBLIC, "b", "()V", null, new String[0]), Opcodes.ACC_PUBLIC, "b", "()V");
gen.visitCode();
gen.getStatic(classType, InstrSupport.DATAFIELD_NAME, Type.getObjectType(InstrSupport.DATAFIELD_DESC));
gen.push(1);
gen.push(1);
gen.arrayStore(Type.BOOLEAN_TYPE);
gen.returnValue();
gen.visitMaxs(3, 0);
gen.visitEnd();
writer.visitEnd();
final TargetLoader loader = new TargetLoader();
return (ITarget) loader.add(className.replace('/', '.'), writer.toByteArray()).newInstance();
}
use of org.objectweb.asm.commons.Method in project jacoco by jacoco.
the class OfflineInstrumentationAccessGeneratorTest method generateAndInstantiateClass.
/**
* Creates a new class with the given id, loads this class and instantiates
* it. The constructor of the generated class will request the probe array
* from the access generator under test.
*/
private ITarget generateAndInstantiateClass(int classid) throws InstantiationException, IllegalAccessException {
final String className = "org/jacoco/test/targets/RuntimeTestTarget_" + classid;
Type classType = Type.getObjectType(className);
final ClassWriter writer = new ClassWriter(0);
writer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", new String[] { Type.getInternalName(ITarget.class) });
writer.visitField(InstrSupport.DATAFIELD_ACC, InstrSupport.DATAFIELD_NAME, InstrSupport.DATAFIELD_DESC, null, null);
// Constructor
GeneratorAdapter gen = new GeneratorAdapter(writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]), Opcodes.ACC_PUBLIC, "<init>", "()V");
gen.visitCode();
gen.loadThis();
gen.invokeConstructor(Type.getType(Object.class), new Method("<init>", "()V"));
gen.loadThis();
final int size = generator.generateDataAccessor(classid, className, 2, gen);
gen.putStatic(classType, InstrSupport.DATAFIELD_NAME, Type.getObjectType(InstrSupport.DATAFIELD_DESC));
gen.returnValue();
gen.visitMaxs(size + 1, 0);
gen.visitEnd();
// get()
gen = new GeneratorAdapter(writer.visitMethod(Opcodes.ACC_PUBLIC, "get", "()[Z", null, new String[0]), Opcodes.ACC_PUBLIC, "get", "()[Z");
gen.visitCode();
gen.getStatic(classType, InstrSupport.DATAFIELD_NAME, Type.getObjectType(InstrSupport.DATAFIELD_DESC));
gen.returnValue();
gen.visitMaxs(1, 0);
gen.visitEnd();
writer.visitEnd();
final TargetLoader loader = new TargetLoader();
return (ITarget) loader.add(className.replace('/', '.'), writer.toByteArray()).newInstance();
}
use of org.objectweb.asm.commons.Method in project MinecraftForge by MinecraftForge.
the class ASMTransformerWrapper method makeWrapper.
private static byte[] makeWrapper(String fileName) {
if (!wrapperModMap.containsKey(fileName) || !wrapperParentMap.containsKey(fileName) || !fileName.endsWith(".class")) {
throw new IllegalArgumentException("makeWrapper called with strange argument: " + fileName);
}
String name = fileName.substring(0, fileName.length() - ".class".length());
try {
Type wrapper = Type.getType(TransformerWrapper.class);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
writer.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, name, null, wrapper.getInternalName(), null);
Method m = Method.getMethod("void <init> ()");
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, writer);
mg.loadThis();
mg.invokeConstructor(wrapper, m);
mg.returnValue();
mg.endMethod();
m = Method.getMethod("java.lang.String getParentClass ()");
mg = new GeneratorAdapter(Opcodes.ACC_PROTECTED, m, null, null, writer);
mg.push(wrapperParentMap.get(fileName));
mg.returnValue();
mg.endMethod();
m = Method.getMethod("java.lang.String getCoreMod ()");
mg = new GeneratorAdapter(Opcodes.ACC_PROTECTED, m, null, null, writer);
mg.push(wrapperModMap.get(fileName));
mg.returnValue();
mg.endMethod();
writer.visitEnd();
return writer.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.objectweb.asm.commons.Method in project deltaspike by apache.
the class AsmProxyClassGenerator method defineSuperAccessorMethod.
private static void defineSuperAccessorMethod(ClassWriter cw, java.lang.reflect.Method method, Type superType, String superAccessorMethodSuffix) {
Method originalAsmMethod = Method.getMethod(method);
Method newAsmMethod = new Method(method.getName() + superAccessorMethodSuffix, originalAsmMethod.getReturnType(), originalAsmMethod.getArgumentTypes());
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, newAsmMethod, null, null, cw);
mg.visitCode();
// call super method
mg.loadThis();
mg.loadArgs();
mg.visitMethodInsn(Opcodes.INVOKESPECIAL, superType.getInternalName(), method.getName(), Type.getMethodDescriptor(method), false);
mg.returnValue();
// finish the method
mg.endMethod();
mg.visitMaxs(10, 10);
mg.visitEnd();
}
Aggregations