summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2004-08-17 09:37:46 +0000
committeraclement <aclement>2004-08-17 09:37:46 +0000
commita2469c733c9f65514c3949cb1cc7254495011894 (patch)
treefe5894dd94c77bf7bb24678601b66b1f98b67e23
parenteb1d697f95742d25109b1d285db38da40464b340 (diff)
downloadaspectj-a2469c733c9f65514c3949cb1cc7254495011894.tar.gz
aspectj-a2469c733c9f65514c3949cb1cc7254495011894.zip
Fix for Bugzilla Bug 70241: outline view shows anonymous inner classes in different way than jdt outline
-rw-r--r--ajde/testdata/extensions/InnerClasses.java35
-rw-r--r--ajde/testsrc/org/aspectj/ajde/ExtensionTests.java76
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java10
3 files changed, 115 insertions, 6 deletions
diff --git a/ajde/testdata/extensions/InnerClasses.java b/ajde/testdata/extensions/InnerClasses.java
new file mode 100644
index 000000000..f51667d13
--- /dev/null
+++ b/ajde/testdata/extensions/InnerClasses.java
@@ -0,0 +1,35 @@
+public class InnerClasses {
+
+ public static void main(String[] args) {
+ Runnable r = new Runnable() {
+ public void run() {
+
+ }
+ };
+
+ r.run();
+
+ new Object() {
+ public String toString() {
+ return "a";
+ }
+ };
+
+ new Runnable() {
+ public void run() {
+
+ }
+ }.run();
+ }
+
+
+ static class A {
+ public void method() {
+ Runnable r = new Runnable() {
+ public void run() {
+
+ }
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java b/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java
index d4659e3a8..ab492011f 100644
--- a/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java
+++ b/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java
@@ -10,9 +10,13 @@
*******************************************************************************/
package org.aspectj.ajde;
+import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import java.io.File;
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IProgramElement;
import org.aspectj.bridge.IMessage;
import org.aspectj.tools.ajc.AjcTestCase;
import org.aspectj.tools.ajc.CompilationResult;
@@ -50,6 +54,78 @@ public class ExtensionTests extends AjcTestCase {
m.getID()==IProblem.UnusedImport);
}
+ public void testInnerClassesInASM() {
+ String[] args = new String[] {"InnerClasses.java","-emacssym"};
+ CompilationResult result = ajc(baseDir,args);
+ List l = result.getWarningMessages();
+ Properties p = AsmManager.ModelInfo.summarizeModel().getProperties();
+ System.out.println("Structure Model for InnerClasses.java:");
+ walkit(AsmManager.getDefault().getHierarchy().getRoot(),0);
+ foundNode = null;
+ findChild("main",AsmManager.getDefault().getHierarchy().getRoot());
+ assertTrue("Should have found node 'main' in the model",foundNode!=null);
+ IProgramElement runnableChild = getChild(foundNode,"new Runnable() {..}");
+ assertTrue("'main' should have a child 'new Runnable() {..}'",
+ runnableChild!=null);
+ assertTrue("'new Runnable() {..}' should have a 'run' child",
+ getChild(runnableChild,"run")!=null);
+
+ /* Left hand side is before the fix, right hand side is after:
+<root>
+ InnerClasses.java
+ import declarations
+ InnerClasses
+ A A
+ method method
+ 1 new Runnable() {..}
+ run run
+ main main
+ 2 new Runnable() {..}
+ run run
+ 3 new Object() {..}
+ toString toString
+ 4 new Runnable
+ run run
+ */
+
+ }
+
+ private IProgramElement getChild(IProgramElement parent,String s) {
+ List kids = parent.getChildren();
+ for (Iterator iter = kids.iterator(); iter.hasNext();) {
+ IProgramElement element = (IProgramElement) iter.next();
+ if (element.getName().indexOf(s)!=-1) return element;
+ }
+ return null;
+ }
+
+ private IProgramElement foundNode = null;
+
+ private void findChild(String s,IProgramElement ipe) {
+ if (ipe == null) return;
+ if (ipe.getName().indexOf(s)!=-1) {foundNode = ipe; return;}
+ if (ipe.getChildren()!=null) {
+ List kids = ipe.getChildren();
+ for (Iterator iter = kids.iterator(); iter.hasNext();) {
+ IProgramElement element = (IProgramElement) iter.next();
+ findChild(s,element);
+ }
+ }
+ }
+
+ public void walkit(IProgramElement ipe,int indent) {
+ if (ipe!=null) {
+ for (int i = 0 ;i<indent;i++) System.out.print(" ");
+ System.out.println(ipe.toLabelString());//getName());
+ if (ipe.getChildren()!=null) {
+ List kids = ipe.getChildren();
+ for (Iterator iter = kids.iterator(); iter.hasNext();) {
+ IProgramElement element = (IProgramElement) iter.next();
+ walkit(element,indent+2);
+ }
+ }
+ }
+ }
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
index 5ff6f078c..ffe8e37e3 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
@@ -279,11 +279,9 @@ public class AsmHierarchyBuilder extends ASTVisitor {
String fullName = "<undefined>";
if (memberTypeDeclaration.binding != null
&& memberTypeDeclaration.binding.constantPoolName() != null) {
- fullName = new String(memberTypeDeclaration.binding.constantPoolName());
+ // Create a name something like 'new Runnable() {..}'
+ fullName = "new "+memberTypeDeclaration.allocation.type.toString()+"() {..}";
}
-
- int dollar = fullName.indexOf('$');
- fullName = fullName.substring(dollar+1);
IProgramElement.Kind kind = IProgramElement.Kind.CLASS;
if (memberTypeDeclaration.isInterface()) kind = IProgramElement.Kind.INTERFACE;
@@ -298,8 +296,8 @@ public class AsmHierarchyBuilder extends ASTVisitor {
peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration));
peNode.setFormalComment(generateJavadocComment(memberTypeDeclaration));
- //??? we add this to the compilation unit
- findEnclosingClass(stack).addChild(peNode);
+
+ ((IProgramElement)stack.peek()).addChild(peNode);
stack.push(peNode);
return true;
}