diff options
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/dom/AjASTFactory.java (renamed from org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java) | 4 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjAST.java | 10 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java | 5 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjTypeDeclaration.java | 2 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AspectDeclaration.java | 132 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java | 51 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjASTTest.java | 96 | ||||
-rw-r--r-- | org.eclipse.jdt.core/jdtcore-for-aspectj-src.zip | bin | 3709255 -> 3709259 bytes | |||
-rw-r--r-- | org.eclipse.jdt.core/jdtcore-for-aspectj.jar | bin | 5491596 -> 5491661 bytes |
9 files changed, 265 insertions, 35 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/dom/AjASTFactory.java index 41ae03e6b..68084e7e4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/dom/AjASTFactory.java @@ -8,8 +8,10 @@ * Contributors: IBM Corporation - initial API and implementation * Helen Hawkins - iniital version *******************************************************************/ -package org.aspectj.org.eclipse.jdt.core.dom; +package org.aspectj.ajdt.core.dom; +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.ASTParser.IASTFactory; public class AjASTFactory implements IASTFactory { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjAST.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjAST.java index fedfa8cd1..39d3782e1 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjAST.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjAST.java @@ -99,16 +99,20 @@ public class AjAST extends AST { * Creates an unparented aspect declaration node owned by this AST. * The name of the aspect is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; - * an empty body; and a null perclause + * an empty body; a null perclause; and is not privileged * <p> * To set the perclause, use this method and then call * <code>AspectDeclaration.setPerClause(ASTNode)</code>. * </p> - * + * <p> + * To create a privileged aspect, use this method and then call + * <code>AspectDeclaration.setPrivileged(true)</code>. + * </p> + * * @return a new unparented aspect declaration node */ public AspectDeclaration newAspectDeclaration() { - AspectDeclaration result = new AspectDeclaration(this,null); + AspectDeclaration result = new AspectDeclaration(this); return result; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java index d7e1a7124..fce7e7c73 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java @@ -2117,10 +2117,11 @@ public class AjASTConverter extends ASTConverter { //////////////// ajh02: added if (typeDeclaration instanceof AspectDeclaration){ org.aspectj.weaver.patterns.PerClause perClause = ((AspectDeclaration)typeDeclaration).perClause; + boolean isPrivileged = ((AspectDeclaration)typeDeclaration).isPrivileged; if (perClause == null){ - typeDecl = new org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,null); + typeDecl = new org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,null, isPrivileged); } else { - typeDecl = new org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,convert(perClause)); + typeDecl = new org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,convert(perClause), isPrivileged); } } /////////////////////////////// diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjTypeDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjTypeDeclaration.java index d76427d7f..b3d7e12ee 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjTypeDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjTypeDeclaration.java @@ -76,7 +76,7 @@ public class AjTypeDeclaration extends TypeDeclaration { /* (omit javadoc for this method) * Method declared on ASTNode. */ - final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { + boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == ASPECT_PROPERTY) { if (get) { return isAspect(); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AspectDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AspectDeclaration.java index 5a45ec9ca..65e550f87 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AspectDeclaration.java @@ -16,41 +16,63 @@ import java.util.List; /** * AspectDeclaration DOM AST node. - * has: - * everything a TypeDeclaration has. * - * This class could probably do with some work. + * Has everything an AjTypeDeclaration has plus: + * an ASTNode called 'perClause' + * a boolean called 'privileged' + * * @author ajh02 * */ - public class AspectDeclaration extends AjTypeDeclaration { - - protected ASTNode perClause = null; // stays null if the aspect is an _implicit_ persingleton() - + public static final ChildPropertyDescriptor PERCLAUSE_PROPERTY = new ChildPropertyDescriptor(AspectDeclaration.class, "perClause", ASTNode.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$ + + public static final SimplePropertyDescriptor PRIVILEGED_PROPERTY = + new SimplePropertyDescriptor(AspectDeclaration.class, "privileged", boolean.class, MANDATORY); //$NON-NLS-1$ - AspectDeclaration(AST ast, ASTNode perClause) { + static { + List temporary = new ArrayList(); + createPropertyList(AspectDeclaration.class, temporary); + temporary.addAll(PROPERTY_DESCRIPTORS_2_0); + addProperty(PERCLAUSE_PROPERTY, temporary); + addProperty(PRIVILEGED_PROPERTY, temporary); + PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(temporary); + + temporary.clear(); + createPropertyList(AspectDeclaration.class, temporary); + temporary.addAll(PROPERTY_DESCRIPTORS_3_0); + addProperty(PERCLAUSE_PROPERTY, temporary); + addProperty(PRIVILEGED_PROPERTY, temporary); + PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(temporary); + } + + protected ASTNode perClause = null; // stays null if the aspect is an _implicit_ persingleton() + /** + * <code>true</code> for a privileged aspect, <code>false</code> otherwise. + * Defaults to not privileged. + */ + private boolean isPrivileged = false; + + AspectDeclaration(AST ast) { super(ast); + } + + AspectDeclaration(AST ast, ASTNode perClause) { + this(ast); this.perClause = perClause; setAspect(true); } - public ASTNode getPerClause(){ - return perClause; - } - - public void setPerClause(ASTNode perClause) { - if (perClause == null) { - throw new IllegalArgumentException(); - } - ASTNode oldChild = this.perClause; - preReplaceChild(oldChild, perClause, PERCLAUSE_PROPERTY); - this.perClause = perClause; - postReplaceChild(oldChild, perClause, PERCLAUSE_PROPERTY); + AspectDeclaration(AST ast, ASTNode perClause, boolean isPrivileged) { + this(ast, perClause); + this.isPrivileged = isPrivileged; } + /* (omit javadoc for this method) + * Method declared on ASTNode. + */ ASTNode clone0(AST target) { AspectDeclaration result = new AspectDeclaration(target, perClause); result.setSourceRange(this.getStartPosition(), this.getLength()); @@ -65,6 +87,7 @@ public class AspectDeclaration extends AjTypeDeclaration { } result.setInterface(isInterface()); result.setAspect(isAspect()); + result.setPrivileged(isPrivileged()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); @@ -81,6 +104,9 @@ public class AspectDeclaration extends AjTypeDeclaration { return result; } + /* (omit javadoc for this method) + * Method declared on ASTNode. + */ void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { @@ -107,6 +133,72 @@ public class AspectDeclaration extends AjTypeDeclaration { visitor.endVisit(this); } + /* (omit javadoc for this method) + * Method declared on ASTNode and AjTypeDeclaration. + */ + final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { + if (property == PRIVILEGED_PROPERTY) { + if (get) { + return isPrivileged(); + } else { + setPrivileged(value); + return false; + } + } + // allow default implementation to flag the error + return super.internalGetSetBooleanProperty(property, get, value); + } + + /* + * (omit javadoc for this method) + * Method declared on ASTNode. + */ + final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,boolean get, ASTNode child) { + if (property == PERCLAUSE_PROPERTY) { + if (get) { + return getPerClause(); + } else { + setPerClause((ASTNode) child); + return null; + } + } + return super.internalGetSetChildProperty(property,get,child); + } + + public ASTNode getPerClause(){ + return perClause; + } + + public void setPerClause(ASTNode perClause) { + if (perClause == null) { + throw new IllegalArgumentException(); + } + ASTNode oldChild = this.perClause; + preReplaceChild(oldChild, perClause, PERCLAUSE_PROPERTY); + this.perClause = perClause; + postReplaceChild(oldChild, perClause, PERCLAUSE_PROPERTY); + } + + /** + * Returns whether this aspect is a privileged one. + * + * @return <code>true</code> if this is a privileged aspect + * declaration, and <code>false</code> otherwise. + */ + public boolean isPrivileged() { + return this.isPrivileged; + } + /** + * Sets whether this aspect is a privileged one + * + * @param isPrivileged <code>true</code> if this is a privileged aspect + * declaration, and <code>false</code> otherwise. + */ + public void setPrivileged(boolean isPrivileged) { + preValueChange(PRIVILEGED_PROPERTY); + this.isPrivileged = isPrivileged; + postValueChange(PRIVILEGED_PROPERTY); + } public List getAdvice() { // ajh02: method added 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() { diff --git a/org.eclipse.jdt.core/jdtcore-for-aspectj-src.zip b/org.eclipse.jdt.core/jdtcore-for-aspectj-src.zip Binary files differindex 0922eb93e..cd0e8f08d 100644 --- a/org.eclipse.jdt.core/jdtcore-for-aspectj-src.zip +++ b/org.eclipse.jdt.core/jdtcore-for-aspectj-src.zip diff --git a/org.eclipse.jdt.core/jdtcore-for-aspectj.jar b/org.eclipse.jdt.core/jdtcore-for-aspectj.jar Binary files differindex b90580df6..f9b149bc1 100644 --- a/org.eclipse.jdt.core/jdtcore-for-aspectj.jar +++ b/org.eclipse.jdt.core/jdtcore-for-aspectj.jar |