当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor.visitLdcInsn方法代码示例

本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitLdcInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitLdcInsn方法的具体用法?Java MethodVisitor.visitLdcInsn怎么用?Java MethodVisitor.visitLdcInsn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitLdcInsn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ldcI

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static void ldcI(MethodVisitor mv, int i) {
    /* Special opcodes for some integer constants */
    if (i >= -1 && i <= 5) {
        mv.visitInsn(Opcodes.ICONST_0 + i);
    } else {
        /* BIPUSH or SIPUSH if integer constant within certain limits */
        if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
            mv.visitIntInsn(Opcodes.BIPUSH, i);
        } else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
            mv.visitIntInsn(Opcodes.SIPUSH, i);
        } else {
            /* Fallback to LDC */
            mv.visitLdcInsn(Integer.valueOf(i));
        }
    }
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:17,代码来源:Util.java

示例2: loadArgumentsAndValidateArguments

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static int loadArgumentsAndValidateArguments(MethodVisitor mv, Type[] paramTypes, ClassMetadata classMetadata, MethodInfo minfo) {
    int var = 0; // <- counts the used local variables
    for (int i = 0; i < paramTypes.length; i++) {
        Type paramType = paramTypes[i];
        mv.visitVarInsn(paramType.getOpcode(ILOAD), var);
        if (VALIDATE.enabled) {
            if (paramType.getSort() == Type.OBJECT && Util.isBuffer(paramType.getInternalName())) {
                mv.visitInsn(DUP);
                mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "checkBuffer", "(" + paramType.getDescriptor() + ")V", false);
            }
            if (ClassMetadata.hasNullables && (paramType.getSort() == Type.OBJECT || paramType.getSort() == Type.ARRAY) && !minfo.nullable[i]) {
                mv.visitInsn(DUP);
                mv.visitLdcInsn(i);
                if (minfo.parameterNames[i] != null)
                    mv.visitLdcInsn(minfo.parameterNames[i]);
                else
                    mv.visitInsn(ACONST_NULL);
                mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "checkNotNull", "(Ljava/lang/Object;ILjava/lang/String;)V", false);
            }
        }
        var += paramType.getSize();
    }
    return var;
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:25,代码来源:InterceptClassGenerator.java

示例3: callUserMethodOrDirect

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void callUserMethodOrDirect(ClassLoader classLoader, InterceptedCall call, MethodVisitor mv) {
    /* Check if we have a user-provided validation method */
    String validationMethodOwnerName = getClassForMethod(classLoader, call.desc, call);
    if (validationMethodOwnerName != null) {
        /* we have, so call it... */
        mv.visitMethodInsn(INVOKESTATIC, validationMethodOwnerName, call.name, call.desc, false);
    } else {
        /* we don't have a user-defined validation method yet, so just call the target method directly */
        mv.visitMethodInsn(INVOKESTATIC, call.receiverInternalName, call.name, call.desc, false);
    }
    /* Check GL error if it was a GL call */
    if (VALIDATE.enabled && call.glName != null && !call.glName.equals("glGetError")) {
        mv.visitLdcInsn(call.name);
        mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "checkError", "(Ljava/lang/String;)V", false);
    }
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:17,代码来源:InterceptClassGenerator.java

示例4: generateClass

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static byte[] generateClass(Class<? extends TileEntity> baseClass, String className, String contentId)
{
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(baseClass), null);

    // Constructor
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(contentId);
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(baseClass), "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();

    return cw.toByteArray();
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:17,代码来源:TileEntityRegistry.java

