]> source.dussan.org Git - javassist.git/commitdiff
fixed JIRA JASSIST-33
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 11 May 2007 13:37:19 +0000 (13:37 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 11 May 2007 13:37:19 +0000 (13:37 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@370 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

Readme.html
src/main/javassist/compiler/TypeChecker.java

index c7c569a15a47cc95b4907d0243191adb3b09025c..8f9a0f9f66f4038cd6e596f4ec0d9a4a41a1013e 100644 (file)
@@ -241,7 +241,7 @@ with a web browser running
 
 <h3>8. sample/hotswap/*.java</h3>
 
-<p>This shows dynamic class reloading by the JPDA.
+<p>This shows dynamic class reloading by the JPDA.  It needs JDK 1.4 or later.
 To run, first type the following commands:
 
 <ul><pre>
@@ -283,6 +283,10 @@ see javassist.Dump.
 
 <p>-version 3.6
 
+<ul>
+    <li><a href="http://jira.jboss.com/jira/browse/JASSIST-33">JIRA JASSIST-33</a> has been fixed.
+</ul>
+
 <p>-version 3.5 on April 29, 2007
 <ul>
        <li>Various minor updates.
index 67e8cef4d5d2e7e09900b1921c09097dafba02f7..8bdcc63a71254872b9d4a7143290170b1f0af541 100644 (file)
@@ -822,12 +822,9 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
                 mem.setField(f);
                 return f;
             }
-            else if (op == '.')
+            else if (op == '.') {
                 try {
                     e.oprand1().accept(this);
-                    if (exprType == CLASS && arrayDim == 0)
-                        return resolver.lookupFieldByJvmName(className,
-                                                    (Symbol)e.oprand2());
                 }
                 catch (NoFieldException nfe) {
                     if (nfe.getExpr() != e.oprand1())
@@ -837,21 +834,56 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
                      * If EXPR might be part of a qualified class name,
                      * lookupFieldByJvmName2() throws NoFieldException.
                      */
-                    Member fname = (Member)e.oprand2();
-                    String jvmClassName = nfe.getField();
-                    CtField f = resolver.lookupFieldByJvmName2(jvmClassName,
-                                                               fname, expr);
-                    e.setOperator(MEMBER);
-                    e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(
-                                                            jvmClassName)));
-                    fname.setField(f);
-                    return f;
+                    return fieldAccess2(e, nfe.getField());
                 }
+
+                CompileError err = null;
+                try {
+                    if (exprType == CLASS && arrayDim == 0)
+                        return resolver.lookupFieldByJvmName(className,
+                                                    (Symbol)e.oprand2());
+                }
+                catch (CompileError ce) {
+                    err = ce;
+                }
+
+                /* If a filed name is the same name as a package's,
+                 * a static member of a class in that package is not
+                 * visible.  For example,
+                 *
+                 * class Foo {
+                 *   int javassist;
+                 * }
+                 *
+                 * It is impossible to add the following method:
+                 *
+                 * String m() { return javassist.CtClass.intType.toString(); }
+                 *
+                 * because javassist is a field name.  However, this is
+                 * often inconvenient, this compiler allows it.  The following
+                 * code is for that.
+                 */
+                ASTree oprnd1 = e.oprand1(); 
+                if (oprnd1 instanceof Symbol)
+                    return fieldAccess2(e, ((Symbol)oprnd1).get());
+
+                if (err != null)
+                    throw err;
+            }
         }
 
         throw new CompileError("bad filed access");
     }
 
+    private CtField fieldAccess2(Expr e, String jvmClassName) throws CompileError {
+        Member fname = (Member)e.oprand2();
+        CtField f = resolver.lookupFieldByJvmName2(jvmClassName, fname, e);
+        e.setOperator(MEMBER);
+        e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(jvmClassName)));
+        fname.setField(f);
+        return f;
+    }
+
     public void atClassObject(Expr expr) throws CompileError {
         exprType = CLASS;
         arrayDim = 0;