當前位置: 首頁>>代碼示例>>Java>>正文


Java Type.getMethodDescriptor方法代碼示例

本文整理匯總了Java中org.objectweb.asm.Type.getMethodDescriptor方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.getMethodDescriptor方法的具體用法?Java Type.getMethodDescriptor怎麽用?Java Type.getMethodDescriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.objectweb.asm.Type的用法示例。


在下文中一共展示了Type.getMethodDescriptor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addSetMethod

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public void addSetMethod(PropertyMetaData property, Method setter) throws Exception {
    Type paramType = Type.getType(setter.getParameterTypes()[0]);
    Type returnType = Type.getType(setter.getReturnType());
    String setterDescriptor = Type.getMethodDescriptor(returnType, paramType);

    // GENERATE public void <propName>(<type> v) { <setter>(v) }
    String setMethodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, paramType);
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, property.getName(), setMethodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();

    // GENERATE <setter>(v)

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

    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, generatedType.getInternalName(), setter.getName(), setterDescriptor, false);

    // END

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:24,代碼來源:AsmBackedClassGenerator.java

示例2: continueLoop

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static AbstractInsnNode continueLoop() {
  return new MethodInsnNode(
      INVOKESTATIC,
      Type.getInternalName(Dispatch.class),
      "signed_le",
      Type.getMethodDescriptor(
          Type.BOOLEAN_TYPE,
          Type.getType(Number.class),
          Type.getType(Number.class),
          Type.getType(Number.class)),
      false);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:13,代碼來源:DispatchMethods.java

示例3: generateMethodArgsUpdater

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static byte[] generateMethodArgsUpdater(Class<?> classToProxy, Method method, int methodId) throws Exception {

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

        String classToProxyDescriptor = Type.getDescriptor(classToProxy);
        String classToProxyInternalName = Type.getInternalName(classToProxy);

        String suffix = SUFFIX_START + method.getName() + methodId;
        String selfClassInternalName = classToProxyInternalName + suffix;
        String selfClassDescriptor = BytecodeGenUtils.makeSuffixClassDescriptor(classToProxyDescriptor, suffix);

        String argsClassInternalName = classToProxyInternalName + MethodArgumentsGenerator.SUFFIX_START + method.getName() + methodId;

        String constDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
                Stream.concat(Stream.of(List.class), Stream.of(method.getParameterTypes())).map(Type::getType)
                        .toArray(Type[]::new));

        cw.visit(52, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, selfClassInternalName, null, "java/lang/Object",
                new String[] {  "io/primeval/reflex/arguments/ArgumentsUpdater" });
        Parameter[] parameters = method.getParameters();

        generateFields(method, cw, parameters);
        generateConstructor(method, cw, selfClassInternalName, selfClassDescriptor, constDesc, parameters);
        generateHashCodeMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateEqualsMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateToStringMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);


        generateUpdateMethod(cw, selfClassInternalName, selfClassDescriptor, argsClassInternalName, constDesc, parameters);

        generateParametersGetter(cw, selfClassInternalName, selfClassDescriptor);

        generateArgumentSetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
        generateArgumentGetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
        cw.visitEnd();

        return cw.toByteArray();
    }
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:39,代碼來源:MethodArgumentssUpdaterGenerator.java

