diff options
Diffstat (limited to 'ajde')
-rw-r--r-- | ajde/testdata/extensions/InnerClasses.java | 35 | ||||
-rw-r--r-- | ajde/testsrc/org/aspectj/ajde/ExtensionTests.java | 76 |
2 files changed, 111 insertions, 0 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); + } + } + } + } } |