本文整理汇总了Java中org.objectweb.asm.ClassWriter.visitSource方法的典型用法代码示例。如果您正苦于以下问题:Java ClassWriter.visitSource方法的具体用法?Java ClassWriter.visitSource怎么用?Java ClassWriter.visitSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.ClassWriter
的用法示例。
在下文中一共展示了ClassWriter.visitSource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public byte[] compile(String className, Class<?> clazz) throws IOException, CompilerException {
ClassWriter cw = new ClassWriter(0);
Type clazzType = Type.getType(clazz);
String internalName = className.replace('.', '/');
String classDesc = "L" + internalName + ";";
String signature = BytecodeGenerator.OBJECT.getDescriptor() + "L" +
BytecodeGenerator.OBJECT_TEMPLATE.getInternalName() + "<" + clazzType.getDescriptor() + ">;";
cw.visit(52, ACC_PUBLIC + ACC_SUPER, internalName, signature,
BytecodeGenerator.OBJECT.getInternalName(),
new String[]{BytecodeGenerator.OBJECT_TEMPLATE.getInternalName()});
cw.visitSource(templateName, null);
createConstructor(cw, classDesc);
createObjectRender(cw, internalName, classDesc, clazzType);
DataManager getter = new ClassDataManager(clazz, clazzType);
generator = new BytecodeGenerator(this, cw, getter, internalName, classDesc);
generator.insertMethodStart("render");
parser.parse();
generator.insertMethodEnd();
cw.visitEnd();
return cw.toByteArray();
}
示例2: generateClass
import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public static byte[] generateClass() {
ClassWriter cw = new ClassWriter(0);
cw.visit(52, ACC_SUPER | ACC_PUBLIC, INNER_CLASS_NAME_INTERNAL, null, "java/lang/Object", null);
cw.visitSource("UnbalancedMonitorsTest.java", null);
cw.visitInnerClass(INNER_CLASS_NAME_INTERNAL, CLASS_NAME_INTERNAL, "UnbalancedMonitors", ACC_STATIC);
visitConstructor(cw);
visitWrongOrder(cw);
visitBlockStructured(cw, true, false);
visitBlockStructured(cw, true, true);
visitBlockStructured(cw, false, false);
visitBlockStructured(cw, false, true);
cw.visitEnd();
return cw.toByteArray();
}
示例3: generateFields
import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private static void generateFields(Method method, ClassWriter cw, Parameter[] parameters) {
FieldVisitor fv;
cw.visitSource(method.getName() + "[email protected]@aspecio", null);
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL, "parameters", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/reflect/Parameter;>;",
null);
fv.visitEnd();
for (Parameter p : parameters) {
fv = cw.visitField(ACC_PUBLIC, p.getName(), Type.getDescriptor(p.getType()), null, null);
fv.visitEnd();
}
}
示例4: generateFields
import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private static void generateFields(Method method, ClassWriter cw, Parameter[] parameters) {
FieldVisitor fv;
cw.visitSource(method.getName() + "[email protected]", null);
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL, "parameters", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/reflect/Parameter;>;",
null);
fv.visitEnd();
for (Parameter p : parameters) {
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL, p.getName(), Type.getDescriptor(p.getType()), null, null);
fv.visitEnd();
}
}
示例5: compileSimple
import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public byte[] compileSimple(String className, Map<String, MustacheType> types) throws IOException, CompilerException {
ClassWriter cw = new ClassWriter(0);
String internalName = className.replace('.', '/');
String classDesc = "L" + internalName + ";";
cw.visit(52, ACC_PUBLIC + ACC_SUPER,
internalName, null,
BytecodeGenerator.OBJECT.getInternalName(),
new String[]{BytecodeGenerator.SIMPLE_TEMPLATE.getInternalName()});
cw.visitSource(templateName, null);
createConstructor(cw, classDesc);
DataManager data;
if(types != null && !types.isEmpty()) {
data = new TypedDataManager(types);
} else {
data = new SimpleDataManager();
}
generator = new BytecodeGenerator(this, cw, data, className, classDesc);
generator.insertMethodStart("render");
parser.parse();
generator.insertMethodEnd();
cw.visitEnd();
return cw.toByteArray();
}
示例6: createWrapper
import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public Class<?> createWrapper(Method callback)
{
if (cache.containsKey(callback))
{
return cache.get(callback);
}
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
boolean isStatic = Modifier.isStatic(callback.getModifiers());
String name = getUniqueName(callback);
String desc = name.replace('.', '/');
String instType = Type.getInternalName(callback.getDeclaringClass());
String eventType = Type.getInternalName(callback.getParameterTypes()[0]);
/*
System.out.println("Name: " + name);
System.out.println("Desc: " + desc);
System.out.println("InstType: " + instType);
System.out.println("Callback: " + callback.getName() + Type.getMethodDescriptor(callback));
System.out.println("Event: " + eventType);
*/
cw.visit(V1_6, ACC_PUBLIC | ACC_SUPER, desc, null, "java/lang/Object", new String[]{ HANDLER_DESC });
cw.visitSource(".dynamic", null);
{
if (!isStatic)
cw.visitField(ACC_PUBLIC, "instance", "Ljava/lang/Object;", null, null).visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", isStatic ? "()V" : "(Ljava/lang/Object;)V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
if (!isStatic)
{
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitFieldInsn(PUTFIELD, desc, "instance", "Ljava/lang/Object;");
}
mv.visitInsn(RETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "invoke", HANDLER_FUNC_DESC, null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
if (!isStatic)
{
mv.visitFieldInsn(GETFIELD, desc, "instance", "Ljava/lang/Object;");
mv.visitTypeInsn(CHECKCAST, instType);
}
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, eventType);
mv.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, instType, callback.getName(), Type.getMethodDescriptor(callback), false);
mv.visitInsn(RETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
cw.visitEnd();
Class<?> ret = LOADER.define(name, cw.toByteArray());
cache.put(callback, ret);
return ret;
}