aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/JvstTest5.java
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2017-06-01 22:46:39 +0900
committerchibash <chiba@javassist.org>2017-06-01 22:46:39 +0900
commitdfd0733e1f73853453ff76086481ebec2e88a624 (patch)
tree267e33ac3f8c053f5a83d9fb934ca75c938c8a8a /src/test/javassist/JvstTest5.java
parentab117a9fe31902167b9a74fee1982068e4c4d095 (diff)
downloadjavassist-dfd0733e1f73853453ff76086481ebec2e88a624.tar.gz
javassist-dfd0733e1f73853453ff76086481ebec2e88a624.zip
modifies CtClass#setModifiers() to correctly support inner classes.
Diffstat (limited to 'src/test/javassist/JvstTest5.java')
-rw-r--r--src/test/javassist/JvstTest5.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 26474bb7..76d0c1a2 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -3,6 +3,7 @@ package javassist;
import java.lang.annotation.Annotation;
import java.lang.reflect.TypeVariable;
+import javassist.bytecode.AccessFlag;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.AttributeInfo;
import javassist.bytecode.ClassFile;
@@ -291,4 +292,58 @@ public class JvstTest5 extends JvstTestRoot {
Object obj = make(cc.getName());
assertEquals(3, invoke(obj, "run"));
}
+
+ public void testInnerClassModifiers() throws Exception {
+ CtClass cc = sloader.get("test5.InnerModifier$NonStatic");
+ try {
+ cc.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
+ fail();
+ }
+ catch (RuntimeException e) {
+ if (!e.getMessage().startsWith("cannot change "))
+ fail();
+ }
+
+ cc.setModifiers(Modifier.PUBLIC);
+ cc.writeFile();
+
+ assertEquals(Modifier.PUBLIC, cc.getModifiers());
+ InnerClassesAttribute ica = getInnerClassAttr(cc);
+ int i = ica.find("test5.InnerModifier$NonStatic");
+ assertTrue(i >= 0);
+ assertEquals(Modifier.PUBLIC, ica.accessFlags(i));
+
+ CtClass cc2 = sloader.get("test5.InnerModifier$Static");
+
+ InnerClassesAttribute ica3 = getInnerClassAttr(cc2);
+ int i3 = ica3.find("test5.InnerModifier$Static");
+ assertTrue(i3 >= 0);
+ assertEquals(AccessFlag.STATIC, ica3.accessFlags(i3));
+
+ cc2.setModifiers(Modifier.PROTECTED | Modifier.STATIC);
+ cc2.setModifiers(Modifier.PUBLIC);
+ cc2.writeFile();
+
+ assertEquals(Modifier.PUBLIC | Modifier.STATIC, cc2.getModifiers());
+ InnerClassesAttribute ica2 = getInnerClassAttr(cc2);
+ int i2 = ica2.find("test5.InnerModifier$Static");
+ assertTrue(i2 >= 0);
+ assertEquals(AccessFlag.PUBLIC | AccessFlag.STATIC, ica2.accessFlags(i2));
+
+ CtClass cc3 = cc.getDeclaringClass();
+ assertTrue(cc3.isModified());
+ cc3.writeFile();
+
+ InnerClassesAttribute ica4 = getInnerClassAttr(cc3);
+ int i4 = ica4.find("test5.InnerModifier$Static");
+ assertTrue(i4 >= 0);
+ assertEquals(AccessFlag.PUBLIC | AccessFlag.STATIC, ica4.accessFlags(i4));
+ int i5 = ica4.find("test5.InnerModifier$NonStatic");
+ assertTrue(i5 >= 0);
+ assertEquals(Modifier.PUBLIC, ica4.accessFlags(i5));
+ }
+
+ private InnerClassesAttribute getInnerClassAttr(CtClass cc) {
+ return (InnerClassesAttribute)cc.getClassFile2().getAttribute(InnerClassesAttribute.tag);
+ }
}