示例5: insertBooleanGetter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void insertBooleanGetter(MethodVisitor mv, int var, String key) {
    loadVar(mv, var);
    mv.visitLdcInsn(key);
    mv.visitMethodInsn(INVOKEINTERFACE, DATA.getInternalName(), "getBoolean",
            Type.getMethodDescriptor(Type.BOOLEAN_TYPE, STRING), true);
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:8,代码来源:SimpleDataManager.java

示例6: addTypeSpecial

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void addTypeSpecial(MethodVisitor mv, Class<?> type) {
    if (type.isPrimitive()) {
        mv.visitFieldInsn(GETSTATIC, Type.getInternalName(getBoxed(type)), "TYPE", "Ljava/lang/Class;");

    } else {
        mv.visitLdcInsn(Type.getType(Type.getDescriptor(type)));
    }
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:9,代码来源:ProxyClassGenerator.java

示例7: insertStringGetter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void insertStringGetter(MethodVisitor mv, int var, String key, boolean escaped) {
    loadVar(mv, var);
    mv.visitLdcInsn(key);
    mv.visitMethodInsn(INVOKEINTERFACE, DATA.getInternalName(), escaped ? "get" : "getUnescaped",
            Type.getMethodDescriptor(STRING, STRING), true);
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:8,代码来源:SimpleDataManager.java

示例8: insertNewInstanceInner

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static void insertNewInstanceInner(ClassWriter cw, String classNameInternal, String enclosingClassNameInternal) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newInstance", "(Ljava/lang/Object;)Ljava/lang/Object;", null,
			null);
	mv.visitCode();
	if (enclosingClassNameInternal != null) {
		mv.visitTypeInsn(NEW, classNameInternal);
		mv.visitInsn(DUP);
		mv.visitVarInsn(ALOAD, 1);
		mv.visitTypeInsn(CHECKCAST, enclosingClassNameInternal);
		mv.visitInsn(DUP);
		mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;");
		mv.visitInsn(POP);
		mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "(L" + enclosingClassNameInternal + ";)V");
		mv.visitInsn(ARETURN);
		mv.visitMaxs(4, 2);
	} else {
		mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
		mv.visitInsn(DUP);
		mv.visitLdcInsn("Not an inner class.");
		mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
				"(Ljava/lang/String;)V");
		mv.visitInsn(ATHROW);
		mv.visitMaxs(3, 2);
	}
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:28,代码来源:ConstructorAccess.java

示例9: genExceptionThrowForUnknownParam

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void genExceptionThrowForUnknownParam(String paramType, MethodVisitor mv) {
    mv.visitTypeInsn(NEW, "java/lang/IllegalArgumentException");
    mv.visitInsn(DUP);
    mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
    mv.visitInsn(DUP);
    mv.visitLdcInsn("No " + paramType + " parameter named ");
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
            false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ATHROW);
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:15,代码来源:MethodArgumentssUpdaterGenerator.java

示例10: applyConventionMappingToSetter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public void applyConventionMappingToSetter(PropertyMetaData property, Method setter) throws Exception {
    // GENERATE public <return-type> <setter>(<type> v) { <return-type> v = super.<setter>(v); __<prop>__ = true; return v; }

    Type paramType = Type.getType(setter.getParameterTypes()[0]);
    Type returnType = Type.getType(setter.getReturnType());
    String setterDescriptor = Type.getMethodDescriptor(returnType, paramType);
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, setter.getName(), setterDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();

    // GENERATE super.<setter>(v)

    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(paramType.getOpcode(Opcodes.ILOAD), 1);

    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), setter.getName(), setterDescriptor, false);

    // END

    // GENERATE __<prop>__ = true

    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitLdcInsn(true);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, generatedType.getInternalName(), propFieldName(property), Type.BOOLEAN_TYPE.getDescriptor());

    // END

    methodVisitor.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:31,代码来源:AsmBackedClassGenerator.java

示例11: writeGenericReturnTypeFieldInitializer

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeGenericReturnTypeFieldInitializer(MethodVisitor mv, ReturnTypeEntry returnType) {
    mv.visitLdcInsn(generatedType);

    // <class>.getDeclaredMethod(<getter-name>)
    mv.visitLdcInsn(returnType.getterName);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitTypeInsn(Opcodes.ANEWARRAY, CLASS_TYPE.getInternalName());
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CLASS_TYPE.getInternalName(), "getDeclaredMethod", GET_DECLARED_METHOD_DESCRIPTOR, false);
    // <method>.getGenericReturnType()
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, METHOD_TYPE.getInternalName(), "getGenericReturnType", Type.getMethodDescriptor(JAVA_LANG_REFLECT_TYPE), false);
    mv.visitFieldInsn(PUTSTATIC, generatedType.getInternalName(), returnType.fieldName, JAVA_REFLECT_TYPE_DESCRIPTOR);

}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:AsmBackedClassGenerator.java

