public Signature(String name, Type returnType, Type[] argumentTypes) { this(name, Type.getMethodDescriptor(returnType, argumentTypes)); }
public Signature(String name, Type returnType, Type[] argumentTypes) { this(name, Type.getMethodDescriptor(returnType, argumentTypes)); }
/** * Returns the method {@link Type} corresponding to the given method. * * @param method a {@link Method} object. * @return the method {@link Type} corresponding to the given method. */ public static Type getType(final Method method) { return getType(getMethodDescriptor(method)); }
/** * Returns the method {@link Type} corresponding to the given argument and return types. * * @param returnType the return type of the method. * @param argumentTypes the argument types of the method. * @return the method {@link Type} corresponding to the given argument and return types. */ public static Type getMethodType(final Type returnType, final Type... argumentTypes) { return getType(getMethodDescriptor(returnType, argumentTypes)); }
private static String methodDescriptor(Class<?> returnType, Class<?>... parameterTypes) { Type[] argumentTypes = new Type[parameterTypes.length]; int typeIndex = 0; for (Class<?> parameterType : parameterTypes) { argumentTypes[typeIndex++] = Type.getType(parameterType); } return Type.getMethodDescriptor(Type.getType(returnType), argumentTypes); } }
@Override protected void writeCallToInitializing(MutableClass mutableClass, RobolectricGeneratorAdapter generator) { generator.invokeDynamic("initializing", Type.getMethodDescriptor(OBJECT_TYPE, mutableClass.classType), BOOTSTRAP_INIT); }
public static Method[] findMethods(String[] namesAndDescriptors, Method[] methods) { Map map = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; map.put(method.getName() + Type.getMethodDescriptor(method), method); } Method[] result = new Method[namesAndDescriptors.length / 2]; for (int i = 0; i < result.length; i++) { result[i] = (Method)map.get(namesAndDescriptors[i * 2] + namesAndDescriptors[i * 2 + 1]); if (result[i] == null) { // TODO: error? } } return result; } }
public static Method[] findMethods(String[] namesAndDescriptors, Method[] methods) { Map map = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; map.put(method.getName() + Type.getMethodDescriptor(method), method); } Method[] result = new Method[namesAndDescriptors.length / 2]; for (int i = 0; i < result.length; i++) { result[i] = (Method)map.get(namesAndDescriptors[i * 2] + namesAndDescriptors[i * 2 + 1]); if (result[i] == null) { // TODO: error? } } return result; } }
private static int helper(FastClass fc, Method method) { int index = fc.getIndex(new Signature(method.getName(), Type.getMethodDescriptor(method))); if (index < 0) { Class[] types = method.getParameterTypes(); System.err.println("hash=" + method.getName().hashCode() + " size=" + types.length); for (int i = 0; i < types.length; i++) { System.err.println(" types[" + i + "]=" + types[i].getName()); } throw new IllegalArgumentException("Cannot find method " + method); } return index; }
public static Signature getSignature(Member member) { if (member instanceof Method) { return new Signature(member.getName(), Type.getMethodDescriptor((Method)member)); } else if (member instanceof Constructor) { Type[] types = TypeUtils.getTypes(((Constructor)member).getParameterTypes()); return new Signature(Constants.CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, types)); } else { throw new IllegalArgumentException("Cannot get signature of a field"); } }
private static int helper(FastClass fc, Method method) { int index = fc.getIndex(new Signature(method.getName(), Type.getMethodDescriptor(method))); if (index < 0) { Class[] types = method.getParameterTypes(); System.err.println("hash=" + method.getName().hashCode() + " size=" + types.length); for (int i = 0; i < types.length; i++) { System.err.println(" types[" + i + "]=" + types[i].getName()); } throw new IllegalArgumentException("Cannot find method " + method); } return index; }
protected MtdInfo findTargetMethod0(Map<MtdInfo, MtdInfo> map, String owner, String name, String desc) { MtdInfo v = map.get(buildKey(owner, name, desc)); if (v != null) { return v; } // try with default ret key.desc = Type.getMethodDescriptor(Type.getType(DEFAULT_RET_TYPE), Type.getArgumentTypes(desc)); v = map.get(key); if (v != null) { return v; } // try with default desc key.desc = DEFAULT_DESC; v = map.get(key); if (v != null) { return v; } if (!name.equals("*")) { return findTargetMethod0(map, owner, "*", desc); } return v; }
public static Signature getSignature(Member member) { if (member instanceof Method) { return new Signature(member.getName(), Type.getMethodDescriptor((Method)member)); } else if (member instanceof Constructor) { Type[] types = TypeUtils.getTypes(((Constructor)member).getParameterTypes()); return new Signature(Constants.CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, types)); } else { throw new IllegalArgumentException("Cannot get signature of a field"); } }
private MtdInfo newMethodA(int opcode, MtdInfo t, MtdInfo mapTo) { MtdInfo n = toCreate.get(t); if (n != null) { return n; } n = new MtdInfo(); n.owner = t.owner; n.name = buildMethodAName(t.name); boolean hasThis = opcode != INVOKESTATIC; if (hasThis) { Type[] args = Type.getArgumentTypes(t.desc); Type ret = Type.getReturnType(t.desc); List<Type> ts = new ArrayList<>(args.length + 1); ts.add(Type.getType(t.owner)); ts.addAll(Arrays.asList(args)); n.desc = Type.getMethodDescriptor(ret, ts.toArray(new Type[ts.size()])); } else { n.desc = t.desc; } toCreate.put(t, n); MethodVisitor mv = cv.visitMethod(ACC_SYNTHETIC | ACC_PRIVATE | ACC_STATIC, n.name, n.desc, null, null); mv.visitCode(); genMethodACode(opcode, t, mapTo, mv, t); return n; }
private void generateMethods(ClassWriter cw, String internalName, List<Method> methods, Class<?> exceptionType) { for (Method method: methods) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null); mv.visitCode();
case Type.LONG: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Long.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Long.class), "longValue", Type.getMethodDescriptor(Type.LONG_TYPE), false)); break; case Type.FLOAT: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Float.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Float.class), "floatValue", Type.getMethodDescriptor(Type.FLOAT_TYPE), false)); break; case Type.DOUBLE: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Double.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Double.class), "doubleValue", Type.getMethodDescriptor(Type.DOUBLE_TYPE), false)); break; case Type.BOOLEAN: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Boolean.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Boolean.class), "booleanValue", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false)); break; case Type.INT: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Integer.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Integer.class), "intValue", Type.getMethodDescriptor(Type.INT_TYPE), false)); break; case Type.SHORT: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Short.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Short.class), "shortValue", Type.getMethodDescriptor(Type.SHORT_TYPE), false)); break; case Type.BYTE: instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(Byte.class))); instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Byte.class), "byteValue", Type.getMethodDescriptor(Type.BYTE_TYPE), false)); break; default:
void writeSysCall(String internalClassName, int INVOKE_TYPE, String method, Class returnClazz, Class... paramClasses) { Type[] args = new Type[paramClasses.length]; if (INVOKE_TYPE == INVOKEVIRTUAL || INVOKE_TYPE == INVOKEINTERFACE) stackPop(); // this for (int i = 0; i < args.length; i++) { args[i] = Type.getType(paramClasses[i]); stackPop(); } code.add(new MethodInsnNode( INVOKE_TYPE, internalClassName, method, Type.getMethodDescriptor(Type.getType(returnClazz), args), false )); if (returnClazz != void.class) { stackPush(null, StackItem.Type.valueOf(returnClazz)); } }
@SuppressWarnings("unchecked") void writeSysCall(Class clazz, int INVOKE_TYPE, String method, Class returnClazz, Class... paramClasses) { if (INVOKE_TYPE != INVOKESPECIAL && clazz != null) { if (compiler.getScope().isDebugMode()) { if (!methodExists(clazz, method, paramClasses)) { throw new NoSuchMethodException(clazz, method, paramClasses); } } } Type[] args = new Type[paramClasses.length]; if (INVOKE_TYPE == INVOKEVIRTUAL || INVOKE_TYPE == INVOKEINTERFACE) stackPop(); // this for (int i = 0; i < args.length; i++) { args[i] = Type.getType(paramClasses[i]); stackPop(); } String owner = clazz == null ? this.method.clazz.node.name : Type.getInternalName(clazz); if (clazz == null && this.method.clazz.entity.isTrait()) throw new CriticalException("[Compiler Error] Cannot use current classname in Trait"); code.add(new MethodInsnNode( INVOKE_TYPE, owner, method, Type.getMethodDescriptor(Type.getType(returnClazz), args), clazz != null && clazz.isInterface() )); if (returnClazz != void.class) { stackPush(null, StackItem.Type.valueOf(returnClazz)); } }
protected void writeInterfaceMethod(MethodEntity method) { MethodNode node = new MethodNodeImpl(); node.access = ACC_PUBLIC; node.name = method.getName(); node.desc = Type.getMethodDescriptor( Type.getType(Memory.class), Type.getType(Environment.class), Type.getType(Memory[].class) ); MethodStmtCompiler methodCompiler = new MethodStmtCompiler(this, node); ExpressionStmtCompiler expressionCompiler = new ExpressionStmtCompiler(methodCompiler, null); methodCompiler.writeHeader(); LabelNode l0 = writeLabel(node, statement.getMeta().getStartLine()); methodCompiler.addLocalVariable("~this", l0); methodCompiler.addLocalVariable("~env", l0); methodCompiler.addLocalVariable("~args", l0); expressionCompiler.writeVarLoad("~this"); expressionCompiler.writeVarLoad("~env"); expressionCompiler.writeVarLoad("~args"); String internalName = entity.findMethod(method.getLowerName()).getInternalName(); expressionCompiler.writeSysDynamicCall(null, internalName, Memory.class, Environment.class, Memory[].class); node.instructions.add(new InsnNode(ARETURN)); methodCompiler.writeFooter(); this.node.methods.add(node); }
destructor.name = "finalize"; destructor.access = ACC_PUBLIC; destructor.desc = Type.getMethodDescriptor(Type.getType(void.class));