]> source.dussan.org Git - javassist.git/commitdiff
Merge branch 'master' into test/java9-jigsaw test/java9-jigsaw
authorchibash <chiba@javassist.org>
Thu, 29 Sep 2016 11:43:05 +0000 (20:43 +0900)
committerchibash <chiba@javassist.org>
Thu, 29 Sep 2016 11:43:05 +0000 (20:43 +0900)
1  2 
src/main/javassist/bytecode/ClassFile.java
src/test/javassist/JvstTest3.java
src/test/javassist/JvstTest5.java

Simple merge
index 41b640c70c72975768b91aaef5f6603ed9e112f1,c20a85f2cc5074228242a33c543678ebe2e7c604..9d22c47cc9d1f8b1077ba2e01cd4d989feb54d10
@@@ -236,10 -237,51 +237,57 @@@ public class JvstTest5 extends JvstTest
          assertEquals(1, invoke(obj, "run"));
      }
  
 +    public void testLoaderClassPath() throws Exception {
 +        ClassPool cp = new ClassPool();
 +        cp.appendClassPath(new LoaderClassPath(new Loader()));
 +        assertNotNull(cp.get(Object.class.getName()));
 +        assertNotNull(cp.get(this.getClass().getName()));
++
+     public void testAddDefaultMethod() throws Exception {
+         CtClass cc = sloader.makeInterface("test5.AddDefaultMethod");
+         cc.addMethod(CtNewMethod.make("static int foo() { return 1; }", cc));
+         cc.addMethod(CtNewMethod.make("public static int foo1() { return 1; }", cc));
+         cc.addMethod(CtNewMethod.make("public int foo2() { return 1; }", cc));
+         cc.addMethod(CtNewMethod.make("int foo3() { return 1; }", cc));
+         try {
+             cc.addMethod(CtNewMethod.make("private int foo4() { return 1; }", cc));
+             fail();
+         } catch (CannotCompileException e) {}
+         try {
+             cc.addMethod(CtNewMethod.make("private static int foo5() { return 1; }", cc));
+             fail();
+         } catch (CannotCompileException e) {}
+     }
+     public void testRemoveAnnotatino() throws Exception {
+         CtClass cc = sloader.get("test5.RemoveAnnotation");
+         AnnotationsAttribute aa
+             = (AnnotationsAttribute)cc.getClassFile().getAttribute(AnnotationsAttribute.invisibleTag);
+         assertTrue(aa.removeAnnotation("test5.RemoveAnno1"));
+         AttributeInfo ai = cc.getClassFile().removeAttribute(AnnotationsAttribute.invisibleTag);
+         assertEquals(ai.getName(), AnnotationsAttribute.invisibleTag);
+         CtMethod foo = cc.getDeclaredMethod("foo");
+         AnnotationsAttribute aa2 = (AnnotationsAttribute)foo.getMethodInfo().getAttribute(AnnotationsAttribute.invisibleTag);
+         assertTrue(aa2.removeAnnotation("test5.RemoveAnno1"));
+         CtMethod bar = cc.getDeclaredMethod("bar");
+         AnnotationsAttribute aa3 = (AnnotationsAttribute)bar.getMethodInfo().getAttribute(AnnotationsAttribute.invisibleTag);
+         assertFalse(aa3.removeAnnotation("test5.RemoveAnno1"));
+         assertTrue(aa3.removeAnnotation("test5.RemoveAnno2"));
+         AttributeInfo ai2 = bar.getMethodInfo().removeAttribute(AnnotationsAttribute.invisibleTag);
+         assertEquals(ai2.getName(), AnnotationsAttribute.invisibleTag);
+         CtMethod run = cc.getDeclaredMethod("run");
+         AttributeInfo ai3 = run.getMethodInfo().removeAttribute(AnnotationsAttribute.invisibleTag);
+         assertNull(ai3);
+         CtField baz = cc.getDeclaredField("baz");
+         AttributeInfo ai4 = baz.getFieldInfo().removeAttribute(AnnotationsAttribute.invisibleTag);
+         assertEquals(ai4.getName(), AnnotationsAttribute.invisibleTag);
+         cc.writeFile();
+         Object obj = make(cc.getName());
+         assertEquals(3, invoke(obj, "run"));
      }
  }