List of usage examples for org.objectweb.asm Opcodes ASM5
int ASM5
To view the source code for org.objectweb.asm Opcodes ASM5.
Click Source Link
From source file:com.google.devtools.build.android.desugar.DesugarObjectsRequireNonNullTest.java
License:Open Source License
@Test public void testClassCallingRequireNonNullHasNoReferenceToRequiresNonNull() { try {/* w w w . j a v a 2s . c o m*/ ClassReader reader = new ClassReader(ClassCallingRequireNonNull.class.getName()); AtomicInteger counterForSingleArgument = new AtomicInteger(0); AtomicInteger counterForString = new AtomicInteger(0); AtomicInteger counterForSupplier = new AtomicInteger(0); reader.accept(new ClassVisitor(Opcodes.ASM5) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new MethodVisitor(api) { @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if (opcode == INVOKESTATIC && owner.equals("java/util/Objects") && name.equals("requireNonNull")) { switch (desc) { case "(Ljava/lang/Object;)Ljava/lang/Object;": counterForSingleArgument.incrementAndGet(); break; case "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;": counterForString.incrementAndGet(); break; case "(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;": counterForSupplier.incrementAndGet(); break; default: fail("Unknown overloaded requireNonNull is found: " + desc); } } } }; } }, 0); assertThat(counterForSingleArgument.get()).isEqualTo(0); // we do not desugar requireNonNull(Object, String) or requireNonNull(Object, Supplier) assertThat(counterForString.get()).isEqualTo(1); assertThat(counterForSupplier.get()).isEqualTo(1); } catch (IOException e) { fail(); } }
From source file:com.google.devtools.build.android.desugar.InterfaceDesugaring.java
License:Open Source License
public InterfaceDesugaring(ClassVisitor dest, ClassReaderFactory bootclasspath, GeneratedClassStore store) { super(Opcodes.ASM5, dest); this.bootclasspath = bootclasspath; this.store = store; }
From source file:com.google.devtools.build.android.desugar.InvokeDynamicLambdaMethodCollector.java
License:Open Source License
public InvokeDynamicLambdaMethodCollector() { super(Opcodes.ASM5); }
From source file:com.google.devtools.build.android.desugar.Java7Compatibility.java
License:Open Source License
public Java7Compatibility(ClassVisitor cv, ClassReaderFactory factory) { super(Opcodes.ASM5, cv); this.factory = factory; }
From source file:com.google.devtools.build.android.desugar.LambdaClassFixer.java
License:Open Source License
public LambdaClassFixer(ClassVisitor dest, LambdaInfo lambdaInfo, ClassReaderFactory factory, ImmutableSet<String> interfaceLambdaMethods, boolean allowDefaultMethods) { super(Opcodes.ASM5, dest); this.lambdaInfo = lambdaInfo; this.factory = factory; this.interfaceLambdaMethods = interfaceLambdaMethods; this.allowDefaultMethods = allowDefaultMethods; }
From source file:com.google.devtools.build.android.desugar.LambdaDesugaring.java
License:Open Source License
public LambdaDesugaring(ClassVisitor dest, ClassLoader targetLoader, LambdaClassMaker lambdas, ImmutableSet.Builder<String> aggregateInterfaceLambdaMethods, boolean allowDefaultMethods) { super(Opcodes.ASM5, dest); this.targetLoader = targetLoader; this.lambdas = lambdas; this.aggregateInterfaceLambdaMethods = aggregateInterfaceLambdaMethods; this.allowDefaultMethods = allowDefaultMethods; }
From source file:com.google.devtools.build.android.desugar.TryWithResourcesRewriterTest.java
License:Open Source License
/** Check whether java.lang.AutoCloseable is used as arguments of any method. */ private static boolean hasAutoCloseable(byte[] classContent) { ClassReader reader = new ClassReader(classContent); final AtomicInteger counter = new AtomicInteger(); ClassVisitor visitor = new ClassVisitor(Opcodes.ASM5) { @Override/*ww w . j a va2 s . c om*/ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { for (Type argumentType : Type.getArgumentTypes(desc)) { if ("Ljava/lang/AutoCloseable;".equals(argumentType.getDescriptor())) { counter.incrementAndGet(); } } return null; } }; reader.accept(visitor, 0); return counter.get() > 0; }
From source file:com.google.devtools.j2objc.gen.TypeGenerator.java
License:Apache License
private boolean areParametersNonnullByDefault() { if (BindingUtil.hasAnnotation(typeBinding, ParametersAreNonnullByDefault.class)) { return true; }//from w w w . j a v a2 s . c om IPackageBinding pkg = typeBinding.getPackage(); try { // See if a package-info source file has a ParametersAreNonnullByDefault annotation. InputFile file = FileUtil.findOnSourcePath(pkg.getName() + ".package-info"); if (file != null) { String pkgInfo = FileUtil.readFile(file); if (pkgInfo.indexOf("@ParametersAreNonnullByDefault") >= 0) { return true; } if (pkgInfo.indexOf("@javax.annotation.ParametersAreNonnullByDefault") >= 0) { return true; } } // See if the package-info class file has it. final boolean[] result = new boolean[1]; file = FileUtil.findOnClassPath(pkg.getName() + ".package-info"); if (file != null) { ClassReader classReader = new ClassReader(file.getInputStream()); classReader.accept(new ClassVisitor(Opcodes.ASM5) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (desc.equals("Ljavax/annotation/ParametersAreNonnullByDefault;")) { result[0] = true; } return null; } }, 0); return result[0]; } } catch (IOException e) { // fall-through } return false; }
From source file:com.google.devtools.j2objc.util.PackageInfoLookup.java
License:Apache License
private PackageData parseDataFromClassFile(InputFile file) throws IOException { PackageDataBuilder builder = new PackageDataBuilder(); ClassReader classReader = new ClassReader(file.getInputStream()); classReader.accept(new ClassVisitor(Opcodes.ASM5) { @Override//ww w. jav a 2 s. co m public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (desc.equals("Lcom/google/j2objc/annotations/ObjectiveCName;")) { return new AnnotationVisitor(Opcodes.ASM5) { @Override public void visit(String name, Object value) { if (name.equals("value")) { builder.setObjectiveCName(value.toString()); } } }; } else if (desc.equals("Ljavax/annotation/ParametersAreNonnullByDefault;")) { builder.setParametersAreNonnullByDefault(); } else if (desc.equals("Lcom/google/j2objc/annotations/ReflectionSupport;")) { return new AnnotationVisitor(Opcodes.ASM5) { @Override public void visitEnum(String name, String desc, String value) { if (desc.equals("Lcom/google/j2objc/annotations/ReflectionSupport$Level;") && name.equals("value")) { builder.setReflectionSupportLevel(ReflectionSupport.Level.valueOf(value)); } } }; } return null; } }, 0); return builder.build(); }
From source file:com.google.devtools.j2objc.util.PackagePrefixes.java
License:Apache License
/** * Check if there is a package-info class with a prefix annotation. *//*from w w w . java 2 s.c om*/ private String getPrefixFromPackageInfoClass(String packageName) { final String[] result = new String[1]; try { InputFile file = FileUtil.findOnClassPath(packageName + ".package-info"); if (file != null) { ClassReader classReader = new ClassReader(file.getInputStream()); classReader.accept(new ClassVisitor(Opcodes.ASM5) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (!desc.equals("Lcom/google/j2objc/annotations/ObjectiveCName;")) { return null; } return new AnnotationVisitor(Opcodes.ASM5) { @Override public void visit(String name, Object value) { if (name.equals("value")) { result[0] = value.toString(); } } }; } }, 0); } } catch (IOException e) { // Continue, as there's no package-info to check. } return result[0]; }