List of usage examples for org.objectweb.asm.commons Method getArgumentTypes
public Type[] getArgumentTypes()
From source file:co.cask.cdap.internal.asm.Signatures.java
License:Apache License
/** * Generates signature for the given method. * * @param method Method that needs signature to be generated * @param types List of {@link TypeToken} that matches with the number of arguments in the given method. * For a given method argument, if the coresponding {@link TypeToken} is non-null, it will be * used to generate the type parameter in the signature, otherwise, the one in the method will be used. * It's useful if the method is parameterized so that parameterize type information can be passed * through the type tokens. * @return A method signature string/*from www.j a va 2 s . co m*/ */ public static String getMethodSignature(Method method, TypeToken<?>... types) { SignatureWriter signWriter = new SignatureWriter(); Type[] argumentTypes = method.getArgumentTypes(); for (int i = 0; i < argumentTypes.length; i++) { SignatureVisitor sv = signWriter.visitParameterType(); if (types[i] != null) { visitTypeSignature(types[i], sv); } else { sv.visitClassType(argumentTypes[i].getInternalName()); sv.visitEnd(); } } signWriter.visitReturnType().visitBaseType('V'); return signWriter.toString(); }
From source file:co.cask.tigon.internal.asm.Signatures.java
License:Apache License
public static String getMethodSignature(Method method, TypeToken<?>[] types) { SignatureWriter signWriter = new SignatureWriter(); Type[] argumentTypes = method.getArgumentTypes(); for (int i = 0; i < argumentTypes.length; i++) { SignatureVisitor sv = signWriter.visitParameterType(); if (types[i] != null) { visitTypeSignature(types[i], sv); } else {/* w ww . j a va 2 s. c o m*/ sv.visitClassType(argumentTypes[i].getInternalName()); sv.visitEnd(); } } signWriter.visitReturnType().visitBaseType('V'); return signWriter.toString(); }
From source file:com.google.gwt.dev.shell.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
/** * For regular Java objects that implement a SingleJsoImpl interface, write * instance trampoline dispatchers for mangled method names to the * implementing method./* w ww. jav a2s . c o m*/ */ private void writeTrampoline(String stubIntr) { /* * This is almost the same kind of trampoline as the ones generated in * WriteJsoImpl, however there are enough small differences between the * semantics of the dispatches that would make a common implementation far * more awkward than the duplication of code. */ for (String mangledName : toImplement(stubIntr)) { for (Method method : jsoData.getDeclarations(mangledName)) { Method toCall = new Method(method.getName(), method.getDescriptor()); // Must not be final MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null); if (mv != null) { mv.visitCode(); /* * It just so happens that the stack and local variable sizes are the * same, but they're kept distinct to aid in clarity should the * dispatch logic change. * * These start at 1 because we need to load "this" onto the stack */ int var = 1; int size = 1; // load this mv.visitVarInsn(Opcodes.ALOAD, 0); // then the rest of the arguments for (Type t : toCall.getArgumentTypes()) { size += t.getSize(); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var); var += t.getSize(); } // Make sure there's enough room for the return value size = Math.max(size, toCall.getReturnType().getSize()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(), toCall.getDescriptor(), false); mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN)); mv.visitMaxs(size, var); mv.visitEnd(); } } } }
From source file:com.google.template.soy.jbcsrc.ConstructorRef.java
License:Apache License
/** * Returns a new {@link ConstructorRef} that refers to a constructor on the given type with the * given parameter types./*from w w w.ja va2 s. c o m*/ */ static ConstructorRef create(TypeInfo type, Method init) { checkArgument(init.getName().equals("<init>") && init.getReturnType().equals(Type.VOID_TYPE), "'%s' is not a valid constructor", init); return new AutoValue_ConstructorRef(type, init, ImmutableList.copyOf(init.getArgumentTypes())); }
From source file:com.google.template.soy.jbcsrc.MethodRef.java
License:Apache License
static MethodRef createInstanceMethod(TypeInfo owner, Method method) { return new AutoValue_MethodRef(Opcodes.INVOKEVIRTUAL, owner, method, method.getReturnType(), ImmutableList.<Type>builder().add(owner.type()).add(method.getArgumentTypes()).build(), Features.of());//from w w w .j a v a 2 s. c o m }
From source file:com.google.template.soy.jbcsrc.restricted.ConstructorRef.java
License:Apache License
/** * Returns a new {@link ConstructorRef} that refers to a constructor on the given type with the * given parameter types./*from w w w . j a v a 2 s . c om*/ */ public static ConstructorRef create(TypeInfo type, Method init) { checkArgument(init.getName().equals("<init>") && init.getReturnType().equals(Type.VOID_TYPE), "'%s' is not a valid constructor", init); return new AutoValue_ConstructorRef(type, init, ImmutableList.copyOf(init.getArgumentTypes())); }
From source file:com.google.template.soy.jbcsrc.restricted.MethodRef.java
License:Apache License
public static MethodRef createInstanceMethod(TypeInfo owner, Method method) { return new AutoValue_MethodRef(Opcodes.INVOKEVIRTUAL, owner, method, method.getReturnType(), ImmutableList.<Type>builder().add(owner.type()).add(method.getArgumentTypes()).build(), Features.of());/* w ww. j ava 2 s . com*/ }
From source file:com.google.template.soy.jbcsrc.restricted.MethodRef.java
License:Apache License
public static MethodRef createStaticMethod(TypeInfo owner, Method method) { return new AutoValue_MethodRef(Opcodes.INVOKESTATIC, owner, method, method.getReturnType(), ImmutableList.<Type>builder().add(method.getArgumentTypes()).build(), Features.of()); }
From source file:com.google.template.soy.jbcsrc.TemplateVariableManager.java
License:Apache License
/** * @param owner The type that is the owner of the method being generated * @param thisVar An expression returning the current 'this' reference * @param method The method being generated * @param fieldNames The field name set for the current class. *//*from w w w. j av a 2 s . com*/ TemplateVariableManager(UniqueNameGenerator fieldNames, TypeInfo owner, LocalVariable thisVar, Method method) { this.fieldNames = fieldNames; this.fieldNames.claimName(CURRENT_CALLEE_FIELD); this.fieldNames.claimName(CURRENT_RENDEREE_FIELD); this.fieldNames.claimName(TEMP_BUFFER_FIELD); this.fieldNames.claimName(MSG_PLACEHOLDER_MAP_FIELD); this.owner = owner; this.thisVar = thisVar; availableSlots.set(0); // for 'this' int from = 1; for (Type type : method.getArgumentTypes()) { int to = from + type.getSize(); availableSlots.set(from, to); from = to; } }
From source file:com.google.template.soy.jbcsrc.VariableSet.java
License:Apache License
/** * @param owner The type that is the owner of the method being generated * @param thisVar An expression returning the current 'this' reference * @param method The method being generated * @param fieldNames The field name set for the current class. *///from w w w .j a v a2s.c om VariableSet(UniqueNameGenerator fieldNames, TypeInfo owner, LocalVariable thisVar, Method method) { this.fieldNames = fieldNames; this.fieldNames.claimName(CURRENT_CALLEE_FIELD); this.fieldNames.claimName(CURRENT_RENDEREE_FIELD); this.fieldNames.claimName(TEMP_BUFFER_FIELD); this.fieldNames.claimName(MSG_PLACEHOLDER_MAP_FIELD); this.owner = owner; this.thisVar = thisVar; availableSlots.set(0); // for 'this' int from = 1; for (Type type : method.getArgumentTypes()) { int to = from + type.getSize(); availableSlots.set(from, to); from = to; } }