List of usage examples for org.objectweb.asm Opcodes ACC_ABSTRACT
int ACC_ABSTRACT
To view the source code for org.objectweb.asm Opcodes ACC_ABSTRACT.
Click Source Link
From source file:com.google.devtools.build.android.desugar.InterfaceDesugaring.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor result;// ww w .jav a2s .c o m if (BitFlags.isSet(accessFlags, Opcodes.ACC_INTERFACE) && BitFlags.noneSet(access, Opcodes.ACC_ABSTRACT | Opcodes.ACC_BRIDGE) && !"<clinit>".equals(name)) { checkArgument(BitFlags.noneSet(access, Opcodes.ACC_NATIVE), "Forbidden per JLS ch 9.4"); boolean isLambdaBody = name.startsWith("lambda$") && BitFlags.isSet(access, Opcodes.ACC_SYNTHETIC); if (isLambdaBody) { access &= ~Opcodes.ACC_PUBLIC; // undo visibility change from LambdaDesugaring // Rename lambda method to reflect the new owner. Not doing so confuses LambdaDesugaring // if it's run over this class again. name += COMPANION_SUFFIX; } if (BitFlags.isSet(access, Opcodes.ACC_STATIC)) { // Completely move static interface methods, which requires rewriting call sites result = companion().visitMethod(access & ~Opcodes.ACC_PRIVATE, name, desc, signature, exceptions); } else { MethodVisitor abstractDest; if (isLambdaBody) { // Completely move lambda bodies, which requires rewriting call sites access &= ~Opcodes.ACC_PRIVATE; abstractDest = null; } else { // Make default methods abstract but move their implementation into a static method with // corresponding signature. Doesn't require callsite rewriting but implementing classes // may need to implement default methods explicitly. checkArgument(BitFlags.noneSet(access, Opcodes.ACC_PRIVATE), "Unexpected private interface method %s.%s : %s", name, internalName, desc); abstractDest = super.visitMethod(access | Opcodes.ACC_ABSTRACT, name, desc, signature, exceptions); } // TODO(b/37110951): adjust signature with explicit receiver type, which may be generic MethodVisitor codeDest = companion().visitMethod(access | Opcodes.ACC_STATIC, name, companionDefaultMethodDescriptor(internalName, desc), (String) null, // drop signature, since given one doesn't include the new param exceptions); result = abstractDest != null ? new MultiplexAnnotations(codeDest, abstractDest) : codeDest; } } else { result = super.visitMethod(access, name, desc, signature, exceptions); } return result != null ? new InterfaceInvocationRewriter(result) : null; }
From source file:com.google.devtools.build.android.desugar.Java7Compatibility.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { // Remove bridge default methods in interfaces; javac generates them again for implementing // classes anyways. if (isInterface && (access & (Opcodes.ACC_BRIDGE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC)) == Opcodes.ACC_BRIDGE) { return null; }//from w ww .j a v a 2 s . c o m if (isInterface && "$jacocoInit".equals(name) && BitFlags.isSet(access, Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC)) { // Drop static interface method that Jacoco generates--we'll inline it into the static // initializer instead return null; } // TODO(b/31547323): Avoid stack trace and report errors more user-friendly checkArgument(!isInterface || BitFlags.isSet(access, Opcodes.ACC_ABSTRACT) || "<clinit>".equals(name), "Interface %s defines non-abstract method %s%s, which is not supported", internalName, name, desc); MethodVisitor result = super.visitMethod(access, name, desc, signature, exceptions); return (isInterface && "<clinit>".equals(name)) ? new InlineJacocoInit(result) : result; }
From source file:com.google.devtools.build.android.desugar.LambdaClassFixer.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (name.equals("writeReplace") && BitFlags.noneSet(access, Opcodes.ACC_STATIC) && desc.equals("()Ljava/lang/Object;")) { // Lambda serialization hooks use java/lang/invoke/SerializedLambda, which isn't available on // Android. Since Jack doesn't do anything special for serializable lambdas we just drop these // serialization hooks. // https://docs.oracle.com/javase/8/docs/platform/serialization/spec/output.html#a5324 gives // details on the role and signature of this method. return null; }// w ww . j ava 2 s .c o m if (BitFlags.noneSet(access, Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC)) { // Keep track of instance methods implemented in this class for later. Since this visitor // is intended for lambda classes, no need to look at the superclass. implementedMethods.add(name + ":" + desc); } if (FACTORY_METHOD_NAME.equals(name)) { hasFactory = true; if (!lambdaInfo.needFactory()) { return null; // drop generated factory method if we won't call it } access &= ~Opcodes.ACC_PRIVATE; // make factory method accessible } else if ("<init>".equals(name)) { this.desc = desc; this.signature = signature; if (!lambdaInfo.needFactory() && !desc.startsWith("()")) { access &= ~Opcodes.ACC_PRIVATE; // make constructor accessible if we'll call it directly } } MethodVisitor methodVisitor = new LambdaClassMethodRewriter( super.visitMethod(access, name, desc, signature, exceptions)); if (!lambdaInfo.bridgeMethod().equals(lambdaInfo.methodReference())) { // Skip UseBridgeMethod unless we actually need it methodVisitor = new UseBridgeMethod(methodVisitor, lambdaInfo, access, name, desc, signature, exceptions); } if (!FACTORY_METHOD_NAME.equals(name) && !"<init>".equals(name)) { methodVisitor = new LambdaClassInvokeSpecialRewriter(methodVisitor); } return methodVisitor; }
From source file:com.google.devtools.build.wireless.testing.java.injector.coverage.CodeCoverageClassAdapter.java
License:Apache License
/** * Adds the method into the {@link CoverageStatisticContainer} and obtains * the index which will be injected. That index is used to create a new * instance of the method adapter used to inject the coverage behavior. * /*from w w w . j av a 2 s .c om*/ * <p>Abstract methods must be skipped, because they do not contains code and * the JVM will execute only their overriding implementation. If a method is * abstract {@code opcode} contains {@link Opcodes#ACC_ABSTRACT}. * * @param opcode The type associated with the method. * @param desc the method's descriptor. * @param signature the method's signature. May be null if the method * parameters, return type and exceptions do not use generic types. * @param exceptions The internal names of the method's exception classes. * May be null. * @return The method visitor which must be used to process the method. */ @Override public MethodVisitor visitMethod(int opcode, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(opcode, name, desc, signature, exceptions); if (isIncluded() && (opcode & Opcodes.ACC_ABSTRACT) == 0) { // TODO: idName should be an integer and not a string. String idName = owner + "." + name + desc; mv = new MethodCoverage(mv, statisticContainer.includeMethod(idName)); } return mv; }
From source file:com.google.devtools.build.wireless.testing.java.injector.coverage.CodeCoverageClassAdapterTest.java
License:Apache License
/** * Tests //from w w w .j av a 2s . co m * {@link CodeCoverageClassAdapter#visitMethod(int, String, String, String, String[])} * . * * <p> Tests that an abstract method would be skipped. */ public void testVisitMethod_skipAbstract() { String className = "Foo"; String methodName = "method"; String methodDesc = "()V"; int lines = 12345; classAdapter.visit(1, Opcodes.ACC_ABSTRACT, className, null, ClassNames.JAVA_LANG_OBJECT, null); MethodVisitor mv = classAdapter.visitMethod(Opcodes.ACC_ABSTRACT, methodName, methodDesc, null, null); assertFalse("Abstract method should not be visited by MethodCoverage", mv instanceof CodeCoverageClassAdapter.MethodCoverage); }
From source file:com.google.gwt.dev.javac.CompilationUnitTypeOracleUpdater.java
License:Apache License
private boolean isJava8InterfaceMethod(CollectMethodData method) { // (Normal) interface methods are abstract. Java 8 introduced the ability to declare default // methods and static methods both of which are exposed as non abstract methods. return (method.getAccess() & Opcodes.ACC_ABSTRACT) == 0; }
From source file:com.google.gwt.dev.shell.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
private void writeEmptyMethod(String mangledMethodName, Method declMethod) { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, mangledMethodName, declMethod.getDescriptor(), null, null); mv.visitEnd();/*from w w w . j av a 2 s . c o m*/ }
From source file:com.google.java.contract.core.agent.SpecificationClassAdapter.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); if ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) != 0) { return mv; }/*from ww w . j a v a 2 s. c om*/ return new SpecificationMethodAdapter(this, mv, access, name, desc); }
From source file:com.googlecode.ddom.weaver.ext.ModelExtensionClass.java
License:Apache License
public void accept(ClassVisitor classVisitor) { ImplementationInfo implementationInfo = info.getImplementation().get(ImplementationInfo.class); String name = Util.classNameToInternalName(info.getClassName()); String superName = Util.classNameToInternalName(info.getSuperClassName()); classVisitor.visit(Opcodes.V1_5,//from w w w .j av a2 s .c o m info.isAbstract() ? Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT : Opcodes.ACC_PUBLIC, name, null, superName, new String[] { Util.classNameToInternalName(info.getExtensionInterface().getClassInfo().getName()) }); for (ConstructorInfo constructor : implementationInfo.getConstructors()) { MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), constructor.getExceptions()); if (mv != null) { mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); Type[] argumentTypes = constructor.getArgumentTypes(); for (int i = 0; i < argumentTypes.length; i++) { mv.visitVarInsn(argumentTypes[i].getOpcode(Opcodes.ILOAD), i + 1); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", constructor.getDescriptor()); mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name + ";", null, l0, l1, 0); for (int i = 0; i < argumentTypes.length; i++) { mv.visitLocalVariable("arg" + i, argumentTypes[i].getDescriptor(), null, l0, l1, i + 1); } mv.visitMaxs(argumentTypes.length + 1, argumentTypes.length + 1); mv.visitEnd(); } } classVisitor.visitEnd(); }
From source file:com.googlecode.ddom.weaver.ext.ModelExtensionFactoryDelegateInterface.java
License:Apache License
public void accept(ClassVisitor classVisitor) { String factoryName = Util.classNameToInternalName(info.getFactoryDelegateInterfaceName()); // TODO: the reactor currently has an issue with interfaces classVisitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE, factoryName, null, "java/lang/Object", new String[0]); for (ConstructorInfo constructor : info.getConstructors()) { MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "create", constructor.getFactoryDelegateMethodDescriptor(), constructor.getSignature(), constructor.getExceptions()); if (mv != null) { mv.visitEnd();// ww w . j a v a2 s . c om } } classVisitor.visitEnd(); }