diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-08-18 15:22:38 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-08-18 15:22:38 +0000 |
commit | 2d60b1690e44dd33553e28618c7c0b25e4b34d9f (patch) | |
tree | b9a6b9c069e8ed045258c00d25708156401a838c /src/main/javassist/compiler/MemberResolver.java | |
parent | ff329de74b48a2a8431024ae1097abbdac60aa8f (diff) | |
download | javassist-2d60b1690e44dd33553e28618c7c0b25e4b34d9f.tar.gz javassist-2d60b1690e44dd33553e28618c7c0b25e4b34d9f.zip |
modified the compiler to support "import".
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@195 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler/MemberResolver.java')
-rw-r--r-- | src/main/javassist/compiler/MemberResolver.java | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java index fafbe22b..f931c9de 100644 --- a/src/main/javassist/compiler/MemberResolver.java +++ b/src/main/javassist/compiler/MemberResolver.java @@ -16,6 +16,7 @@ package javassist.compiler; import java.util.List; +import java.util.Iterator; import javassist.*; import javassist.bytecode.*; import javassist.compiler.ast.*; @@ -354,21 +355,32 @@ public class MemberResolver implements TokenId { try { return lookupClass0(name, notCheckInner); } - catch (NotFoundException e) {} - if (name.indexOf('.') < 0) { - String jlangName = "java.lang." + name; - try { - CtClass cc = classPool.get(jlangName); - // if java.lang... is found, then - classPool.recordInvalidClassName(name); - return cc; - } - catch (NotFoundException e) { - classPool.recordInvalidClassName(jlangName); + catch (NotFoundException e) { + return searchImports(name); + } + } + + private CtClass searchImports(String orgName) + throws CompileError + { + if (orgName.indexOf('.') < 0) { + Iterator it = classPool.getImportedPackages(); + while (it.hasNext()) { + String pac = (String)it.next(); + String fqName = pac + '.' + orgName; + try { + CtClass cc = classPool.get(fqName); + // if the class is found, + classPool.recordInvalidClassName(orgName); + return cc; + } + catch (NotFoundException e) { + classPool.recordInvalidClassName(fqName); + } } } - throw new CompileError("no such class: " + name); + throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) |