[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[aspectj-users] Made a fix, not shure how to submit
|
- From: Linas <vejobrolis@xxxxxxxxx>
- Date: Sun, 30 Aug 2009 16:53:12 +0300
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type :date:message-id:mime-version:x-mailer; bh=Bj7n3R1Pmxw0M5lO4geED+NbLmfMGcHTeZj7tjOUM1k=; b=lu4nknJCyKSxvDBwHHUP/qgG19VKeXnJWrSdifLpeKR856Ohn1v6Glx/hizj0s728U IsDRQhhLOO97FCSrnSD7aN5oK8xDEBYmp5t24QPp0OL0DXCfb5ylYP9duZALD5ahuSek kVIRRDcJq0aYACQlNhUlH38+MI5+gm3abLP2A=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer; b=cXJBHLKZcMt5D6BP1cGmWe/rm1XbJb+rRSs1KDKmeymM0QxQNBgBSxcCgMmXS+mMcA 12qfKIj5P728jR47z47wGMMcNrCpT1Jh6L/+vcCuGwtIWvmS98D71IJ7f9xFjX8qB3qq uCE6GDZ1ttqGkrwu2RHBoKjLVUw/8kdyGJXh0=
Hello,
I made a fix for "weaver" that allows finding outer class from inner
class when inner class name does not follow javac name mangling
convention (for example because it's produced by scalac).
Since there is no relevant bug, should I open one and attach a patch, or
should I just post it here? In the second case, the patch is attached.
Linas.
### Eclipse Workspace Patch 1.0
#P weaver
Index: src/org/aspectj/weaver/bcel/BcelObjectType.java
===================================================================
RCS file: /cvsroot/tools/org.aspectj/modules/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java,v
retrieving revision 1.82
diff -u -r1.82 BcelObjectType.java
--- src/org/aspectj/weaver/bcel/BcelObjectType.java 24 Aug 2009 18:07:09 -0000 1.82
+++ src/org/aspectj/weaver/bcel/BcelObjectType.java 30 Aug 2009 13:31:27 -0000
@@ -23,8 +23,14 @@
import java.util.List;
import java.util.Set;
+import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.AttributeUtils;
+import org.aspectj.apache.bcel.classfile.ConstantClass;
+import org.aspectj.apache.bcel.classfile.ConstantString;
+import org.aspectj.apache.bcel.classfile.ConstantUtf8;
import org.aspectj.apache.bcel.classfile.Field;
+import org.aspectj.apache.bcel.classfile.InnerClass;
+import org.aspectj.apache.bcel.classfile.InnerClasses;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Signature;
@@ -805,6 +811,52 @@
public ResolvedType getOuterClass() {
if (!isNested())
throw new IllegalStateException("Can't get the outer class of a non-nested type");
+
+ //try finding outer class name from InnerClasses attribute assigned to this class
+ Attribute[] attrs = javaClass.getAttributes();
+ for( int attrIndex = 0; attrIndex < attrs.length; attrIndex++ ){
+ if( attrs[attrIndex] instanceof InnerClasses ){
+ //search for InnerClass entry that has current class as inner and some other class as outer
+ InnerClass[] innerClss = ((InnerClasses)attrs[attrIndex]).getInnerClasses();
+
+ for( int innerClsIndex = 0; innerClsIndex < innerClss.length; innerClsIndex++ ){
+ InnerClass innerCls = innerClss[innerClsIndex];
+
+ //skip entries that miss any necessary component, 0 index means "undefined", from JVM Spec 2nd ed. par. 4.7.5
+ if( innerCls.getInnerClassIndex() == 0 || innerCls.getOuterClassIndex() == 0 ) continue;
+
+ //resolve inner class name, check if it matches current class name
+ ConstantClass innerClsInfo = (ConstantClass)javaClass
+ .getConstantPool()
+ .getConstant(innerCls.getInnerClassIndex());
+
+ String innerClsName = ((ConstantUtf8)javaClass
+ .getConstantPool()
+ .getConstant(innerClsInfo.getNameIndex()))
+ .getBytes()
+ .replace('/', '.'); //class names in constant pool use '/' instead of '.', from JVM Spec 2nd ed. par. 4.2
+
+ if( innerClsName.compareTo(className) == 0 ){
+ //resolve outer class name
+ ConstantClass outerClsInfo = (ConstantClass)javaClass
+ .getConstantPool()
+ .getConstant(innerCls.getOuterClassIndex());
+
+ String outerClsName = ((ConstantUtf8)javaClass
+ .getConstantPool()
+ .getConstant(outerClsInfo.getNameIndex()))
+ .getBytes()
+ .replace('/', '.'); //class names in constant pool use '/' instead of '.', from JVM Spec 2nd ed. par. 4.2
+
+ //
+ UnresolvedType outer = UnresolvedType.forName(outerClsName);
+ return outer.resolve(getResolvedTypeX().getWorld());
+ }
+ }
+ }
+ }
+
+ //try finding outer class name by assuming standard class name mangling convention of javac for this class
int lastDollar = className.lastIndexOf('$');
String superClassName = className.substring(0, lastDollar);
UnresolvedType outer = UnresolvedType.forName(superClassName);