示例4: addConstructor

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public void addConstructor(Constructor<?> constructor) throws Exception {
    List<Type> paramTypes = new ArrayList<Type>();
    for (Class<?> paramType : constructor.getParameterTypes()) {
        paramTypes.add(Type.getType(paramType));
    }
    String methodDescriptor = Type.getMethodDescriptor(VOID_TYPE, paramTypes.toArray(EMPTY_TYPES));

    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", methodDescriptor, signature(constructor), EMPTY_STRINGS);

    for (Annotation annotation : constructor.getDeclaredAnnotations()) {
        if (annotation.annotationType().getAnnotation(Inherited.class) != null) {
            continue;
        }
        Retention retention = annotation.annotationType().getAnnotation(Retention.class);
        AnnotationVisitor annotationVisitor = methodVisitor.visitAnnotation(Type.getType(annotation.annotationType()).getDescriptor(), retention != null && retention.value() == RetentionPolicy.RUNTIME);
        annotationVisitor.visitEnd();
    }

    methodVisitor.visitCode();

    // this.super(p0 .. pn)
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    for (int i = 0; i < constructor.getParameterTypes().length; i++) {
        methodVisitor.visitVarInsn(Type.getType(constructor.getParameterTypes()[i]).getOpcode(Opcodes.ILOAD), i + 1);
    }
    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>", methodDescriptor, false);

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:32,代碼來源:AsmBackedClassGenerator.java

示例5: addSetter

import org.objectweb.asm.Type; //導入方法依賴的package包/類
private void addSetter(Method method, MethodCodeBody body) throws Exception {
    String methodDescriptor = Type.getMethodDescriptor(method);
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();
    body.add(methodVisitor);
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,代碼來源:AsmBackedClassGenerator.java

示例6: registerTicks

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static MethodInsnNode registerTicks() {
  return new MethodInsnNode(
      INVOKEINTERFACE,
      selfTpe().getInternalName(),
      "registerTicks",
      Type.getMethodDescriptor(
          Type.VOID_TYPE,
          Type.INT_TYPE),
      true);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:11,代碼來源:ExecutionContextMethods.java

示例7: rawset

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static AbstractInsnNode rawset() {
  return new MethodInsnNode(
      INVOKEVIRTUAL,
      Type.getInternalName(Table.class),
      "rawset",
      Type.getMethodDescriptor(
          Type.VOID_TYPE,
          Type.getType(Object.class),
          Type.getType(Object.class)),
      false);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:12,代碼來源:TableMethods.java

示例8: insertString

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public void insertString(String string) throws CompilerException {
    if(string.length() == 0) return;

    if(!builderLoaded && needLocal) {
        mv.visitVarInsn(ALOAD, varBuilder);
        builderLoaded = true;
    }

    String desc;

    if(string.length() == 1) {
        // Uses append(char)
        int c = (int)string.charAt(0);
        if(c < Byte.MAX_VALUE) {
            mv.visitIntInsn(BIPUSH, c);
        } else {
            mv.visitLdcInsn(c);
        }
        desc = Type.getMethodDescriptor(BUILDER, Type.CHAR_TYPE);
    } else {
        // Uses append(String)
        mv.visitLdcInsn(string);
        desc = Type.getMethodDescriptor(BUILDER, STRING);
    }

    // builder.append(...)
    mv.visitMethodInsn(INVOKEVIRTUAL, BUILDER.getInternalName(), "append", desc, false);
}
 
開發者ID:Guichaguri,項目名稱:FastMustache,代碼行數:29,代碼來源:BytecodeGenerator.java

示例9: constructor

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static AbstractInsnNode constructor() {
  return new MethodInsnNode(
      INVOKESPECIAL,
      selfTpe().getInternalName(),
      "<init>",
      Type.getMethodDescriptor(
          Type.VOID_TYPE,
          Type.getType(Object.class)),
      false);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:11,代碼來源:VariableMethods.java

示例10: boxedNumberToLuaFormatString

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static AbstractInsnNode boxedNumberToLuaFormatString() {
  return new MethodInsnNode(
      INVOKESTATIC,
      Type.getInternalName(Conversions.class),
      "stringValueOf",
      Type.getMethodDescriptor(
          Type.getType(String.class),
          Type.getType(Number.class)),
      false);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:11,代碼來源:ConversionMethods.java

示例11: applyConventionMappingToSetMethod

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public void applyConventionMappingToSetMethod(PropertyMetaData property, Method method) throws Exception {
    Type paramType = Type.getType(method.getParameterTypes()[0]);
    Type returnType = Type.getType(method.getReturnType());
    String methodDescriptor = Type.getMethodDescriptor(returnType, paramType);

    // GENERATE public <returnType> <propName>(<type> v) { val = super.<propName>(v); __<prop>__ = true; return val; }
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();

    // GENERATE super.<propName>(v)

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

    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), method.getName(), methodDescriptor, false);

    // 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,代碼行數:29,代碼來源:AsmBackedClassGenerator.java

示例12: addActionMethod

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public void addActionMethod(Method method) throws Exception {
    Type returnType = Type.getType(method.getReturnType());

    Type[] originalParameterTypes = CollectionUtils.collectArray(method.getParameterTypes(), Type.class, new Transformer<Type, Class>() {
        public Type transform(Class clazz) {
            return Type.getType(clazz);
        }
    });
    int numParams = originalParameterTypes.length;
    Type[] closurisedParameterTypes = new Type[numParams];
    System.arraycopy(originalParameterTypes, 0, closurisedParameterTypes, 0, numParams);
    closurisedParameterTypes[numParams - 1] = CLOSURE_TYPE;

    String methodDescriptor = Type.getMethodDescriptor(returnType, closurisedParameterTypes);

    // GENERATE public <return type> <method>(Closure v) { return <method>(…, ConfigureUtil.configureUsing(v)); }
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();

    // GENERATE <method>(…, ConfigureUtil.configureUsing(v));
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);

    for (int stackVar = 1; stackVar < numParams; ++stackVar) {
        methodVisitor.visitVarInsn(closurisedParameterTypes[stackVar - 1].getOpcode(Opcodes.ILOAD), stackVar);
    }

    // GENERATE ConfigureUtil.configureUsing(v);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, numParams);
    methodDescriptor = Type.getMethodDescriptor(ACTION_TYPE, CLOSURE_TYPE);
    methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, CONFIGURE_UTIL_TYPE.getInternalName(), "configureUsing", methodDescriptor, false);

    methodDescriptor = Type.getMethodDescriptor(Type.getType(method.getReturnType()), originalParameterTypes);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, generatedType.getInternalName(), method.getName(), methodDescriptor, false);

    methodVisitor.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:39,代碼來源:AsmBackedClassGenerator.java

示例13: rawBinaryOperator

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static AbstractInsnNode rawBinaryOperator(String methodName, Type returnType,
    Type argType) {
  return new MethodInsnNode(
      INVOKESTATIC,
      Type.getInternalName(LuaMathOperators.class),
      methodName,
      Type.getMethodDescriptor(
          returnType,
          argType,
          argType),
      false);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:13,代碼來源:OperatorMethods.java

示例14: StringBuilder_toString

import org.objectweb.asm.Type; //導入方法依賴的package包/類
public static AbstractInsnNode StringBuilder_toString() {
  return new MethodInsnNode(
      INVOKEVIRTUAL,
      Type.getInternalName(StringBuilder.class),
      "toString",
      Type.getMethodDescriptor(
          Type.getType(String.class)),
      false);
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:10,代碼來源:UtilMethods.java

示例15: generateMethodProxy

import org.objectweb.asm.Type; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, null, null, _, _ -> fail")
static void generateMethodProxy(ClassVisitor cv, Method interfaceMethod,
                                Type reflectorClass, Type targetClass, Type interfaceClass,
                                String targetMethodName, Type[] targetParameters, Type targetReturnType,
                                int flags, int mhIndex) {
    String methodName = interfaceMethod.getName();
    String methodDesc = Type.getMethodDescriptor(interfaceMethod);
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
    GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
    adapter.visitCode();

    /* Load MethodHandle, if required */
    loadMH(adapter, reflectorClass, flags, mhIndex);

    /* Load instance, if required */
    loadInstance(adapter, reflectorClass, targetClass, flags);

    /* Load method parameters into stack */
    loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0);

    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
        /* Build MethodHandle descriptor (invokeExact is polymorphic) */
        String mhDescriptor = convertDesc(targetParameters,
                ((flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetReturnType : OBJECT),
                (flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT) : null);

        /* Select right MethodHandle invoker */
        String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";

        /* Invoke MethodHandle */
        mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
    } else {
        /* Figure out what opcode to use */
        int opCode = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ?
                ((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEINTERFACE : INVOKESTATIC)
                :
                ((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEVIRTUAL : INVOKESTATIC);

        /* Build descriptor & select target class */
        String targetDescriptor = convertDesc(targetParameters, targetReturnType, null);
        String targetName = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ? interfaceClass.getInternalName() : targetClass.getInternalName();

        /* Invoke method */
        adapter.visitMethodInsn(opCode, targetName, targetMethodName, targetDescriptor, (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0);
    }

    /* Return */
    handleReturn(adapter, interfaceMethod, targetReturnType);
    adapter.returnValue();

    /* End method */
    adapter.endMethod();
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:54,代碼來源:MethodGenerator.java


注:本文中的org.objectweb.asm.Type.getMethodDescriptor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。