示例12: pushInt

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void pushInt(MethodVisitor mv, int i) {
    if (0 <= i && i <= 5) {
        mv.visitInsn(Opcodes.ICONST_0 + i); //  ICONST_0 ~ ICONST_5
    } else if (i <= Byte.MAX_VALUE) {
        mv.visitIntInsn(Opcodes.BIPUSH, i);
    } else if (i <= Short.MAX_VALUE) {
        mv.visitIntInsn(Opcodes.SIPUSH, i);
    } else {
        mv.visitLdcInsn(i);
    }
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:12,代码来源:ShrinkRClassVisitor.java

示例13: insertThrowExceptionForFieldType

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static private MethodVisitor insertThrowExceptionForFieldType(MethodVisitor mv, String fieldType) {
	mv.visitTypeInsn(NEW, "java/lang/IllegalArgumentException");
	mv.visitInsn(DUP);
	mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
	mv.visitInsn(DUP);
	mv.visitLdcInsn("Field not declared as " + fieldType + ": ");
	mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V");
	mv.visitVarInsn(ILOAD, 2);
	mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;");
	mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
	mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V");
	mv.visitInsn(ATHROW);
	return mv;
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:16,代码来源:FieldAccess.java

示例14: generateMethodTest13

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 * MethodHandle of kind put instance. The method handle write an instance field in a class and
 * then print its value.
 */
private void generateMethodTest13(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test13", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitVarInsn(Opcodes.ASTORE, 0);
  mv.visitVarInsn(Opcodes.ALOAD, 0);
  mv.visitLdcInsn("Write instance field");
  mv.visitInvokeDynamicInsn("instanceField1", "(Linvokecustom/InvokeCustom;Ljava/lang/String;)V",
      bootstrap, new Handle(Opcodes.H_PUTFIELD, Type.getInternalName(InvokeCustom.class),
          "instanceField1", "Ljava/lang/String;", false));
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitVarInsn(Opcodes.ALOAD, 0);
  mv.visitFieldInsn(Opcodes.GETFIELD,
      Type.getInternalName(InvokeCustom.class),
      "instanceField1",
      "Ljava/lang/String;");
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:39,代码来源:TestGenerator.java

示例15: buildClosureClass

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void buildClosureClass(TContext closure_ctx) throws CompileException {
  Debug.assertion(closure_ctx instanceof TContextClosure, "closure_ctx should be closure ctx");

  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
  ((TContextClosure) closure_ctx).setClassWriter(cw);

  cw.visit(Compiler.java_version, Opcodes.ACC_PUBLIC, closure_ctx.getName(), null, "java/lang/Object", null);

  // default constructor
  MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
  mv.visitCode();

  LOG.info("ALOAD 0 for this");
  LOG.info("INVOKESPECIAL java/lang/Object");

  mv.visitVarInsn(Opcodes.ALOAD, 0); // this
  mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
  if (Debug.enable_compile_debug_print) {
    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn(closure_ctx.getName() + " was instantiated");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
  }
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(0, 0);
  mv.visitEnd();
  // end default constructor

  TContext parent_ctx = (TContext) closure_ctx.getOwnerType();
  Debug.assertion(parent_ctx != null, "parent_ctx should be valid");

  // add closure class member field
  Container var_cont = null;
  AbsType var_type = null;

  LinkedList<Container> var_list = closure_ctx.get_childvar_list();
  int var_size = var_list.size();
  Container closure_member_var = null;

  for (int i = 0; i < var_size; i++) {
    closure_member_var = var_list.get(i);
    var_cont = closure_member_var.getClosureOrgFuncvarContainer();

    Debug.assertion(var_cont != null, "var_cont should be valid");
    // Debug.assertion(var_cont.isForm(Container.FORM_FUNSTACK_VAR), "var_cont
    // should be stack variable");
    Debug.assertion(var_cont.isTypeInitialized(), "var_cont type should be initialized");

    if (var_cont.isForm(Container.FORM_FUNSTACK_VAR)) {
      // only assigned stack variable will be copied
      if (var_cont.isAssigned()) {
        LOG.debug("  (" + var_cont.getContextVarIdx() + ") " + var_cont);
        var_type = var_cont.getType();
        cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
      }
    } else if (var_cont.isForm(Container.FORM_OBJMEMBER_VAR)) {
      LOG.debug("  (" + var_cont.getContextVarIdx() + ") " + var_cont);
      var_type = var_cont.getType();
      cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
    } else {
      throw new CompileException("Invalid var_cont form(" + var_cont + ")");
    }

  }

}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:66,代码来源:ASTCompileVisitor.java


注:本文中的org.objectweb.asm.MethodVisitor.visitLdcInsn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。