]> source.dussan.org Git - aspectj.git/commitdiff
Bug 152982 "org.aspectj Restructure - Phase 2: Move tests" (move Java 5 dependent...
authormwebster <mwebster>
Tue, 8 Aug 2006 14:11:26 +0000 (14:11 +0000)
committermwebster <mwebster>
Tue, 8 Aug 2006 14:11:26 +0000 (14:11 +0000)
org.aspectj.ajdt.core/.classpath
org.aspectj.ajdt.core/java5-testsrc/Eajc515ModuleTests.java [new file with mode: 0644]
org.aspectj.ajdt.core/java5-testsrc/org/aspectj/tools/ajc/AjAST5Test.java [new file with mode: 0644]
org.aspectj.ajdt.core/java5-testsrc/org/aspectj/tools/ajc/Ajc5Tests.java [new file with mode: 0644]
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/EajcModuleTests.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTestCase.java [new file with mode: 0644]

index eeb6941b2ac5ac566bc118cd97a61c32b5f7a7a1..7699c178151fd4d7c9552d8489109ac87f3af415 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
        <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="java5-testsrc"/>
        <classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>
        <classpathentry kind="src" path="/bridge"/>
        <classpathentry kind="src" path="/weaver"/>
diff --git a/org.aspectj.ajdt.core/java5-testsrc/Eajc515ModuleTests.java b/org.aspectj.ajdt.core/java5-testsrc/Eajc515ModuleTests.java
new file mode 100644 (file)
index 0000000..9efd128
--- /dev/null
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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
+ * 
+ * Contributors:
+ *     Matthew Webster - initial implementation
+ *******************************************************************************/
+import junit.framework.*;
+import junit.framework.Test;
+
+public class Eajc515ModuleTests extends TestCase {
+
+    public static Test suite() { 
+        TestSuite suite = new TestSuite(Eajc515ModuleTests.class.getName());
+        suite.addTest(org.aspectj.tools.ajc.Ajc5Tests.suite());
+        return suite;
+    }
+
+    public Eajc515ModuleTests(String name) { super(name); }
+
+}  
diff --git a/org.aspectj.ajdt.core/java5-testsrc/org/aspectj/tools/ajc/AjAST5Test.java b/org.aspectj.ajdt.core/java5-testsrc/org/aspectj/tools/ajc/AjAST5Test.java
new file mode 100644 (file)
index 0000000..213cf0e
--- /dev/null
@@ -0,0 +1,158 @@
+/********************************************************************
+ * Copyright (c) 2006 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://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: IBM Corporation - initial API and implementation 
+ *                              Helen Hawkins   - initital version
+ *                              Matthew Webster - moved tests
+ *******************************************************************/
+package org.aspectj.tools.ajc;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.org.eclipse.jdt.core.dom.AST;
+import org.aspectj.org.eclipse.jdt.core.dom.AjAST;
+import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
+import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
+import org.aspectj.org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
+import org.aspectj.org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
+import org.aspectj.org.eclipse.jdt.core.dom.DeclareParentsDeclaration;
+import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern;
+import org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin;
+import org.aspectj.org.eclipse.jdt.core.dom.SimplePropertyDescriptor;
+import org.aspectj.org.eclipse.jdt.core.dom.TypePattern;
+
+
+public class AjAST5Test extends AjASTTestCase {
+
+       public void testInternalAspectDeclaration() {
+               AjAST ajast = createAjAST();
+               AspectDeclaration d = ajast.newAspectDeclaration();
+               List props = AspectDeclaration.propertyDescriptors(AST.JLS3);
+               for (Iterator iter = props.iterator(); iter.hasNext();) {
+                       Object o = iter.next();
+                       if (o instanceof ChildPropertyDescriptor) {
+                               ChildPropertyDescriptor element = (ChildPropertyDescriptor)o;
+                               if (element.getId().equals("perClause")) {
+                                       assertNull("AspectDeclaration's " + element.getId() + " property" +
+                                                       "should be null since we haven't set it yet",
+                                                       d.getStructuralProperty(element));                                      
+                               }
+                       } else if (o instanceof SimplePropertyDescriptor) {
+                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
+                               assertNotNull("AspectDeclaration's " + element.getId() + " property" +
+                                               "should not be null since it is a boolean",
+                                               d.getStructuralProperty(element));
+                       }
+               }
+               for (Iterator iter = props.iterator(); iter.hasNext();) {
+                       Object o = iter.next();
+                       if (o instanceof ChildPropertyDescriptor) {
+                               ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
+                               if (element.getId().equals("perClause")) {
+                                       PerTypeWithin ptw = ajast.newPerTypeWithin();
+                                       d.setStructuralProperty(element,ptw);
+                                       assertEquals("AspectDeclaration's perClause property should" +
+                                                       " now be a perTypeWithin",ptw,d.getStructuralProperty(element));
+                               } else if (element.getId().equals("javadoc")) {
+                                       // do nothing since makes no sense to have javadoc
+                               }                               
+                       } else if (o instanceof SimplePropertyDescriptor) {
+                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
+                           if (element.getId().equals("privileged")) {
+                                       Boolean b = new Boolean(true);
+                                       d.setStructuralProperty(element,b);
+                                       assertEquals("AspectDeclaration's isPrivileged property should" +
+                                                       " now be a boolean",b,d.getStructuralProperty(element));
+                           }
+                       }
+               }
+       }
+       
+       public void testInternalAjTypeDeclaration() {
+               AjAST ajast = createAjAST();
+               AjTypeDeclaration d = ajast.newAjTypeDeclaration();
+               List props = AjTypeDeclaration.propertyDescriptors(AST.JLS3);
+               for (Iterator iter = props.iterator(); iter.hasNext();) {
+                       Object o = iter.next();
+                       if (o instanceof SimplePropertyDescriptor) {
+                               SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
+                               if (element.getId().equals("aspect")) {
+                                       assertNotNull("AjTypeDeclaration's " + element.getId() + " property" +
+                                                       " should not be null since it is a boolean",
+                                                       d.getStructuralProperty(element));                              
+                               }                               
+                       }
+               }
+               for (Iterator iter = props.iterator(); iter.hasNext();) {
+                       Object o = iter.next();
+                       if (o instanceof SimplePropertyDescriptor) {
+                               SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
+                               if (element.getId().equals("aspect")) {
+                                       Boolean b = new Boolean(true);
+                                       d.setStructuralProperty(element,b);
+                                       assertEquals("AjTypeDeclaration's aspect property should" +
+                                               " now be a SignaturePattern",b,d.getStructuralProperty(element));
+                               }
+                       }
+               }
+       }
+       
+       public void testInternalDeclareParentsDeclaration() {
+               AjAST ajast = createAjAST();
+               DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
+               List props = DeclareParentsDeclaration.propertyDescriptors(AST.JLS3);
+               for (Iterator iter = props.iterator(); iter.hasNext();) {
+                       Object o = iter.next();
+                       if (o instanceof ChildPropertyDescriptor) {
+                               ChildPropertyDescriptor element = (ChildPropertyDescriptor)o;
+                               assertNull("DeclareParentsDeclaration's " + element.getId() + " property" +
+                                               "should be null since we haven't set it yet",
+                                               d.getStructuralProperty(element));                                      
+                       } else if (o instanceof ChildListPropertyDescriptor) {
+                               ChildListPropertyDescriptor element = (ChildListPropertyDescriptor)o;
+                               assertNotNull("DeclareParentsDeclaration's " + element.getId() + " property" +
+                                               "should not be null since it is a list",
+                                               d.getStructuralProperty(element));
+                               assertEquals("should only be able to put TypePattern's into the list",
+                                               TypePattern.class,element.getElementType());
+                       } else if (o instanceof SimplePropertyDescriptor) {
+                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
+                               assertNotNull("DeclareParentsDeclaration's " + element.getId() + " property" +
+                                               "should not be null since it is a boolean",
+                                               d.getStructuralProperty(element));                                                                      
+                       } else {
+                               fail("unknown PropertyDescriptor associated with DeclareParentsDeclaration: " + o);
+                       }
+               }
+               for (Iterator iter = props.iterator(); iter.hasNext();) {
+                       Object o = iter.next();
+                       if (o instanceof ChildPropertyDescriptor) {
+                               ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
+                               if (element.getId().equals("childTypePattern")) {
+                                       DefaultTypePattern dtp = ajast.newDefaultTypePattern();
+                                       d.setStructuralProperty(element,dtp);
+                                       assertEquals("DeclareParentsDeclaration's typePattern property should" +
+                                                       " now be a DefaultTypePattern",dtp,d.getStructuralProperty(element));
+                               } else if (element.getId().equals("javadoc")) {
+                                       // do nothing since makes no sense to have javadoc
+                               } else {
+                                       fail("unknown property for DeclareParentsDeclaration");
+                               }                               
+                       } else if (o instanceof SimplePropertyDescriptor) {
+                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
+                           if (element.getId().equals("isExtends")) {
+                                       Boolean b = new Boolean(true);
+                                       d.setStructuralProperty(element,b);
+                                       assertEquals("DeclareParentsDeclaration's isExtends property should" +
+                                                       " now be a boolean",b,d.getStructuralProperty(element));
+                           }
+                       }
+               }
+       }
+
+}
diff --git a/org.aspectj.ajdt.core/java5-testsrc/org/aspectj/tools/ajc/Ajc5Tests.java b/org.aspectj.ajdt.core/java5-testsrc/org/aspectj/tools/ajc/Ajc5Tests.java
new file mode 100644 (file)
index 0000000..44bdc76
--- /dev/null
@@ -0,0 +1,30 @@
+/* *******************************************************************
+ * Copyright (c) 2005 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://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *     Matthew Webster  initial implementation 
+ * ******************************************************************/
+package org.aspectj.tools.ajc;
+
+import org.aspectj.testing.util.TestUtil;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class Ajc5Tests extends TestCase {
+    public static String aspectjrtClasspath() {
+        return TestUtil.aspectjrtPath().getPath();        
+    }
+    public static Test suite() { 
+        TestSuite suite = new TestSuite(Ajc5Tests.class.getName());
+        suite.addTestSuite(AjAST5Test.class);
+        return suite;
+    }
+
+}
index 58816162d65938324e05347644abaf3714c11393..8889ddc0681ac13fe9504fd43073b85dc4ad6817 100644 (file)
@@ -16,8 +16,9 @@ package org.aspectj.ajdt;
 // default package
 
 
+import org.aspectj.testing.util.TestUtil;
+
 import junit.framework.*;
-import junit.framework.Test;
 
 public class EajcModuleTests extends TestCase {
 
@@ -27,6 +28,13 @@ public class EajcModuleTests extends TestCase {
         suite.addTest(org.aspectj.ajdt.internal.compiler.batch.AjdtBatchTests.suite()); 
         suite.addTest(org.aspectj.ajdt.internal.core.builder.AjdtBuilderTests.suite()); 
         suite.addTest(org.aspectj.tools.ajc.AjcTests.suite());
+
+        /* FIXME maw move these Java 5 dependent tests to a separate project */
+        if (TestUtil.is15VMOrGreater()) {
+            TestUtil.loadTestsReflectively(suite, "Eajc515ModuleTests", true);
+        } else {
+            suite.addTest(TestUtil.testNamed("Eajc515ModuleTests require 1.5"));
+        }
         return suite;
     }
 
index b9e198b018d58b954c56aaff9470211797e3c2ff..08d72586a20fe4e78082b372fe5125e583357573 100644 (file)
  *******************************************************************/
 package org.aspectj.tools.ajc;
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.aspectj.org.eclipse.jdt.core.dom.AST;
 import org.aspectj.org.eclipse.jdt.core.dom.ASTNode;
-import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
 import org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration;
 import org.aspectj.org.eclipse.jdt.core.dom.AfterReturningAdviceDeclaration;
 import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
@@ -33,7 +29,6 @@ import org.aspectj.org.eclipse.jdt.core.dom.Block;
 import org.aspectj.org.eclipse.jdt.core.dom.CflowPointcut;
 import org.aspectj.org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
 import org.aspectj.org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
-import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
 import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtConstructorDeclaration;
 import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtFieldDeclaration;
 import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtMethodDeclaration;
@@ -82,7 +77,7 @@ import org.aspectj.org.eclipse.jdt.core.dom.TypePattern;
  *  implementation of the accept0() method which is tested
  *  in ASTVisitorTest.     
  */
-public class AjASTTest extends TestCase {
+public class AjASTTest extends AjASTTestCase {
        
        // -------------- DefaultPointcut tests ---------------
        
@@ -573,50 +568,6 @@ public class AjASTTest extends TestCase {
                                copy.isPrivileged());
        }
        
-       public void testInternalAspectDeclaration() {
-               AjAST ajast = createAjAST();
-               AspectDeclaration d = ajast.newAspectDeclaration();
-               List props = AspectDeclaration.propertyDescriptors(AST.JLS3);
-               for (Iterator iter = props.iterator(); iter.hasNext();) {
-                       Object o = iter.next();
-                       if (o instanceof ChildPropertyDescriptor) {
-                               ChildPropertyDescriptor element = (ChildPropertyDescriptor)o;
-                               if (element.getId().equals("perClause")) {
-                                       assertNull("AspectDeclaration's " + element.getId() + " property" +
-                                                       "should be null since we haven't set it yet",
-                                                       d.getStructuralProperty(element));                                      
-                               }
-                       } else if (o instanceof SimplePropertyDescriptor) {
-                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
-                               assertNotNull("AspectDeclaration's " + element.getId() + " property" +
-                                               "should not be null since it is a boolean",
-                                               d.getStructuralProperty(element));
-                       }
-               }
-               for (Iterator iter = props.iterator(); iter.hasNext();) {
-                       Object o = iter.next();
-                       if (o instanceof ChildPropertyDescriptor) {
-                               ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
-                               if (element.getId().equals("perClause")) {
-                                       PerTypeWithin ptw = ajast.newPerTypeWithin();
-                                       d.setStructuralProperty(element,ptw);
-                                       assertEquals("AspectDeclaration's perClause property should" +
-                                                       " now be a perTypeWithin",ptw,d.getStructuralProperty(element));
-                               } else if (element.getId().equals("javadoc")) {
-                                       // do nothing since makes no sense to have javadoc
-                               }                               
-                       } else if (o instanceof SimplePropertyDescriptor) {
-                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
-                           if (element.getId().equals("privileged")) {
-                                       Boolean b = new Boolean(true);
-                                       d.setStructuralProperty(element,b);
-                                       assertEquals("AspectDeclaration's isPrivileged property should" +
-                                                       " now be a boolean",b,d.getStructuralProperty(element));
-                           }
-                       }
-               }
-       }
-
        
        /**
         * AsepctDeclarations's have a perClause property - test the getting
@@ -850,35 +801,6 @@ public class AjASTTest extends TestCase {
                assertTrue("the AjTypeDeclaration clone should be an aspect",
                                copy.isAspect());
        }
-       
-       public void testInternalAjTypeDeclaration() {
-               AjAST ajast = createAjAST();
-               AjTypeDeclaration d = ajast.newAjTypeDeclaration();
-               List props = AjTypeDeclaration.propertyDescriptors(AST.JLS3);
-               for (Iterator iter = props.iterator(); iter.hasNext();) {
-                       Object o = iter.next();
-                       if (o instanceof SimplePropertyDescriptor) {
-                               SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
-                               if (element.getId().equals("aspect")) {
-                                       assertNotNull("AjTypeDeclaration's " + element.getId() + " property" +
-                                                       " should not be null since it is a boolean",
-                                                       d.getStructuralProperty(element));                              
-                               }                               
-                       }
-               }
-               for (Iterator iter = props.iterator(); iter.hasNext();) {
-                       Object o = iter.next();
-                       if (o instanceof SimplePropertyDescriptor) {
-                               SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
-                               if (element.getId().equals("aspect")) {
-                                       Boolean b = new Boolean(true);
-                                       d.setStructuralProperty(element,b);
-                                       assertEquals("AjTypeDeclaration's aspect property should" +
-                                               " now be a SignaturePattern",b,d.getStructuralProperty(element));
-                               }
-                       }
-               }
-       }
 
        // test for bug 125809 - make sure the property descriptors 
        // associated with the AspectDeclaration aren't consequently
@@ -1532,59 +1454,6 @@ public class AjASTTest extends TestCase {
                                copy.isExtends());
        }
        
-       public void testInternalDeclareParentsDeclaration() {
-               AjAST ajast = createAjAST();
-               DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
-               List props = DeclareParentsDeclaration.propertyDescriptors(AST.JLS3);
-               for (Iterator iter = props.iterator(); iter.hasNext();) {
-                       Object o = iter.next();
-                       if (o instanceof ChildPropertyDescriptor) {
-                               ChildPropertyDescriptor element = (ChildPropertyDescriptor)o;
-                               assertNull("DeclareParentsDeclaration's " + element.getId() + " property" +
-                                               "should be null since we haven't set it yet",
-                                               d.getStructuralProperty(element));                                      
-                       } else if (o instanceof ChildListPropertyDescriptor) {
-                               ChildListPropertyDescriptor element = (ChildListPropertyDescriptor)o;
-                               assertNotNull("DeclareParentsDeclaration's " + element.getId() + " property" +
-                                               "should not be null since it is a list",
-                                               d.getStructuralProperty(element));
-                               assertEquals("should only be able to put TypePattern's into the list",
-                                               TypePattern.class,element.getElementType());
-                       } else if (o instanceof SimplePropertyDescriptor) {
-                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
-                               assertNotNull("DeclareParentsDeclaration's " + element.getId() + " property" +
-                                               "should not be null since it is a boolean",
-                                               d.getStructuralProperty(element));                                                                      
-                       } else {
-                               fail("unknown PropertyDescriptor associated with DeclareParentsDeclaration: " + o);
-                       }
-               }
-               for (Iterator iter = props.iterator(); iter.hasNext();) {
-                       Object o = iter.next();
-                       if (o instanceof ChildPropertyDescriptor) {
-                               ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
-                               if (element.getId().equals("childTypePattern")) {
-                                       DefaultTypePattern dtp = ajast.newDefaultTypePattern();
-                                       d.setStructuralProperty(element,dtp);
-                                       assertEquals("DeclareParentsDeclaration's typePattern property should" +
-                                                       " now be a DefaultTypePattern",dtp,d.getStructuralProperty(element));
-                               } else if (element.getId().equals("javadoc")) {
-                                       // do nothing since makes no sense to have javadoc
-                               } else {
-                                       fail("unknown property for DeclareParentsDeclaration");
-                               }                               
-                       } else if (o instanceof SimplePropertyDescriptor) {
-                               SimplePropertyDescriptor element = (SimplePropertyDescriptor)o;
-                           if (element.getId().equals("isExtends")) {
-                                       Boolean b = new Boolean(true);
-                                       d.setStructuralProperty(element,b);
-                                       assertEquals("DeclareParentsDeclaration's isExtends property should" +
-                                                       " now be a boolean",b,d.getStructuralProperty(element));
-                           }
-                       }
-               }
-       }
-       
        // -------------- DeclarePrecedenceDeclaration tests ---------------
 
        public void testNewDeclarePrecedenceDeclaration() {
@@ -1897,43 +1766,6 @@ public class AjASTTest extends TestCase {
                checkJLS3("aspect A{}aspect B{declare precedence: B,A;}",
                                19,23);
        }
-
-       
-       
-       // --------- Helper methods ----------
-       
-       private AjAST createAjAST() {
-               return createAjAST(AST.JLS3);
-       }
-       
-       private AjAST createAjAST(int astlevel) {
-               if (astlevel != AST.JLS2 && astlevel != AST.JLS3) {
-                       fail("need to pass AST.JLS2 or AST.JLS3 as an argument");
-               }
-               String source = "";
-               ASTParser parser = ASTParser.newParser(astlevel);
-               parser.setSource(source.toCharArray());
-               parser.setCompilerOptions(new HashMap());
-               CompilationUnit cu = (CompilationUnit) parser.createAST(null);
-               AST ast = cu.getAST();
-               assertTrue("the ast should be an instance of AjAST",ast instanceof AjAST);
-               return (AjAST)ast;
-       }
-       
-       private void checkJLS3(String source, int start, int length) {
-               ASTParser parser = ASTParser.newParser(AST.JLS3);
-               parser.setCompilerOptions(new HashMap());
-               parser.setSource(source.toCharArray());
-               CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
-               SourceRangeVisitor visitor = new SourceRangeVisitor();
-               cu2.accept(visitor);
-               int s = visitor.getStart();
-               int l = visitor.getLength();
-               assertTrue("Expected start position: "+ start + ", Actual:" + s,
-                               start == s);
-               assertTrue("Expected length: "+ length + ", Actual:" + l,
-                               length == l);
-       }
 }
 
 class SourceRangeVisitor extends AjASTVisitor {
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTestCase.java
new file mode 100644 (file)
index 0000000..4b74665
--- /dev/null
@@ -0,0 +1,57 @@
+/********************************************************************
+ * Copyright (c) 2006 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://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: Helen Hawkins   - initial implementation
+ *                              Matthew Webster - initial implementation
+ *******************************************************************/
+package org.aspectj.tools.ajc;
+
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.aspectj.org.eclipse.jdt.core.dom.AST;
+import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
+import org.aspectj.org.eclipse.jdt.core.dom.AjAST;
+import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
+
+public abstract class AjASTTestCase extends TestCase {
+
+       protected AjAST createAjAST() {
+               return createAjAST(AST.JLS3);
+       }
+
+       protected AjAST createAjAST(int astlevel) {
+               if (astlevel != AST.JLS2 && astlevel != AST.JLS3) {
+                       fail("need to pass AST.JLS2 or AST.JLS3 as an argument");
+               }
+               String source = "";
+               ASTParser parser = ASTParser.newParser(astlevel);
+               parser.setSource(source.toCharArray());
+               parser.setCompilerOptions(new HashMap());
+               CompilationUnit cu = (CompilationUnit) parser.createAST(null);
+               AST ast = cu.getAST();
+               assertTrue("the ast should be an instance of AjAST",ast instanceof AjAST);
+               return (AjAST)ast;
+       }
+
+       protected void checkJLS3(String source, int start, int length) {
+               ASTParser parser = ASTParser.newParser(AST.JLS3);
+               parser.setCompilerOptions(new HashMap());
+               parser.setSource(source.toCharArray());
+               CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
+               SourceRangeVisitor visitor = new SourceRangeVisitor();
+               cu2.accept(visitor);
+               int s = visitor.getStart();
+               int l = visitor.getLength();
+               assertTrue("Expected start position: "+ start + ", Actual:" + s,
+                               start == s);
+               assertTrue("Expected length: "+ length + ", Actual:" + l,
+                               length == l);
+       }
+
+}