]> source.dussan.org Git - aspectj.git/commitdiff
itd inner classes
authoraclement <aclement>
Mon, 7 Jun 2010 23:50:36 +0000 (23:50 +0000)
committeraclement <aclement>
Mon, 7 Jun 2010 23:50:36 +0000 (23:50 +0000)
16 files changed:
tests/features169/itdInnerTypes/Basic2.java [new file with mode: 0644]
tests/features169/itdInnerTypes/Choice.java [new file with mode: 0644]
tests/features169/itdInnerTypes/FieldAccess.java [new file with mode: 0644]
tests/features169/itdInnerTypes/MethodCall.java [new file with mode: 0644]
tests/features169/itdInnerTypes/OnAnnotation.java [new file with mode: 0644]
tests/features169/itdInnerTypes/OnEnum.java [new file with mode: 0644]
tests/features169/itdInnerTypes/OnInterface.java [new file with mode: 0644]
tests/features169/itdInnerTypes/OnlyStatic.java [new file with mode: 0644]
tests/features169/itdInnerTypes/Simplest.java [new file with mode: 0644]
tests/features169/itdInnerTypes/Simplest2.java [new file with mode: 0644]
tests/features169/itdInnerTypes/Simplest3.java [new file with mode: 0644]
tests/features169/itdInnerTypes/Simplest4.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc169/AllTestsAspectJ169.java
tests/src/org/aspectj/systemtest/ajc169/IntertypeTests.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc169/intertype.txt [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc169/intertype.xml [new file with mode: 0644]

diff --git a/tests/features169/itdInnerTypes/Basic2.java b/tests/features169/itdInnerTypes/Basic2.java
new file mode 100644 (file)
index 0000000..b0c4244
--- /dev/null
@@ -0,0 +1,9 @@
+class Basic2 {
+  class Inner {
+  }
+}
+
+aspect Targeter {
+  class Basic2.Inner.InnerInner {
+  }
+}
diff --git a/tests/features169/itdInnerTypes/Choice.java b/tests/features169/itdInnerTypes/Choice.java
new file mode 100644 (file)
index 0000000..f944e4f
--- /dev/null
@@ -0,0 +1,28 @@
+import java.util.*;
+
+public class Choice {
+  public static void main(String []argv) {
+    System.out.println(Keys.CHOICE);
+  }
+}
+
+aspect X {
+  static List<Choice> choices;
+  public static List forClass() {
+    ArrayList al = new ArrayList();
+    return al;
+  }
+  public static class Choice.Keys {
+    public static final Function<Object, Choice> CHOICE = Get.attrOf(choices,"choice");
+  }
+}
+
+class Get {
+  public static <T> Function<Object,T> attrOf(List<T> t,String s) {
+    return null;
+  }
+}
+
+class Function<A,B> {
+  
+}
diff --git a/tests/features169/itdInnerTypes/FieldAccess.java b/tests/features169/itdInnerTypes/FieldAccess.java
new file mode 100644 (file)
index 0000000..6fba671
--- /dev/null
@@ -0,0 +1,15 @@
+public class FieldAccess {
+ // static String abc = "hello world";
+  public static void main(String []argv) {
+    System.out.println(Inner.number);
+  }
+}
+
+aspect X {
+  public static class FieldAccess.Inner {
+    static int number = 42;
+    public void m() {
+//      System.out.println(abc);
+    }
+  }
+}
diff --git a/tests/features169/itdInnerTypes/MethodCall.java b/tests/features169/itdInnerTypes/MethodCall.java
new file mode 100644 (file)
index 0000000..ce8649e
--- /dev/null
@@ -0,0 +1,15 @@
+public class MethodCall {
+ // static String abc = "hello world";
+  public static void main(String []argv) {
+    System.out.println(Inner.m());
+  }
+}
+
+aspect X {
+  public static class MethodCall.Inner {
+    static int number = 42;
+    public static Integer m() {
+      return number;
+    }
+  }
+}
diff --git a/tests/features169/itdInnerTypes/OnAnnotation.java b/tests/features169/itdInnerTypes/OnAnnotation.java
new file mode 100644 (file)
index 0000000..8aaa6f1
--- /dev/null
@@ -0,0 +1,11 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Anno {
+}
+
+aspect X {
+  class Anno.Inner {
+    Inner() {}
+  }
+}
diff --git a/tests/features169/itdInnerTypes/OnEnum.java b/tests/features169/itdInnerTypes/OnEnum.java
new file mode 100644 (file)
index 0000000..02d92dc
--- /dev/null
@@ -0,0 +1,9 @@
+enum EEE {
+  Red,Green,Blue;
+}
+
+aspect X {
+  class EEE.Inner {
+    Inner() {}
+  }
+}
diff --git a/tests/features169/itdInnerTypes/OnInterface.java b/tests/features169/itdInnerTypes/OnInterface.java
new file mode 100644 (file)
index 0000000..f2c381d
--- /dev/null
@@ -0,0 +1,8 @@
+interface OnInterface {
+}
+
+aspect X {
+  static class OnInterface.Inner {
+    Inner() {}
+  }
+}
diff --git a/tests/features169/itdInnerTypes/OnlyStatic.java b/tests/features169/itdInnerTypes/OnlyStatic.java
new file mode 100644 (file)
index 0000000..cbab609
--- /dev/null
@@ -0,0 +1,8 @@
+class OnlyStatic {
+}
+
+aspect X {
+  class OnlyStatic.Inner {
+    Inner() {}
+  }
+}
diff --git a/tests/features169/itdInnerTypes/Simplest.java b/tests/features169/itdInnerTypes/Simplest.java
new file mode 100644 (file)
index 0000000..873eb69
--- /dev/null
@@ -0,0 +1,4 @@
+aspect Targeter {
+  intertype Basic {}
+  //static aspect C {}
+}
diff --git a/tests/features169/itdInnerTypes/Simplest2.java b/tests/features169/itdInnerTypes/Simplest2.java
new file mode 100644 (file)
index 0000000..d3649df
--- /dev/null
@@ -0,0 +1,7 @@
+aspect Targeter {
+  intertype Basic {
+    static class Foo {
+    }
+  }
+  //static aspect C {}
+}
diff --git a/tests/features169/itdInnerTypes/Simplest3.java b/tests/features169/itdInnerTypes/Simplest3.java
new file mode 100644 (file)
index 0000000..4a1c2b5
--- /dev/null
@@ -0,0 +1,12 @@
+aspect Targeter {
+  intertype Basic {
+    public void foo() {} // declared on Basic
+  }
+  //static aspect C {}
+}
+
+class Basic {
+  public static void main(String[] argv) {
+    new Basic().foo();
+  }
+}
diff --git a/tests/features169/itdInnerTypes/Simplest4.java b/tests/features169/itdInnerTypes/Simplest4.java
new file mode 100644 (file)
index 0000000..8798e1f
--- /dev/null
@@ -0,0 +1,15 @@
+public class Simplest4 {
+ // static String abc = "hello world";
+  public static void main(String []argv) {
+    System.out.println(Inner.number);
+  }
+}
+
+aspect X {
+  public static class Simplest4.Inner {
+    static int number = 42;
+    public void m() {
+//      System.out.println(abc);
+    }
+  }
+}
index 4801b41488d8e8cce7a6af9ebd0347883d877e9c..f143fca991d76f496a9c87ea33277e5d50ebd620 100644 (file)
@@ -20,6 +20,7 @@ public class AllTestsAspectJ169 {
                // $JUnit-BEGIN$
                suite.addTest(Ajc169Tests.suite());
                suite.addTest(TransparentWeavingTests.suite());
+               suite.addTest(IntertypeTests.suite());
                // $JUnit-END$
                return suite;
        }
diff --git a/tests/src/org/aspectj/systemtest/ajc169/IntertypeTests.java b/tests/src/org/aspectj/systemtest/ajc169/IntertypeTests.java
new file mode 100644 (file)
index 0000000..6a002a7
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Contributors 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc169;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.util.ClassPath;
+import org.aspectj.apache.bcel.util.SyntheticRepository;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/**
+ * Tests exploring intertype declared inner types and the new intertype syntax.
+ * 
+ * @author Andy Clement
+ */
+public class IntertypeTests extends org.aspectj.testing.XMLBasedAjcTestCase {
+
+       // inter type declared classes - working scenarios
+       public void testFieldAccess() throws Exception {
+               runTest("field access");
+       }
+
+       public void testMethodAccess() throws Exception {
+               runTest("method access");
+       }
+
+       public void testRooScenario() throws Exception {
+               runTest("choice");
+       }
+
+       // compiler limitation tests
+       public void testNotAllowedOnInterface() throws Exception {
+               runTest("on interface");
+       }
+
+       public void testNotAllowedOnEnum() throws Exception {
+               runTest("on enum");
+       }
+
+       public void testNotAllowedOnAnnotation() throws Exception {
+               runTest("on annotation");
+       }
+
+       public void testOnlyStatic() throws Exception {
+               runTest("only static");
+       }
+
+       // tests for alternate syntax, not yet supported in the grammar
+
+       // intertype {} syntax
+       // public void testWillItParseEmptyIntertype() throws Exception {
+       // runTest("simplest", true);
+       // }
+       //
+       // public void testWithAnInnerClass() throws Exception {
+       // runTest("simplest 2");
+       // }
+       //
+       // public void testIntertypeMethodInNewStyle() throws Exception {
+       // runTest("simplest 3");
+       // }
+       // --
+
+       public SyntheticRepository createRepos(File cpentry) {
+               ClassPath cp = new ClassPath(cpentry + File.pathSeparator + System.getProperty("java.class.path"));
+               return SyntheticRepository.getInstance(cp);
+       }
+
+       protected JavaClass getClassFrom(File where, String clazzname) throws ClassNotFoundException {
+               SyntheticRepository repos = createRepos(where);
+               return repos.loadClass(clazzname);
+       }
+
+       public static Test suite() {
+               return XMLBasedAjcTestCase.loadSuite(IntertypeTests.class);
+       }
+
+       @Override
+       protected File getSpecFile() {
+               return new File("../tests/src/org/aspectj/systemtest/ajc169/intertype.xml");
+       }
+
+}
\ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc169/intertype.txt b/tests/src/org/aspectj/systemtest/ajc169/intertype.txt
new file mode 100644 (file)
index 0000000..0fedf99
--- /dev/null
@@ -0,0 +1,5 @@
+AspectDeclaration.buildInterTypeAndPerClause
+
+EclipseTypeMunger.mungeNewInnerClass
+
+EclipseTypeMunger.findOrCreateInterTypeMemberClassFinder
\ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc169/intertype.xml b/tests/src/org/aspectj/systemtest/ajc169/intertype.xml
new file mode 100644 (file)
index 0000000..bac6008
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<suite>
+
+   <ajc-test dir="features169/itdInnerTypes" title="choice">
+     <compile files="Choice.java" options="-1.5"/>
+     <run class="Choice">
+       <stdout>
+       <line text="null"/>
+       </stdout></run>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="field access">
+     <compile files="FieldAccess.java" options="-1.5"/>
+     <run class="FieldAccess">
+       <stdout>
+       <line text="42"/>
+       </stdout></run>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="method access">
+     <compile files="MethodCall.java" options="-1.5"/>
+     <run class="MethodCall">
+       <stdout>
+       <line text="42"/>
+       </stdout></run>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="only static">
+     <compile files="OnlyStatic.java" options="-1.5">
+       <message kind="error" line="5" text="Intertype declared member types can only be static (compiler limitation)"/>
+     </compile>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="on interface">
+     <compile files="OnInterface.java" options="-1.5">
+       <message kind="error" line="5" text="Cannot declare new member type on 'OnInterface'. New member types can only be specified on classes (compiler limitation)"/>
+     </compile>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="on enum">
+     <compile files="OnEnum.java" options="-1.5">
+       <message kind="error" line="6" text="Cannot declare new member type on 'EEE'. New member types can only be specified on classes (compiler limitation)"/>
+     </compile>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="on annotation">
+     <compile files="OnAnnotation.java" options="-1.5">
+       <message kind="error" line="8" text="Cannot declare new member type on 'Anno'. New member types can only be specified on classes (compiler limitation)"/>
+     </compile>
+   </ajc-test>
+   
+   <!-- 
+   <ajc-test dir="features169/itdInnerTypes" title="simplest 3">
+     <compile files="Simplest3.java" options="-1.5"/>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="simplest 2">
+     <compile files="Simplest2.java" options="-1.5"/>
+   </ajc-test>
+   
+   <ajc-test dir="features169/itdInnerTypes" title="simplest">
+     <compile files="Simplest.java" options="-1.5"/>
+   </ajc-test>
+   -->
+   
+</suite>
\ No newline at end of file