From: aclement Date: Mon, 7 Jun 2010 23:50:36 +0000 (+0000) Subject: itd inner classes X-Git-Tag: V1_6_9RC2~41 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c23f4a9bbd3aa38b86c9a3d8eb0a353af4eff9c5;p=aspectj.git itd inner classes --- diff --git a/tests/features169/itdInnerTypes/Basic2.java b/tests/features169/itdInnerTypes/Basic2.java new file mode 100644 index 000000000..b0c4244e8 --- /dev/null +++ b/tests/features169/itdInnerTypes/Basic2.java @@ -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 index 000000000..f944e4fda --- /dev/null +++ b/tests/features169/itdInnerTypes/Choice.java @@ -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 choices; + public static List forClass() { + ArrayList al = new ArrayList(); + return al; + } + public static class Choice.Keys { + public static final Function CHOICE = Get.attrOf(choices,"choice"); + } +} + +class Get { + public static Function attrOf(List t,String s) { + return null; + } +} + +class Function { + +} diff --git a/tests/features169/itdInnerTypes/FieldAccess.java b/tests/features169/itdInnerTypes/FieldAccess.java new file mode 100644 index 000000000..6fba671eb --- /dev/null +++ b/tests/features169/itdInnerTypes/FieldAccess.java @@ -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 index 000000000..ce8649ecd --- /dev/null +++ b/tests/features169/itdInnerTypes/MethodCall.java @@ -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 index 000000000..8aaa6f11f --- /dev/null +++ b/tests/features169/itdInnerTypes/OnAnnotation.java @@ -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 index 000000000..02d92dc98 --- /dev/null +++ b/tests/features169/itdInnerTypes/OnEnum.java @@ -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 index 000000000..f2c381d5d --- /dev/null +++ b/tests/features169/itdInnerTypes/OnInterface.java @@ -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 index 000000000..cbab60919 --- /dev/null +++ b/tests/features169/itdInnerTypes/OnlyStatic.java @@ -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 index 000000000..873eb69ae --- /dev/null +++ b/tests/features169/itdInnerTypes/Simplest.java @@ -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 index 000000000..d3649dfb8 --- /dev/null +++ b/tests/features169/itdInnerTypes/Simplest2.java @@ -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 index 000000000..4a1c2b5c6 --- /dev/null +++ b/tests/features169/itdInnerTypes/Simplest3.java @@ -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 index 000000000..8798e1f1d --- /dev/null +++ b/tests/features169/itdInnerTypes/Simplest4.java @@ -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); + } + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc169/AllTestsAspectJ169.java b/tests/src/org/aspectj/systemtest/ajc169/AllTestsAspectJ169.java index 4801b4148..f143fca99 100644 --- a/tests/src/org/aspectj/systemtest/ajc169/AllTestsAspectJ169.java +++ b/tests/src/org/aspectj/systemtest/ajc169/AllTestsAspectJ169.java @@ -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 index 000000000..6a002a782 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc169/IntertypeTests.java @@ -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 index 000000000..0fedf993f --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc169/intertype.txt @@ -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 index 000000000..bac60086a --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc169/intertype.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file