List of usage examples for org.objectweb.asm Opcodes INVOKEINTERFACE
int INVOKEINTERFACE
To view the source code for org.objectweb.asm Opcodes INVOKEINTERFACE.
Click Source Link
From source file:com.google.devtools.build.android.desugar.CoreLibrarySupportTest.java
License:Open Source License
/** * Tests that call sites of renamed core libraries are treated like call sites in regular * {@link InterfaceDesugaring}./* www . ja va2 s. co m*/ */ @Test public void testGetCoreInterfaceRewritingTarget_renamed() throws Exception { CoreLibrarySupport support = new CoreLibrarySupport(new CoreLibraryRewriter(""), Thread.currentThread().getContextClassLoader(), ImmutableList.of("java/util/"), ImmutableList.of(), ImmutableList.of(), ImmutableList.of()); // regular invocations of default methods: ignored assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEINTERFACE, "java/util/Collection", "removeIf", "(Ljava/util/function/Predicate;)Z", true)).isNull(); assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEVIRTUAL, "java/util/ArrayList", "removeIf", "(Ljava/util/function/Predicate;)Z", false)).isNull(); // abstract methods: ignored assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I", true)).isNull(); // static interface method assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKESTATIC, "java/util/Comparator", "reverseOrder", "()Ljava/util/Comparator;", true)).isEqualTo(Comparator.class); // invokespecial for default methods: find nearest definition assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKESPECIAL, "java/util/List", "removeIf", "(Ljava/util/function/Predicate;)Z", true)).isEqualTo(Collection.class); // invokespecial on a class: ignore (even if there's an inherited default method) assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "removeIf", "(Ljava/util/function/Predicate;)Z", false)).isNull(); }
From source file:com.google.devtools.build.android.desugar.CoreLibrarySupportTest.java
License:Open Source License
@Test public void testGetCoreInterfaceRewritingTarget_ignoreRenamedInvokeInterface() throws Exception { CoreLibrarySupport support = new CoreLibrarySupport(new CoreLibraryRewriter(""), Thread.currentThread().getContextClassLoader(), ImmutableList.of("java/util/concurrent/"), // should return null for these ImmutableList.of("java/util/Map"), ImmutableList.of(), ImmutableList.of()); assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEINTERFACE, "java/util/Map", "getOrDefault", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true)).isEqualTo(Map.class); assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEINTERFACE, "java/util/concurrent/ConcurrentMap", "getOrDefault", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true)).isNull(); }
From source file:com.google.devtools.build.android.desugar.CoreLibrarySupportTest.java
License:Open Source License
@Test public void testGetCoreInterfaceRewritingTarget_excludedMethodIgnored() throws Exception { CoreLibrarySupport support = new CoreLibrarySupport(new CoreLibraryRewriter(""), Thread.currentThread().getContextClassLoader(), ImmutableList.of(), ImmutableList.of("java/util/Collection"), ImmutableList.of(), ImmutableList.of("java/util/Collection#removeIf")); assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEINTERFACE, "java/util/List", "removeIf", "(Ljava/util/function/Predicate;)Z", true)).isNull(); assertThat(support.getCoreInterfaceRewritingTarget(Opcodes.INVOKEVIRTUAL, "java/util/ArrayList", "removeIf", "(Ljava/util/function/Predicate;)Z", false)).isNull(); }
From source file:com.google.devtools.build.android.desugar.LambdaDesugaring.java
License:Open Source License
static int invokeOpcode(Handle invokedMethod) { switch (invokedMethod.getTag()) { case Opcodes.H_INVOKESTATIC: return Opcodes.INVOKESTATIC; case Opcodes.H_INVOKEVIRTUAL: return Opcodes.INVOKEVIRTUAL; case Opcodes.H_INVOKESPECIAL: case Opcodes.H_NEWINVOKESPECIAL: // Must be preceded by NEW return Opcodes.INVOKESPECIAL; case Opcodes.H_INVOKEINTERFACE: return Opcodes.INVOKEINTERFACE; default:/*from w ww. j ava 2 s. c om*/ throw new UnsupportedOperationException("Don't know how to call " + invokedMethod); } }
From source file:com.google.gwtorm.schema.sql.SqlTypeInfo.java
License:Apache License
public void generatePreparedStatementNull(final CodeGenSupport cgs) { cgs.pushSqlHandle();//ww w . ja v a 2 s.com cgs.pushColumnIndex(); cgs.push(getSqlTypeConstant()); cgs.mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(PreparedStatement.class), "setNull", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE })); }
From source file:com.google.template.soy.jbcsrc.MethodRef.java
License:Apache License
static MethodRef create(java.lang.reflect.Method method) { Class<?> clazz = method.getDeclaringClass(); TypeInfo ownerType = TypeInfo.create(method.getDeclaringClass()); boolean isStatic = Modifier.isStatic(method.getModifiers()); ImmutableList<Type> argTypes; if (isStatic) { argTypes = ImmutableList.copyOf(Type.getArgumentTypes(method)); } else {/*w w w . ja v a2 s. c o m*/ // for instance methods the first 'argument' is always an instance of the class. argTypes = ImmutableList.<Type>builder().add(ownerType.type()).add(Type.getArgumentTypes(method)) .build(); } return new AutoValue_MethodRef( clazz.isInterface() ? Opcodes.INVOKEINTERFACE : isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, ownerType, org.objectweb.asm.commons.Method.getMethod(method), Type.getType(method.getReturnType()), argTypes, Features.of()); }
From source file:com.google.template.soy.jbcsrc.MethodRef.java
License:Apache License
/** * Writes an invoke instruction for this method to the given adapter. Useful when the expression * is not useful for representing operations. For example, explicit dup operations are awkward * in the Expression api. /*ww w . ja v a 2s.c om*/ */ void invokeUnchecked(CodeBuilder mv) { mv.visitMethodInsn(opcode(), owner().internalName(), method().getName(), method().getDescriptor(), // This is for whether the methods owner is an interface. This is mostly to handle java8 // default methods on interfaces. We don't care about those currently, but ASM requires // this. opcode() == Opcodes.INVOKEINTERFACE); }
From source file:com.google.template.soy.jbcsrc.restricted.MethodRef.java
License:Apache License
public static MethodRef create(java.lang.reflect.Method method) { Class<?> clazz = method.getDeclaringClass(); TypeInfo ownerType = TypeInfo.create(method.getDeclaringClass()); boolean isStatic = Modifier.isStatic(method.getModifiers()); ImmutableList<Type> argTypes; if (isStatic) { argTypes = ImmutableList.copyOf(Type.getArgumentTypes(method)); } else {/*ww w . j ava 2 s. c o m*/ // for instance methods the first 'argument' is always an instance of the class. argTypes = ImmutableList.<Type>builder().add(ownerType.type()).add(Type.getArgumentTypes(method)) .build(); } return new AutoValue_MethodRef( clazz.isInterface() ? Opcodes.INVOKEINTERFACE : isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, ownerType, Method.getMethod(method), Type.getType(method.getReturnType()), argTypes, Features.of()); }
From source file:com.google.template.soy.jbcsrc.restricted.MethodRef.java
License:Apache License
/** * Writes an invoke instruction for this method to the given adapter. Useful when the expression * is not useful for representing operations. For example, explicit dup operations are awkward in * the Expression api./*w w w. ja va 2 s . c o m*/ */ public void invokeUnchecked(CodeBuilder cb) { cb.visitMethodInsn(opcode(), owner().internalName(), method().getName(), method().getDescriptor(), // This is for whether the methods owner is an interface. This is mostly to handle java8 // default methods on interfaces. We don't care about those currently, but ASM requires // this. opcode() == Opcodes.INVOKEINTERFACE); }
From source file:com.googlecode.ddom.weaver.compound.CompoundClassGenerator.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, name, desc, signature, exceptions); if (mv != null) { Type[] argumentTypes = Type.getArgumentTypes(desc); mv.visitCode();// w w w .ja v a 2 s .c o m Label l0 = new Label(); mv.visitLabel(l0); for (int i = 0; i < componentClasses.length; i++) { String componentClass = Util.classNameToInternalName(componentClasses[i]); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "c" + i, "L" + componentClass + ";"); for (int j = 0; j < argumentTypes.length; j++) { mv.visitVarInsn(argumentTypes[j].getOpcode(Opcodes.ILOAD), j + 1); } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ifaceName, name, desc); } mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0); mv.visitMaxs(argumentTypes.length + 1, argumentTypes.length + 1); mv.visitEnd(); } return null; }