summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2004-12-02 10:36:03 +0000
committeraclement <aclement>2004-12-02 10:36:03 +0000
commita52e04ffdef2103958591521ac4c106be42e4bdc (patch)
tree3d364e68f119c19c714ac9657d9bccebb2a1c731
parentc20b526c0e3334d6c9606ef0764c93918c9673f8 (diff)
downloadaspectj-a52e04ffdef2103958591521ac4c106be42e4bdc.tar.gz
aspectj-a52e04ffdef2103958591521ac4c106be42e4bdc.zip
72766 - tests to confirm ITDs on enums/annotations not allowed.
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/Annotations.java56
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/Enums.java70
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/TestUtils.java88
3 files changed, 214 insertions, 0 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc150/Annotations.java b/tests/src/org/aspectj/systemtest/ajc150/Annotations.java
new file mode 100644
index 000000000..7255d427b
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc150/Annotations.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.tools.ajc.CompilationResult;
+
+
+/**
+ * Annotations, the rules/tests:
+ *
+ * 1. cannot make ITD (C,M or F) on an annotation
+ *
+ * XXXAJ5: The rest of these can't be tested (and so can't be attempted by users!) until the binary decp thing is fixed:
+ * 2. cannot use declare parents to change the super type of an annotation
+ * 3. cannot use decp to make an annotation type implement an interface
+ * 4. cannot use decp to dec java.lang.annotation.Annotation as the parent of any type
+ * 5. cannot extend set of values in an annotation via an ITD like construct
+ * 6. Compilation error if you explicitly identify an Annotation type.
+ * 7. Lint warning if a non-explicit type pattern would match an annotation type.
+ */
+public class Annotations extends TestUtils {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ baseDir = new File("../tests/java5/annotations");
+ }
+
+ // Cannot make ITD (c/m/f) on an annotation
+ public void test001_itdsOnAnnotationsNotAllowed() {
+ CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect01.aj",3,0);
+ assertTrue("Expected three message about ITDs not allowed on Annotations but got: #"+
+ cR.getErrorMessages().size()+": \n"+cR.getErrorMessages(),
+ cR.getErrorMessages().size()==3);
+ IMessage msg1_ctor = (IMessage)cR.getErrorMessages().get(0);
+ IMessage msg2_method = (IMessage)cR.getErrorMessages().get(1);
+ IMessage msg3_field = (IMessage)cR.getErrorMessages().get(2);
+ assertTrue("Expected message about ITDCs on annotations not allowed, but got: \n"+msg1_ctor,
+ msg1_ctor.toString().indexOf("can't make inter-type constructor declarations")!=-1);
+ assertTrue("Expected message about ITDMs on annotations not allowed, but got: \n"+msg2_method,
+ msg2_method.toString().indexOf("can't make inter-type method declarations")!=-1);
+ assertTrue("Expected message about ITDFs on annotations not allowed, but got: \n"+msg3_field,
+ msg3_field.toString().indexOf("can't make inter-type field declarations")!=-1);
+ verifyWeavingMessagesOutput(cR,new String[]{});
+ }
+} \ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc150/Enums.java b/tests/src/org/aspectj/systemtest/ajc150/Enums.java
new file mode 100644
index 000000000..a71f58c8e
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc150/Enums.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.tools.ajc.CompilationResult;
+
+
+/**
+ * Enums, the rules/tests:
+ *
+ * 1. cannot make ITDC on an enum
+ * 2. cannot make ITDM or ITDF on an enum
+ *
+ * XXXAJ5: The rest of these can't be tested (and so can't be attempted by users!) until the binary decp thing is fixed:
+ * 3. cannot use declare parents to change the super type of an enum
+ * 4. cannot use decp to make an enum type implement an interface
+ * 5. cannot use decp to dec java.lang.Enum as the parent of any type
+ * 6. cannot extend set of values in an enum via an ITD like construct
+ * 7. Compilation error if you explicitly identify an Enum type.
+ * 8. Lint warning if a non-explicit type pattern would match an enum type.
+ *
+ */
+public class Enums extends TestUtils {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ baseDir = new File("../tests/java5/enums");
+ }
+
+ // Cannot make ITDC on an enum
+ public void test001_itdcsOnEnumNotAllowed() {
+ CompilationResult cR = binaryWeave("testcode.jar","EnumAspect01.aj",1,0);
+ IMessage msg = (IMessage)cR.getErrorMessages().get(0);
+ assertTrue("Expected a message about ITDCs not allowed on enums but got: "+msg,
+ msg.toString().indexOf("can't make inter-type constructor declarations")!=-1);
+ verifyWeavingMessagesOutput(cR,new String[]{});
+ }
+
+ // Cannot make ITDM or ITDF on an enum
+ public void test002_itdFieldOrMethodOnEnumNotAllowed() {
+ CompilationResult cR = binaryWeave("testcode.jar","EnumAspect02.aj",2,0);
+ IMessage msg1 = (IMessage)cR.getErrorMessages().get(0);
+ IMessage msg2 = (IMessage)cR.getErrorMessages().get(1);
+ assertTrue("Expected a message about ITD methods not allowed on enums but got: "+msg1,
+ msg1.toString().indexOf("can't make inter-type method declarations")!=-1);
+ assertTrue("Expected a message about ITD fields not allowed on enums but got: "+msg2,
+ msg2.toString().indexOf("can't make inter-type field declarations")!=-1);
+ verifyWeavingMessagesOutput(cR,new String[]{});
+ }
+
+// public void test003_decpOnEnumNotAllowed() {
+// CompilationResult cR = binaryWeave("testcode.jar","EnumAspect03.aj",0,0);
+//// IMessage msg = (IMessage)cR.getErrorMessages().get(0);
+//// assertTrue("Expected a message about ITDCs not allowed on enums but got: "+msg,
+//// msg.toString().indexOf("not allowed on enum types")!=-1);
+// verifyWeavingMessagesOutput(cR,new String[]{});
+// }
+
+} \ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java b/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java
new file mode 100644
index 000000000..b7d90489e
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.tools.ajc.AjcTestCase;
+import org.aspectj.tools.ajc.CompilationResult;
+
+public abstract class TestUtils extends AjcTestCase {
+ private static final boolean verbose = false;
+ protected File baseDir;
+
+
+ protected CompilationResult binaryWeave(String inpath, String insource,int expErrors,int expWarnings) {
+ String[] args = new String[] {"-inpath",inpath,insource,"-showWeaveInfo","-proceedOnError"};
+ CompilationResult result = ajc(baseDir,args);
+ if (verbose || result.hasErrorMessages()) System.out.println(result);
+ assertTrue("Expected "+expErrors+" errors but got "+result.getErrorMessages().size()+":\n"+
+ formatCollection(result.getErrorMessages()),result.getErrorMessages().size()==expErrors);
+ assertTrue("Expected "+expWarnings+" warnings but got "+result.getWarningMessages().size()+":\n"+
+ formatCollection(result.getWarningMessages()),result.getWarningMessages().size()==expWarnings);
+ return result;
+ }
+
+
+ private String formatCollection(Collection s) {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator iter = s.iterator(); iter.hasNext();) {
+ Object element = (Object) iter.next();
+ sb.append(element).append("\n");
+ }
+ return sb.toString();
+ }
+
+ private List getWeavingMessages(List msgs) {
+ List result = new ArrayList();
+ for (Iterator iter = msgs.iterator(); iter.hasNext();) {
+ IMessage element = (IMessage) iter.next();
+ if (element.getKind()==IMessage.WEAVEINFO) {
+ result.add(element.toString());
+ }
+ }
+ return result;
+ }
+
+ protected void verifyWeavingMessagesOutput(CompilationResult cR,String[] expected) {
+ List weavingmessages = getWeavingMessages(cR.getInfoMessages());
+ dump(weavingmessages);
+ for (int i = 0; i < expected.length; i++) {
+ boolean found = weavingmessages.contains(expected[i]);
+ if (found) {
+ weavingmessages.remove(expected[i]);
+ } else {
+ System.err.println(dump(getWeavingMessages(cR.getInfoMessages())));
+ fail("Expected message not found.\nExpected:\n"+expected[i]+"\nObtained:\n"+dump(getWeavingMessages(cR.getInfoMessages())));
+ }
+ }
+ if (weavingmessages.size()!=0) {
+ fail("Unexpected messages obtained from program:\n"+dump(weavingmessages));
+ }
+ }
+
+
+ private String dump(List l) {
+ StringBuffer sb = new StringBuffer();
+ int i =0;
+ sb.append("--- Weaving Messages ---\n");
+ for (Iterator iter = l.iterator(); iter.hasNext();) {
+ sb.append(i+") "+iter.next()+"\n");
+ }
+ sb.append("------------------------\n");
+ return sb.toString();
+ }
+}