aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/compiler/MemberResolver.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-12-07 17:17:07 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-12-07 17:17:07 +0000
commit2467ddfb2132c361d0b36315c17055606487368d (patch)
tree8b5efe8bb64008c7570420d0bdea4618e6b06b38 /src/main/javassist/compiler/MemberResolver.java
parentcdca9771599b4c3337aaf42cf7460a27dc1719d5 (diff)
downloadjavassist-2467ddfb2132c361d0b36315c17055606487368d.tar.gz
javassist-2467ddfb2132c361d0b36315c17055606487368d.zip
made the compiler support inner classes appearing in type names.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@56 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler/MemberResolver.java')
-rw-r--r--src/main/javassist/compiler/MemberResolver.java70
1 files changed, 57 insertions, 13 deletions
diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java
index a716fa92..a96f3e66 100644
--- a/src/main/javassist/compiler/MemberResolver.java
+++ b/src/main/javassist/compiler/MemberResolver.java
@@ -208,20 +208,40 @@ public class MemberResolver implements TokenId {
}
/**
+ * Only used by fieldAccess() in MemberCodeGen.
+ *
* @param jvmClassName a JVM class name. e.g. java/lang/String
*/
- public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName)
- throws CompileError
+ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym,
+ ASTree expr) throws NoFieldException
{
- return lookupField(jvmToJavaName(jvmClassName), fieldName);
+ String field = fieldSym.get();
+ CtClass cc = null;
+ try {
+ cc = lookupClass(jvmToJavaName(jvmClassName), true);
+ }
+ catch (CompileError e) {
+ // EXPR might be part of a qualified class name.
+ throw new NoFieldException(jvmClassName + "/" + field, expr);
+ }
+
+ try {
+ return cc.getField(field);
+ }
+ catch (NotFoundException e) {
+ // maybe an inner class.
+ jvmClassName = javaToJvmName(cc.getName());
+ throw new NoFieldException(jvmClassName + "$" + field, expr);
+ }
}
- // never used??
- private CtField lookupField2(ASTList className, Symbol fieldName)
+ /**
+ * @param jvmClassName a JVM class name. e.g. java/lang/String
+ */
+ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName)
throws CompileError
{
- return lookupField(Declarator.astToClassName(className, '.'),
- fieldName);
+ return lookupField(jvmToJavaName(jvmClassName), fieldName);
}
/**
@@ -230,7 +250,7 @@ public class MemberResolver implements TokenId {
public CtField lookupField(String className, Symbol fieldName)
throws CompileError
{
- CtClass cc = lookupClass(className);
+ CtClass cc = lookupClass(className, false);
try {
return cc.getField(fieldName.get());
}
@@ -239,11 +259,11 @@ public class MemberResolver implements TokenId {
}
public CtClass lookupClassByName(ASTList name) throws CompileError {
- return lookupClass(Declarator.astToClassName(name, '.'));
+ return lookupClass(Declarator.astToClassName(name, '.'), false);
}
public CtClass lookupClassByJvmName(String jvmName) throws CompileError {
- return lookupClass(jvmToJavaName(jvmName));
+ return lookupClass(jvmToJavaName(jvmName), false);
}
public CtClass lookupClass(Declarator decl) throws CompileError {
@@ -302,15 +322,17 @@ public class MemberResolver implements TokenId {
while (dim-- > 0)
cname += "[]";
- return lookupClass(cname);
+ return lookupClass(cname, false);
}
/**
* @param name a qualified class name. e.g. java.lang.String
*/
- public CtClass lookupClass(String name) throws CompileError {
+ public CtClass lookupClass(String name, boolean notCheckInner)
+ throws CompileError
+ {
try {
- return classPool.get(name);
+ return lookupClass0(name, notCheckInner);
}
catch (NotFoundException e) {}
@@ -323,6 +345,28 @@ public class MemberResolver implements TokenId {
throw new CompileError("no such class: " + name);
}
+ private CtClass lookupClass0(String classname, boolean notCheckInner)
+ throws NotFoundException
+ {
+ CtClass cc = null;
+ do {
+ try {
+ cc = classPool.get(classname);
+ }
+ catch (NotFoundException e) {
+ int i = classname.lastIndexOf('.');
+ if (notCheckInner || i < 0)
+ throw e;
+ else {
+ StringBuffer sbuf = new StringBuffer(classname);
+ sbuf.setCharAt(i, '$');
+ classname = sbuf.toString();
+ }
+ }
+ } while (cc == null);
+ return cc;
+ }
+
/* Converts a class name into a JVM-internal representation.
*
* It may also expand a simple class name to java.lang.*.