diff options
-rw-r--r-- | build.xml | 3 | ||||
-rw-r--r-- | javassist.jar | bin | 729051 -> 740722 bytes | |||
-rw-r--r-- | src/main/javassist/CtClassType.java | 16 | ||||
-rw-r--r-- | src/test/javassist/JvstTest.java | 8 | ||||
-rw-r--r-- | src/test/javassist/JvstTest5.java | 46 | ||||
-rw-r--r-- | src/test/test1/FieldInit.java | 7 | ||||
-rw-r--r-- | src/test/test5/InnerModifier2.java | 13 |
7 files changed, 88 insertions, 5 deletions
@@ -17,7 +17,7 @@ <property name="build.classes.dir" value="${build.dir}/classes"/> <property name="test.src.dir" value="${basedir}/src/test"/> <property name="test.build.dir" value="${build.dir}/test-classes"/> - <property name="test.run.dir" value="${basedir}/runtest"/> + <property name="test.run.dir" value="${build.dir}/runtest"/> <property name="test.reports.dir" value = "${build.dir}/test-output"/> <property name="run.dir" value="${build.classes.dir}"/> @@ -219,7 +219,6 @@ Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i>]]></bottom> <target name="clean"> <delete dir="html"/> - <delete dir="${test.run.dir}" /> <delete dir="${build.dir}"/> <delete file="${target.jar}"/> <delete file="${dist-version}.zip"/> diff --git a/javassist.jar b/javassist.jar Binary files differindex 915b45a6..78328e63 100644 --- a/javassist.jar +++ b/javassist.jar diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 0c2f775e..3791b5fb 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -446,9 +446,19 @@ class CtClassType extends CtClass { int acc = cf.getAccessFlags(); acc = AccessFlag.clear(acc, AccessFlag.SUPER); int inner = cf.getInnerAccessFlags(); - if (inner != -1 && (inner & AccessFlag.STATIC) != 0) - acc |= AccessFlag.STATIC; - + if (inner != -1) { + if ((inner & AccessFlag.STATIC) != 0) + acc |= AccessFlag.STATIC; + if ((inner & AccessFlag.PUBLIC) != 0) + acc |= AccessFlag.PUBLIC; + else { + acc &= ~AccessFlag.PUBLIC; //clear PUBLIC + if ((inner & AccessFlag.PROTECTED) != 0) + acc |= AccessFlag.PROTECTED; + else if ((inner & AccessFlag.PRIVATE) != 0) + acc |= AccessFlag.PRIVATE; + } + } return AccessFlag.toModifier(acc); } diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index c6825fd0..d28c0654 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -103,6 +103,10 @@ public class JvstTest extends JvstTestRoot { cc.addField(f2); CtField f3 = CtField.make("public int f3;", cc); cc.addField(f3); + CtField f4 = CtField.make("public int f4 = this.f2 + 3;", cc); + cc.addField(f4); + CtField fi = CtField.make("public test1.FieldInit.FI fi = new test1.FieldInit.FI(this);", cc); + cc.addField(fi); testFieldInitHash = f1.hashCode(); cc.writeFile(); Object obj = make(cc.getName()); @@ -112,6 +116,10 @@ public class JvstTest extends JvstTestRoot { assertEquals(3, value2); int value3 = obj.getClass().getField("f3").getInt(obj); assertEquals(0, value3); + int value4 = obj.getClass().getField("f4").getInt(obj); + assertEquals(6, value4); + Object obfi = obj.getClass().getField("fi").get(obj); + assertTrue(obfi.getClass().getField("fi").get(obfi) == obj); } /* test CodeIterator.insertExGap(). diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 578abfb2..346263cb 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -344,6 +344,52 @@ public class JvstTest5 extends JvstTestRoot { assertEquals(Modifier.PUBLIC, ica4.accessFlags(i5)); } + public void testInnerClassModifiers2() throws Exception { + CtClass cc = sloader.get("test5.InnerModifier2$Protected"); + Class<?> ccc = Class.forName("test5.InnerModifier2$Protected"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isProtected(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$Public"); + ccc = Class.forName("test5.InnerModifier2$Public"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isPublic(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$Private"); + ccc = Class.forName("test5.InnerModifier2$Private"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isPrivate(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$Package"); + ccc = Class.forName("test5.InnerModifier2$Package"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isPackage(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$ProtectedStatic"); + ccc = Class.forName("test5.InnerModifier2$ProtectedStatic"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isProtected(cc.getModifiers())); + assertTrue(Modifier.isStatic(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$PublicStatic"); + ccc = Class.forName("test5.InnerModifier2$PublicStatic"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isPublic(cc.getModifiers())); + assertTrue(Modifier.isStatic(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$PrivateStatic"); + ccc = Class.forName("test5.InnerModifier2$PrivateStatic"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isPrivate(cc.getModifiers())); + assertTrue(Modifier.isStatic(cc.getModifiers())); + + cc = sloader.get("test5.InnerModifier2$PackageStatic"); + ccc = Class.forName("test5.InnerModifier2$PackageStatic"); + assertEquals(cc.getModifiers(), ccc.getModifiers()); + assertTrue(Modifier.isPackage(cc.getModifiers())); + assertTrue(Modifier.isStatic(cc.getModifiers())); + } + private InnerClassesAttribute getInnerClassAttr(CtClass cc) { return (InnerClassesAttribute)cc.getClassFile2().getAttribute(InnerClassesAttribute.tag); } diff --git a/src/test/test1/FieldInit.java b/src/test/test1/FieldInit.java index 87f5a3bc..ee483149 100644 --- a/src/test/test1/FieldInit.java +++ b/src/test/test1/FieldInit.java @@ -14,4 +14,11 @@ public class FieldInit { --loop; } while (loop > 0); } + + public static class FI { + public FieldInit fi; + public FI(FieldInit fi) { + this.fi = fi; + } + } } diff --git a/src/test/test5/InnerModifier2.java b/src/test/test5/InnerModifier2.java new file mode 100644 index 00000000..009a0321 --- /dev/null +++ b/src/test/test5/InnerModifier2.java @@ -0,0 +1,13 @@ +package test5; + +@SuppressWarnings("unused") +public class InnerModifier2 { + public class Public {} + protected class Protected {} + private class Private {} + class Package {} + public static class PublicStatic {} + protected static class ProtectedStatic {} + private static class PrivateStatic {} + static class PackageStatic {} +} |