List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:com.google.devtools.build.wireless.testing.java.injector.coverage.CodeCoverageClassAdapterTest.java
License:Apache License
/** * Tests//from ww w. j a v a 2s . com * {@link CodeCoverageClassAdapter#visitSource(String, String)} * . * * <p>Verifies: * <ul> * <li>that source file would be collected correctly. * <li>that duplicated source file would be collected only once. * <li>that file with the same name but in different packages would be * considered as different files. * </ul> * In case of failure the problems is probably located in the class adapter or * in the statistic container. */ public void testVisitSource() { String[] inclusion = new String[] { "+com" }; classAdapter = new CodeCoverageClassAdapter(new EmptyVisitor(), statisticContainer, inclusion, CoverageMode.SUMMARY); int currentSize = 0; for (int i = 0; i < MAX; i++) { classAdapter.visit(1, Opcodes.ACC_PUBLIC, "com/" + i, null, ClassNames.JAVA_LANG_OBJECT, null); classAdapter.visitSource(i + ".java", null); assertEquals("Number of source files.", i + 1, statisticContainer.getSourceFileCount()); } currentSize = statisticContainer.getSourceFileCount(); for (int i = 0; i < MAX; i++) { classAdapter.visit(1, Opcodes.ACC_PUBLIC, "com/Dummy" + i, null, ClassNames.JAVA_LANG_OBJECT, null); classAdapter.visitSource("Dummy.java", null); assertEquals("Duplicated source files.", currentSize + 1, statisticContainer.getSourceFileCount()); } currentSize = statisticContainer.getSourceFileCount(); for (int i = 0; i < MAX; i++) { classAdapter.visit(1, Opcodes.ACC_PUBLIC, "com/foo" + i + "/Dummy", null, ClassNames.JAVA_LANG_OBJECT, null); // TODO: this will never happen. The filename is relative to the path classAdapter.visitSource("com/foo" + i + "/Dummy.java", null); assertEquals("Package handling in source files counting.", currentSize + i + 1, statisticContainer.getSourceFileCount()); } }
From source file:com.google.devtools.build.wireless.testing.java.injector.StackServantTest.java
License:Apache License
/** * Initializes a new StackServant with a given description and checks if * the return type is correct.//from ww w .j a v a 2s.c o m * * @param type The given return type. */ private void assertReturnType(String type) { StackServant servant = new StackServant(null, Opcodes.ACC_PUBLIC, "()" + type); assertEquals("Wrong return type", type, servant.getReturnType()); }
From source file:com.google.devtools.build.wireless.testing.java.injector.WrapperClassAdapterTest.java
License:Apache License
/** * Tests //from w ww .j a v a 2s . c om * {@link WrapperClassAdapter#visitMethod(int, String, String, String, String[])} * . * * <p>This tests verifies that constructors of wrapped types are wrapped * with invocations to the related constructor of the wrapper. */ public void testWrappingConstructor() { MethodVisitor mv = wrapper.visitMethod(Opcodes.ACC_PUBLIC, "Method", "()V", null, null); assertTrue("Wrong MethodVisitor.", mv instanceof WrapperMethodAdapter); for (String key : classMap.keySet()) { mv.visitMethodInsn(Opcodes.ACC_PUBLIC, key, "<init>", "()V"); assertEquals("The given classname should have been wrapped", classMap.get(key), spyVisitor.ownerClassName); } mv.visitMethodInsn(Opcodes.ACC_PUBLIC, fakeKey, "<init>", "()V"); assertEquals("The given classname should NOT have been wrapped", fakeKey, spyVisitor.ownerClassName); }
From source file:com.google.devtools.build.wireless.testing.java.injector.WrapperClassAdapterTest.java
License:Apache License
/** * Tests /*from w w w . j a v a 2 s . c om*/ * {@link WrapperClassAdapter#visitMethod(int, String, String, String, String[])} * . * * <p>This test checks that the operator new has been invoked on the wrapped * type when necessary. */ public void testWrappingOperatorNew() { MethodVisitor mv = wrapper.visitMethod(Opcodes.ACC_PUBLIC, "Method", "()V", null, null); assertTrue("Wrong MethodVisitor.", mv instanceof WrapperMethodAdapter); for (String key : classMap.keySet()) { mv.visitTypeInsn(Opcodes.NEW, key); assertEquals("The given classname should have been wrapped", classMap.get(key), spyVisitor.ownerClassName); } mv.visitTypeInsn(Opcodes.NEW, fakeKey); assertEquals("The given classname should NOT have been wrapped", fakeKey, spyVisitor.ownerClassName); }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testOne() { CollectClassData cd = collect(One.class); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Nested, cd.getClassType()); assertEquals(0, cd.getFields().size()); assertEquals(0, cd.getInterfaceInternalNames().length); assertEquals(0, cd.getAnnotations().size()); assertEquals("com/google/gwt/dev/javac/asmbridge/EmptyVisitor", cd.getSuperInternalName()); assertEquals("CollectClassDataTest.One", cd.getNestedSourceName()); List<CollectMethodData> methods = cd.getMethods(); assertEquals(2, methods.size());/*from w w w. java2s . c om*/ // TODO(jat): Is it safe to assume the implicit constructor is always first? CollectMethodData method = methods.get(0); Type[] argTypes = method.getArgTypes(); String[] argNames = method.getArgNames(); assertEquals("<init>", method.getName()); assertEquals(0, argTypes.length); assertEquals(0, argNames.length); assertEquals(0, method.getArgAnnotations().length); assertEquals(0, method.getAnnotations().size()); assertEquals(0, method.getExceptions().length); method = methods.get(1); argTypes = method.getArgTypes(); argNames = method.getArgNames(); assertEquals("visitAnnotation", method.getName()); assertEquals(2, argTypes.length); assertEquals("java.lang.String", argTypes[0].getClassName()); assertEquals("boolean", argTypes[1].getClassName()); assertEquals(2, argNames.length); assertEquals("desc", argNames[0]); assertEquals("visible", argNames[1]); assertEquals(2, method.getArgAnnotations().length); assertEquals(0, method.getArgAnnotations()[0].size()); assertEquals(0, method.getArgAnnotations()[1].size()); // Note that @Override is a source-only annotation assertEquals(0, method.getAnnotations().size()); assertEquals(0, method.getExceptions().length); }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testTopLevel() { CollectClassData cd = collect(CollectClassDataTest.class); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(Opcodes.ACC_PUBLIC, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.TopLevel, cd.getClassType()); assertEquals("CollectClassDataTest", cd.getNestedSourceName()); }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testTwoInner() { CollectClassData cd = collect(Two.TwoInner.class); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(Opcodes.ACC_PUBLIC, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Inner, cd.getClassType()); assertEquals("CollectClassDataTest.Two.TwoInner", cd.getNestedSourceName()); }
From source file:com.google.gwt.dev.javac.asm.ResolveGenericsTest.java
License:Apache License
private void resolveMethodSignature(JMethod method, String signature) { TypeParameterLookup lookup = new TypeParameterLookup(); lookup.pushEnclosingScopes(method.getEnclosingType()); lookup.pushScope(method.getTypeParameters()); int access = Opcodes.ACC_PUBLIC; Method reflectionMethod = reflectionMethods.get(method); String desc = Type.getMethodDescriptor(reflectionMethod); CollectMethodData methodData = new CollectMethodData(ClassType.TopLevel, access, method.getName(), desc, signature, null);//www .j a va 2 s . co m Class<?>[] paramTypes = reflectionMethod.getParameterTypes(); int n = paramTypes.length; Type[] argTypes = new Type[n]; String[] argNames = new String[n]; for (int i = 0; i < n; ++i) { argNames[i] = "arg" + i; argTypes[i] = Type.getType(paramTypes[i]); } ResolveMethodSignature methodResolver = new ResolveMethodSignature(resolver, failTreeLogger, method, lookup, true, methodData, argTypes, argNames, false, new MethodArgNamesLookup()); new SignatureReader(signature).accept(methodResolver); methodResolver.finish(); }
From source file:com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.java
License:Apache License
public byte[] writeJsoIntf(final String className, byte classBytes[]) { String desc = toDescriptor(className); assert (jsoIntfDescs.contains(desc)); assert (jsoSuperDescs.containsKey(desc)); List<String> superDescs = jsoSuperDescs.get(desc); assert (superDescs != null); assert (superDescs.size() > 0); // The ASM model is to chain a bunch of visitors together. ClassWriter writer = new ClassWriter(0); final ClassVisitor v = writer; // v = new CheckClassAdapter(v); // v = new TraceClassVisitor(v, new PrintWriter(System.out)); String[] interfaces;/* w w w . jav a 2 s . co m*/ // TODO(bov): something better than linear? if (superDescs.contains("java/lang/Object")) { interfaces = null; } else { interfaces = superDescs.toArray(new String[superDescs.size()]); } v.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE, desc, null, "java/lang/Object", interfaces); if (classBytes != null) { // Java7 enforces innerclass/outerclass consistency. In order to fix this, copy from original ClassVisitor cv = new EmptyVisitor() { @Override public void visitInnerClass(String name, String outerName, String innerName, int access) { // copy inner class table from original JSO to synthetic interface v.visitInnerClass(name, outerName, innerName, access); } @Override public void visitOuterClass(String owner, String name, String desc) { // copy outer class table from original JSO to synthetic interface v.visitOuterClass(owner, name, desc); } }; new ClassReader(classBytes).accept(cv, 0); } v.visitEnd(); return writer.toByteArray(); }
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 a v a2 s . c om*/ }