aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core/testsrc
diff options
context:
space:
mode:
authoraclement <aclement>2006-01-27 15:50:36 +0000
committeraclement <aclement>2006-01-27 15:50:36 +0000
commit5d7f4e1f89c76fd54c40d513af4c19b8dd74f771 (patch)
tree799356d1b29b5690137dfbc22ac3d6722ea7d80e /org.aspectj.ajdt.core/testsrc
parent551b446bec83bef0f7df1f57353fdb4297bc14a6 (diff)
downloadaspectj-5d7f4e1f89c76fd54c40d513af4c19b8dd74f771.tar.gz
aspectj-5d7f4e1f89c76fd54c40d513af4c19b8dd74f771.zip
fixes for the AST - see comment #26 in 110465. Now exposes perclause/privileged information.
Diffstat (limited to 'org.aspectj.ajdt.core/testsrc')
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java51
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java96
2 files changed, 139 insertions, 8 deletions
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java
index 024a93906..500651404 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java
@@ -22,6 +22,7 @@ import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.AroundAdviceDeclaration;
+import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.Assignment;
import org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.Block;
@@ -48,6 +49,9 @@ import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.MethodDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.MethodInvocation;
import org.aspectj.org.eclipse.jdt.core.dom.NumberLiteral;
+import org.aspectj.org.eclipse.jdt.core.dom.PerCflow;
+import org.aspectj.org.eclipse.jdt.core.dom.PerObject;
+import org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin;
import org.aspectj.org.eclipse.jdt.core.dom.PointcutDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.PrimitiveType;
import org.aspectj.org.eclipse.jdt.core.dom.QualifiedName;
@@ -75,7 +79,9 @@ public class ASTVisitorTest extends TestCase {
public void testAspectWithCommentThenPointcut() {
check("aspect A{ /** */ pointcut x(); }","(compilationUnit(aspect(simpleName)(pointcut(simpleName))))");
}
-
+ public void testAPrivilegedAspect() {
+ check("privileged aspect AnAspect{}","(compilationUnit(privileged(aspect(simpleName))))");
+ }
// original tests
public void testAnInterface() {
check("interface AnInterface{}","(compilationUnit(interface(simpleName)))");
@@ -267,19 +273,19 @@ public class ASTVisitorTest extends TestCase {
}
public void testPerThis(){
check("aspect A perthis(a()) {pointcut a();}",
- "(compilationUnit(aspect(simpleName)(referencePointcut(simpleName))(pointcut(simpleName))))");
+ "(compilationUnit(aspect(simpleName)(perObject(referencePointcut(simpleName)))(pointcut(simpleName)))))");
}
public void testPerTarget(){
check("aspect A pertarget(a()) {pointcut a();}",
- "(compilationUnit(aspect(simpleName)(referencePointcut(simpleName))(pointcut(simpleName))))");
+ "(compilationUnit(aspect(simpleName)(perObject(referencePointcut(simpleName)))(pointcut(simpleName)))))");
}
public void testPerCFlow(){
check("aspect A percflow(a()) {pointcut a();}",
- "(compilationUnit(aspect(simpleName)(referencePointcut(simpleName))(pointcut(simpleName))))");
+ "(compilationUnit(aspect(simpleName)(perCflow(referencePointcut(simpleName)))(pointcut(simpleName)))))");
}
public void testPerCFlowBelow(){
check("aspect A percflowbelow(a()) {pointcut a();}",
- "(compilationUnit(aspect(simpleName)(referencePointcut(simpleName))(pointcut(simpleName))))");
+ "(compilationUnit(aspect(simpleName)(perCflow(referencePointcut(simpleName)))(pointcut(simpleName)))))");
}
private void check(String source, String expectedOutput){
@@ -365,10 +371,13 @@ class TestVisitor extends AjASTVisitor {
public boolean visit(TypeDeclaration node) {
if (((AjTypeDeclaration)node).isAspect()) {
+ if (((AspectDeclaration) node).isPrivileged()){
+ b.append("(privileged");
+ }
b.append("(aspect"); //$NON-NLS-1$
- //if (((AspectDeclaration)node).getPerClause() != null){
- // b.append("{" + ((AspectDeclaration)node).getPerClause() + "}");
- //}
+// if (((AspectDeclaration)node).getPerClause() != null){
+// b.append("{" + ((AspectDeclaration)node).getPerClause() + "}");
+// }
} else if (node.isInterface()){
b.append("(interface"); // $NON-NLS-1$
} else {
@@ -377,6 +386,11 @@ class TestVisitor extends AjASTVisitor {
return isVisitingChildren();
}
public void endVisit(TypeDeclaration node) {
+ if (((AjTypeDeclaration)node).isAspect())
+ if (((AspectDeclaration) node).isPrivileged()
+ || ((AspectDeclaration)node).getPerClause() != null) {
+ b.append(")");
+ }
b.append(")"); //$NON-NLS-1$
}
public boolean visit(PointcutDeclaration node) {
@@ -669,4 +683,25 @@ class TestVisitor extends AjASTVisitor {
public void endVisit(SignaturePattern node) {
b.append(")"); //$NON-NLS-1$
}
+ public boolean visit(PerObject node) {
+ b.append("(perObject");
+ return isVisitingChildren();
+ }
+ public boolean visit(PerCflow node) {
+ b.append("(perCflow");
+ return isVisitingChildren();
+ }
+ public boolean visit(PerTypeWithin node) {
+ b.append("(perTypeWithin");
+ return isVisitingChildren();
+ }
+ public void endVisit(PerObject node) {
+ b.append(")"); //$NON-NLS-1$
+ }
+ public void endVisit(PerCflow node) {
+ b.append(")"); //$NON-NLS-1$
+ }
+ public void endVisit(PerTypeWithin node) {
+ b.append(")"); //$NON-NLS-1$
+ }
}
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java
index b72cf317c..dd27dca0f 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java
@@ -400,6 +400,90 @@ public class AjASTTest extends TestCase {
assertNotNull("a new AspectDeclaration should have been created",ad);
}
+ public void testPropertyDescriptorsForAspectDeclaration() {
+ AjAST ajast = createAjAST();
+ AspectDeclaration d = ajast.newAspectDeclaration();
+ List props = AspectDeclaration.propertyDescriptors(AST.JLS3);
+ boolean foundJavadoc = false;
+ boolean foundPerClause = false;
+ boolean foundIsPrivileged = false;
+ for (Iterator iter = props.iterator(); iter.hasNext();) {
+ Object o = iter.next();
+ if ((o instanceof ChildPropertyDescriptor)) {
+ ChildPropertyDescriptor element = (ChildPropertyDescriptor)o;
+ String id = element.getId();
+ if (id.equals("javadoc")) {
+ foundJavadoc = true;
+ } else if (id.equals("perClause")) {
+ foundPerClause = true;
+ }
+ } else if ((o instanceof SimplePropertyDescriptor)
+ && ((SimplePropertyDescriptor)o).getId().equals("privileged")) {
+ foundIsPrivileged = true;
+ }
+ }
+ assertTrue("AspectDeclaration should have a javadoc PropertyDescriptor",foundJavadoc);
+ assertTrue("AspectDeclaration should have a perClause PropertyDescriptor",foundPerClause);
+ assertTrue("AspectDeclaration should have an isPrivileged PropertyDescriptor",foundIsPrivileged);
+ }
+
+ public void testCloneAspectDeclaration() {
+ AjAST ajast = createAjAST();
+ AspectDeclaration d = ajast.newAspectDeclaration();
+ d.setPerClause(ajast.newPerTypeWithin());
+ d.setPrivileged(true);
+ AspectDeclaration copy = (AspectDeclaration)ASTNode.copySubtree(ajast,d);
+ assertNotNull("the AspectDeclaration clone should have a perClause set",
+ copy.getPerClause());
+ assertTrue("the AspectDeclaration clone should be a 'privileged'",
+ 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
* and setting of this property
@@ -414,6 +498,18 @@ public class AjASTTest extends TestCase {
pcf,ad.getPerClause());
}
+ /**
+ * AsepctDeclarations's have a isPrivileged property - test the getting
+ * and setting of this property
+ */
+ public void testSetPrivilegedInAspectDeclaration() {
+ AjAST ajast = createAjAST();
+ AspectDeclaration ad = ajast.newAspectDeclaration();
+ assertFalse("by default the aspect should not be privileged",ad.isPrivileged());
+ ad.setPrivileged(true);
+ assertTrue("the aspect should now privileged",ad.isPrivileged());
+ }
+
// -------------- AfterAdviceDeclaration tests ---------------
public void testNewAfterAdviceDeclaration() {