]> source.dussan.org Git - aspectj.git/commitdiff
hasmember (hasmethod / hasfield) tests - not linked into main suite at this point...
authoracolyer <acolyer>
Sun, 21 Aug 2005 19:53:30 +0000 (19:53 +0000)
committeracolyer <acolyer>
Sun, 21 Aug 2005 19:53:30 +0000 (19:53 +0000)
tests/hasmember/HasField.aj [new file with mode: 0644]
tests/hasmember/HasFieldInherited.aj [new file with mode: 0644]
tests/hasmember/HasMethod.aj [new file with mode: 0644]
tests/hasmember/HasMethodInherited.aj [new file with mode: 0644]
tests/hasmember/HasMethodViaITD.aj [new file with mode: 0644]
tests/hasmember/HasPrivateFieldInherited.aj [new file with mode: 0644]
tests/hasmember/HasPrivateMethodInherited.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/HasMember.java [new file with mode: 0644]

diff --git a/tests/hasmember/HasField.aj b/tests/hasmember/HasField.aj
new file mode 100644 (file)
index 0000000..d8b4ef5
--- /dev/null
@@ -0,0 +1,19 @@
+public aspect HasField {
+       
+       declare parents : hasfield(* printer) implements Printable; 
+
+       public static void main(String[] args) {
+               C c = new C();
+               if (! (c instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasfield failed");
+               }
+       }
+}
+
+class C {
+       
+       int printer;
+       
+}
+
+interface Printable {};
\ No newline at end of file
diff --git a/tests/hasmember/HasFieldInherited.aj b/tests/hasmember/HasFieldInherited.aj
new file mode 100644 (file)
index 0000000..bed5b42
--- /dev/null
@@ -0,0 +1,28 @@
+public aspect HasFieldInherited {
+       
+       declare parents : D && hasfield(* printer) implements Printable; 
+
+       public static void main(String[] args) {
+               C c = new C();
+               if ((c instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasfield failed on super");
+               }
+               D d = new D();
+               if (!(d instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasfield failed on sub");
+               }
+               
+       }
+}
+
+class C {
+       
+       String printer;
+       
+}
+
+class D extends C {
+       
+}
+
+interface Printable {};
\ No newline at end of file
diff --git a/tests/hasmember/HasMethod.aj b/tests/hasmember/HasMethod.aj
new file mode 100644 (file)
index 0000000..dc1bb3e
--- /dev/null
@@ -0,0 +1,19 @@
+public aspect HasMethod {
+       
+       declare parents : hasmethod(* print(..)) implements Printable; 
+
+       public static void main(String[] args) {
+               C c = new C();
+               if (! (c instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasmethod failed");
+               }
+       }
+}
+
+class C {
+       
+       public void print() {}
+       
+}
+
+interface Printable {};
\ No newline at end of file
diff --git a/tests/hasmember/HasMethodInherited.aj b/tests/hasmember/HasMethodInherited.aj
new file mode 100644 (file)
index 0000000..1c5aaaa
--- /dev/null
@@ -0,0 +1,28 @@
+public aspect HasMethodInherited {
+       
+       declare parents : D && hasmethod(* print(..)) implements Printable; 
+
+       public static void main(String[] args) {
+               C c = new C();
+               if ((c instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasmethod failed on super");
+               }
+               D d = new D();
+               if (!(d instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasmethod failed on sub");
+               }
+               
+       }
+}
+
+class C {
+       
+       protected void print() {}
+       
+}
+
+class D extends C {
+       
+}
+
+interface Printable {};
\ No newline at end of file
diff --git a/tests/hasmember/HasMethodViaITD.aj b/tests/hasmember/HasMethodViaITD.aj
new file mode 100644 (file)
index 0000000..5573675
--- /dev/null
@@ -0,0 +1,17 @@
+public aspect HasMethodViaITD {
+       
+       declare parents : hasmethod(* foo()) implements I;
+       
+       // C gets foo via ITD
+       public void C.foo() {}
+       
+       declare warning : execution(* I+.bar()) : "hasmethod matched on ITD ok";
+}
+
+interface I {}
+
+class C {
+       
+       void bar() {}
+       
+}
\ No newline at end of file
diff --git a/tests/hasmember/HasPrivateFieldInherited.aj b/tests/hasmember/HasPrivateFieldInherited.aj
new file mode 100644 (file)
index 0000000..b4d7b9a
--- /dev/null
@@ -0,0 +1,28 @@
+public aspect HasPrivateFieldInherited {
+       
+       declare parents : D && hasfield(* printer) implements Printable; 
+
+       public static void main(String[] args) {
+               C c = new C();
+               if ((c instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasfield failed on super");
+               }
+               D d = new D();
+               if ((d instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasfield failed on sub");
+               }
+               
+       }
+}
+
+class C {
+       
+       private String printer;
+       
+}
+
+class D extends C {
+       
+}
+
+interface Printable {};
\ No newline at end of file
diff --git a/tests/hasmember/HasPrivateMethodInherited.aj b/tests/hasmember/HasPrivateMethodInherited.aj
new file mode 100644 (file)
index 0000000..dff672b
--- /dev/null
@@ -0,0 +1,28 @@
+public aspect HasPrivateMethodInherited {
+       
+       declare parents : D && hasmethod(* print(..)) implements Printable; 
+
+       public static void main(String[] args) {
+               C c = new C();
+               if ((c instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasmethod failed on super");
+               }
+               D d = new D();
+               if ((d instanceof Printable)) {
+                       throw new RuntimeException("declare parents : hasmethod failed on sub");
+               }
+               
+       }
+}
+
+class C {
+       
+       private void print() {}
+       
+}
+
+class D extends C {
+       
+}
+
+interface Printable {};
\ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc150/HasMember.java b/tests/src/org/aspectj/systemtest/ajc150/HasMember.java
new file mode 100644 (file)
index 0000000..9eb7ba5
--- /dev/null
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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:
+ *    Adrian Colyer - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+public class HasMember extends XMLBasedAjcTestCase {
+
+         public static Test suite() {
+           return XMLBasedAjcTestCase.loadSuite(HasMember.class);
+         }
+
+         protected File getSpecFile() {
+           return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+         }
+
+         public void testSimpleDecPHasMethod() {
+                 runTest("declare parents : hasmethod(..) - 1");
+         }
+
+         public void testSimpleDecPHasMethodInherited() {
+                 runTest("declare parents : hasmethod(..) - 2");
+         }       
+
+         public void testSimpleDecPHasMethodInheritedPrivate() {
+                 runTest("declare parents : hasmethod(..) - 3");
+         }      
+         
+         public void testDecPHasMethodViaITD() {
+                 runTest("declare parents : hasmethod(..) - 4");
+         }
+         
+         public void testSimpleDecPHasField() {
+                 runTest("declare parents : hasfield(..) - 1");
+         }
+         
+         public void testSimpleDecPHasFieldInherited() {
+                 runTest("declare parents : hasfield(..) - 2");
+         }
+
+         public void testSimpleDecPHasFieldInheritedPrivate() {
+                 runTest("declare parents : hasfield(..) - 3");
+         }
+
+}
\ No newline at end of file