]> source.dussan.org Git - aspectj.git/commitdiff
265729: testing ctor/field/method itds
authoraclement <aclement>
Thu, 26 Feb 2009 17:12:47 +0000 (17:12 +0000)
committeraclement <aclement>
Thu, 26 Feb 2009 17:12:47 +0000 (17:12 +0000)
tests/bugs164/pr265729/Aspect.java [new file with mode: 0644]
tests/bugs164/pr265729/Fruit.java [new file with mode: 0644]
tests/bugs164/pr265729/Orange.java [new file with mode: 0644]
tests/bugs164/pr265729/Strawberry.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc164/Ajc164Tests.java
tests/src/org/aspectj/systemtest/ajc164/ajc164.xml

diff --git a/tests/bugs164/pr265729/Aspect.java b/tests/bugs164/pr265729/Aspect.java
new file mode 100644 (file)
index 0000000..5e48a1c
--- /dev/null
@@ -0,0 +1,8 @@
+import java.awt.*;
+import demo.*;
+
+public aspect Aspect {
+  public Color Orange.getColor() { return Color.orange; }
+  public Color Strawberry.color = Color.red;
+  public Fruit.new(Color c,String name) {this();}
+}
diff --git a/tests/bugs164/pr265729/Fruit.java b/tests/bugs164/pr265729/Fruit.java
new file mode 100644 (file)
index 0000000..ffe4d54
--- /dev/null
@@ -0,0 +1,3 @@
+package demo;
+public class Fruit {
+}
diff --git a/tests/bugs164/pr265729/Orange.java b/tests/bugs164/pr265729/Orange.java
new file mode 100644 (file)
index 0000000..60c1dbf
--- /dev/null
@@ -0,0 +1,4 @@
+package demo;
+
+public class Orange {
+}
diff --git a/tests/bugs164/pr265729/Strawberry.java b/tests/bugs164/pr265729/Strawberry.java
new file mode 100644 (file)
index 0000000..5547e3e
--- /dev/null
@@ -0,0 +1,4 @@
+package demo;
+
+public class Strawberry {
+}
index cfc86fce98c75e51f10246089a714124aba478d6..74175ea6a8be3441b3a9a558fa523da86b176821 100644 (file)
@@ -11,6 +11,7 @@
 package org.aspectj.systemtest.ajc164;
 
 import java.io.File;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -28,10 +29,75 @@ import org.aspectj.apache.bcel.util.SyntheticRepository;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.IHierarchy;
 import org.aspectj.asm.IProgramElement;
+import org.aspectj.asm.IRelationship;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc164Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+       /**
+        * This test program can be used to compare handles for faulted in binary
+        * aspects with handles that would be used if the aspect was available as
+        * source. There are two compile steps in the xml for the test - commenting
+        * out the first will allow the source handles to be seen, leaving it in
+        * will switch to binary. Effectively the only difference should be that in
+        * the binary case the handles are prefixed 'binaries'.
+        */
+       public void testItdsAspectPathModel_pr265729_1() {
+               runTest("aspectpath model");
+               AsmManager model = AsmManager.lastActiveStructureModel;
+               IHierarchy top = model.getHierarchy();
+               printModel(model);
+               IProgramElement ipe = null;
+
+               // ITD METHOD
+               // should be the ITD method from the binary aspect:
+               // public Color Orange.getColor() { return Color.orange; }
+               ipe = top.findElementForType("demo", "Orange");
+               assertNotNull(ipe);
+               assertEquals("<demo{Orange.java[Orange", ipe.getHandleIdentifier());
+               IRelationship ir = (IRelationship) model.getRelationshipMap().get(ipe).get(0);
+               String itdMethodHandle = (String) ir.getTargets().get(0);
+               // handle when all source: <{Aspect.java}Aspect)Orange.getColor
+               assertEquals("/binaries<{Aspect.java}Aspect)Orange.getColor", itdMethodHandle);
+               IProgramElement itdpe = model.getHierarchy().findElementForHandle(itdMethodHandle);
+               assertEquals("java.awt.Color", itdpe.getCorrespondingType(true));
+
+               // ITD FIELD
+               // should be the ITD field from the binary aspect:
+               // public Color Strawberry.color
+               ipe = top.findElementForType("demo", "Strawberry");
+               assertNotNull(ipe);
+               assertEquals("<demo{Strawberry.java[Strawberry", ipe.getHandleIdentifier());
+               ir = (IRelationship) model.getRelationshipMap().get(ipe).get(0);
+               String itdFieldHandle = (String) ir.getTargets().get(0);
+               // source handle <{Aspect.java}Aspect)Strawberry.color
+               assertEquals("/binaries<{Aspect.java}Aspect)Strawberry.color", itdFieldHandle);
+               IProgramElement itdfpe = model.getHierarchy().findElementForHandle(itdMethodHandle);
+               assertEquals("java.awt.Color", itdfpe.getCorrespondingType(true));
+
+               // ITD CONSTRUCTOR
+               // /binaries< Aspect.java}Aspect)java.awt.Color demo.Strawberry.color
+               ipe = top.findElementForType("demo", "Fruit");
+               assertNotNull(ipe);
+               assertEquals("<demo{Fruit.java[Fruit", ipe.getHandleIdentifier());
+               ir = (IRelationship) model.getRelationshipMap().get(ipe).get(0);
+               String itdCtorHandle = (String) ir.getTargets().get(0);
+               // source handle <{Aspect.java}Aspect)Fruit.Fruit_new)QColor;)QString;
+               assertEquals("/binaries<{Aspect.java}Aspect)Fruit.Fruit_new)QColor;)QString;", itdCtorHandle);
+               IProgramElement itdcpe = model.getHierarchy().findElementForHandle(itdCtorHandle);
+               List ptypes = itdcpe.getParameterTypes();
+               assertEquals("java.awt.Color", new String((char[]) ptypes.get(0)));
+               assertEquals("java.lang.String", new String((char[]) ptypes.get(1)));
+       }
+
+       private void printModel(AsmManager model) {
+               try {
+                       model.dumptree(model.getHierarchy().getRoot(), 0);
+                       model.dumprels(new PrintWriter(System.out));
+               } catch (Exception e) {
+               }
+       }
+
        public void testGenericsAopXml_pr266220() {
                runTest("generics and aop.xml");
        }
index ecdf7ef9fa3ec7c2b31513cec276b52db22e74bc..b7cba242444c0ad45e645b3d05184415b2b23adf 100644 (file)
@@ -2,6 +2,12 @@
 
 <suite>
    
+   <ajc-test dir="bugs164/pr265729" title="aspectpath model">
+    <compile files="Aspect.java Orange.java Strawberry.java Fruit.java" outjar="library.jar" options="-emacssym"/>
+    <compile files="Orange.java Strawberry.java Fruit.java" aspectpath="library.jar" options="-emacssym"/>
+    <!--
+    -->
+   </ajc-test>
    
     <ajc-test dir="bugs164/pr266220" title="generics and aop.xml">
         <compile files="Code.java"/>