@@ -525,6 +525,14 @@ public class AjASTConverter extends ASTConverter { | |||
} else { | |||
pointcutDecl.setDesignator(new org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut(this.ast,pointcutDeclaration.toString())); | |||
} | |||
org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = pointcutDeclaration.arguments; | |||
if (parameters != null) { | |||
int parametersLength = parameters.length; | |||
for (int i = 0; i < parametersLength; i++) { | |||
pointcutDecl.parameters().add(convert(parameters[i])); | |||
} | |||
} | |||
// The javadoc comment is now got from list store in compilation unit declaration | |||
if (this.resolveBindings) { | |||
recordNodes(pointcutDecl, pointcutDeclaration); |
@@ -514,7 +514,15 @@ public class AjNaiveASTFlattener extends AjASTVisitor { | |||
printIndent(); | |||
buffer.append(" pointcut "); | |||
node.getName().accept(this); | |||
buffer.append("():"); | |||
buffer.append("("); | |||
List parameters = node.parameters(); | |||
for (Iterator iter = parameters.iterator(); iter.hasNext();) { | |||
SingleVariableDeclaration element = (SingleVariableDeclaration) iter.next(); | |||
buffer.append(element.getType().toString()+" "+element.getName()); | |||
if (iter.hasNext()) | |||
buffer.append(", "); | |||
} | |||
buffer.append("):"); | |||
buffer.append(((DefaultPointcut)node.getDesignator()).getDetail()); | |||
buffer.append(";\n"); | |||
return false; |
@@ -19,6 +19,7 @@ import java.util.List; | |||
* has: | |||
* a name | |||
* an optional pointcut designator called 'designator' | |||
* a SingleVariableDeclaration list called 'parameters' | |||
* javadoc | |||
* modifiers | |||
* | |||
@@ -36,6 +37,12 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
private PointcutDesignator pointcutDesignator = null; | |||
public static final ChildPropertyDescriptor DESIGNATOR_PROPERTY = | |||
new ChildPropertyDescriptor(PointcutDeclaration.class, "designator", PointcutDesignator.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$ | |||
/** | |||
* The "parameters" structural property of this node type. | |||
*/ | |||
public static final ChildListPropertyDescriptor PARAMETERS_PROPERTY = | |||
new ChildListPropertyDescriptor(PointcutDeclaration.class, "parameters", SingleVariableDeclaration.class, CYCLE_RISK); //$NON-NLS-1$ | |||
public PointcutDesignator getDesignator() { | |||
return this.pointcutDesignator; | |||
@@ -110,20 +117,24 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
private static final List PROPERTY_DESCRIPTORS_3_0; | |||
static { | |||
List propertyList = new ArrayList(5); | |||
List propertyList = new ArrayList(6); | |||
createPropertyList(PointcutDeclaration.class, propertyList); | |||
addProperty(JAVADOC_PROPERTY, propertyList); | |||
addProperty(MODIFIERS_PROPERTY, propertyList); | |||
addProperty(NAME_PROPERTY, propertyList); | |||
addProperty(DESIGNATOR_PROPERTY, propertyList); | |||
addProperty(PARAMETERS_PROPERTY, propertyList); | |||
PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList); | |||
propertyList = new ArrayList(5); | |||
propertyList = new ArrayList(6); | |||
createPropertyList(PointcutDeclaration.class, propertyList); | |||
addProperty(JAVADOC_PROPERTY, propertyList); | |||
addProperty(MODIFIERS2_PROPERTY, propertyList); | |||
addProperty(NAME_PROPERTY, propertyList); | |||
addProperty(DESIGNATOR_PROPERTY, propertyList); | |||
addProperty(PARAMETERS_PROPERTY, propertyList); | |||
PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList); | |||
} | |||
@@ -161,6 +172,8 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
super(ast); | |||
} | |||
protected ASTNode.NodeList parameters = | |||
new ASTNode.NodeList(PARAMETERS_PROPERTY); | |||
/* (omit javadoc for this method) | |||
* Method declared on ASTNode. | |||
@@ -225,6 +238,9 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
if (property == MODIFIERS2_PROPERTY) { | |||
return modifiers(); | |||
} | |||
if (property == PARAMETERS_PROPERTY) { | |||
return parameters(); | |||
} | |||
// allow default implementation to flag the error | |||
return super.internalGetChildListProperty(property); | |||
} | |||
@@ -272,7 +288,11 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); | |||
} | |||
result.setName((SimpleName) getName().clone(target)); | |||
result.setDesignator((PointcutDesignator) getDesignator().clone(target)); | |||
if (getDesignator() != null) { | |||
result.setDesignator((PointcutDesignator) getDesignator().clone(target)); | |||
} | |||
result.parameters().addAll( | |||
ASTNode.copySubtrees(target, parameters())); | |||
return result; | |||
} | |||
@@ -299,16 +319,28 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
} | |||
acceptChild(ajvis, getName()); | |||
acceptChild(ajvis, getDesignator()); | |||
acceptChildren(visitor, this.parameters); | |||
} | |||
ajvis.endVisit(this); | |||
} | |||
} | |||
/** | |||
* Returns the live ordered list of method parameter declarations for this | |||
* method declaration. | |||
* | |||
* @return the live list of method parameter declarations | |||
* (element type: <code>SingleVariableDeclaration</code>) | |||
*/ | |||
public List parameters() { | |||
return this.parameters; | |||
} | |||
/* (omit javadoc for this method) | |||
* Method declared on ASTNode. | |||
*/ | |||
int memSize() { | |||
return super.memSize() + 2 * 4; | |||
return super.memSize() + 3 * 4; | |||
} | |||
/* (omit javadoc for this method) | |||
@@ -320,6 +352,7 @@ public class PointcutDeclaration extends BodyDeclaration { | |||
+ (this.optionalDocComment == null ? 0 : getJavadoc().treeSize()) | |||
+ (this.pointcutName == null ? 0 : getName().treeSize()) | |||
+ (this.modifiers == null ? 0 : this.modifiers.listSize()) | |||
+ this.parameters.listSize() | |||
+ (this.pointcutDesignator == null ? 0 : getDesignator().treeSize()); | |||
} | |||
} |
@@ -180,6 +180,38 @@ public class ASTVisitorTest extends TestCase { | |||
"(compilationUnit(aspect(simpleName)(pointcut(simpleName))))"); | |||
} | |||
public void testPointcutWithoutArguments(){ | |||
check("aspect A {pointcut a(): adviceexecution();}", | |||
"(compilationUnit(aspect(simpleName)(pointcut(simpleName))))"); | |||
} | |||
public void testPointcutWithOnePrimitiveArgument(){ | |||
check("aspect A {pointcut a(int a): adviceexecution();}", | |||
"(compilationUnit(aspect(simpleName)(pointcut(simpleName)(primitiveType)(simpleName))))"); | |||
} | |||
public void testPointcutWithTwoPrimitiveArguments(){ | |||
check("aspect A {pointcut a(int a, double b): adviceexecution();}", | |||
"(compilationUnit(aspect(simpleName)(pointcut" + | |||
"(simpleName)(primitiveType)(simpleName)(primitiveType)" + | |||
"(simpleName))))"); | |||
} | |||
public void testPointcutWithOneTypedArgument(){ | |||
check("aspect A {pointcut a(A a): adviceexecution();}", | |||
"(compilationUnit(aspect(simpleName)(pointcut" + | |||
"(simpleName)(simpleName)" + | |||
"(simpleName))))"); | |||
} | |||
public void testPointcutWithTwoTypedArgument(){ | |||
check("aspect A {pointcut a(A a, B b): adviceexecution();}", | |||
"(compilationUnit(aspect(simpleName)(pointcut" + | |||
"(simpleName)(simpleName)" + | |||
"(simpleName)(simpleName)" + | |||
"(simpleName))))"); | |||
} | |||
public void testFieldITD(){ | |||
check("class A {}aspect B {int A.a;}", | |||
"(compilationUnit(class(simpleName))(aspect(simpleName)(fieldITD(primitiveType)(simpleName))))"); |
@@ -45,6 +45,7 @@ import org.aspectj.org.eclipse.jdt.core.dom.DeclareSoftDeclaration; | |||
import org.aspectj.org.eclipse.jdt.core.dom.DeclareWarningDeclaration; | |||
import org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut; | |||
import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern; | |||
import org.aspectj.org.eclipse.jdt.core.dom.IExtendedModifier; | |||
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration; | |||
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration; | |||
import org.aspectj.org.eclipse.jdt.core.dom.NotPointcut; | |||
@@ -393,6 +394,131 @@ public class AjASTTest extends TestCase { | |||
"the ReferencePointcut",rp,pd.getDesignator()); | |||
} | |||
public void testGetAndSetPointcutArguments(){ | |||
AjAST ajast = createAjAST(); | |||
PointcutDeclaration pd = ajast.newPointcutDeclaration(); | |||
assertEquals("by default the number of arguments is zero",pd.parameters().size(), 0); | |||
List l = pd.parameters(); | |||
assertEquals("there shouldn't be any arguments associated with" + | |||
"the pointcut yet",0,l.size()); | |||
SingleVariableDeclaration p1 = ajast.newSingleVariableDeclaration(); | |||
l.add(p1); | |||
assertEquals("there should be one parameter associated with" + | |||
"the pointcut",1,pd.parameters().size()); | |||
assertEquals("there should be a SingleVariableDeclaration associated with" + | |||
"the pointcut",p1,pd.parameters().get(0)); | |||
} | |||
public void testPropertyDescriptorsForPointcutDeclaration() { | |||
AjAST ajast = createAjAST(); | |||
PointcutDeclaration d = ajast.newPointcutDeclaration(); | |||
List props = PointcutDeclaration.propertyDescriptors(AST.JLS3); | |||
boolean foundJavadoc = false; | |||
boolean foundModifiers = false; | |||
boolean foundName = false; | |||
boolean foundParamList = false; | |||
boolean foundDesignator = 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("designator")) { | |||
foundDesignator = true; | |||
} else if (id.equals("name")) { | |||
foundName = true; | |||
} else { | |||
fail("unknown PropertyDescriptor associated with PointcutDeclaration: " + element.getId()); | |||
} | |||
} else if (o instanceof ChildListPropertyDescriptor) { | |||
ChildListPropertyDescriptor element = (ChildListPropertyDescriptor)o; | |||
if (element.getId().equals("parameters")) { | |||
foundParamList= true; | |||
} else if (element.getId().equals("modifiers")) { | |||
foundModifiers = true; | |||
} | |||
} else { | |||
fail("unknown PropertyDescriptor associated with PointcutDeclaration: " + o); | |||
} | |||
} | |||
assertTrue("PointcutDeclaration should have a javadoc PropertyDescriptor",foundJavadoc); | |||
assertTrue("PointcutDeclaration should have a designator PropertyDescriptor",foundDesignator); | |||
assertTrue("PointcutDeclaration should have an name PropertyDescriptor",foundName); | |||
assertTrue("PointcutDeclaration should have a parameters PropertyDescriptor",foundParamList); | |||
assertTrue("PointcutDeclaration should have a modifiers PropertyDescriptor",foundModifiers); | |||
} | |||
public void testClonePointcutDeclaration() { | |||
AjAST ajast = createAjAST(); | |||
PointcutDeclaration d = ajast.newPointcutDeclaration(); | |||
d.setName(ajast.newSimpleName("pointcut_name")); | |||
d.parameters().add(ajast.newSingleVariableDeclaration()); | |||
PointcutDeclaration copy = (PointcutDeclaration)ASTNode.copySubtree(ajast,d); | |||
assertEquals("there should be one parameter associated with" + | |||
"the pointcut copy",1,copy.parameters().size()); | |||
assertEquals("the PointcutDeclaration clone should have the name ", "pointcut_name", | |||
copy.getName().toString()); | |||
} | |||
public void testInternalPointcutDeclaration() { | |||
AjAST ajast = createAjAST(); | |||
PointcutDeclaration d = ajast.newPointcutDeclaration(); | |||
List props = PointcutDeclaration.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("name")) { | |||
assertNotNull("PointcutDeclaration's " + element.getId() + " property" + | |||
" should not be null since it is lazily created", | |||
d.getStructuralProperty(element)); | |||
} else { | |||
assertNull("PointcutDeclaration'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("PointcutDeclaration's " + element.getId() + " property" + | |||
"should not be null since it is a list", | |||
d.getStructuralProperty(element)); | |||
boolean isIExtendedModifier = element.getElementType().equals(IExtendedModifier.class); | |||
boolean isSingleVariable = element.getElementType().equals(SingleVariableDeclaration.class); | |||
assertTrue("should only be able to put SingleVariableDeclaration's" + | |||
" (which itself has node type IExtendedModifier) into the list", | |||
isIExtendedModifier || isSingleVariable); | |||
} else if (o instanceof SimplePropertyDescriptor) { | |||
SimplePropertyDescriptor element = (SimplePropertyDescriptor)o; | |||
assertNotNull("PointcutDeclaration's " + element.getId() + " property" + | |||
"should not be null since it is a boolean", | |||
d.getStructuralProperty(element)); | |||
} else { | |||
fail("unknown PropertyDescriptor associated with PointcutDeclaration: " + o); | |||
} | |||
} | |||
for (Iterator iter = props.iterator(); iter.hasNext();) { | |||
Object o = iter.next(); | |||
if (o instanceof ChildPropertyDescriptor) { | |||
ChildPropertyDescriptor element = (ChildPropertyDescriptor) o; | |||
if (element.getId().equals("designator")) { | |||
ReferencePointcut rp = ajast.newReferencePointcut(); | |||
d.setStructuralProperty(element,rp); | |||
assertEquals("PointcutDeclaration's designator property should" + | |||
" now be a ReferencePointcut",rp,d.getStructuralProperty(element)); | |||
} else if (element.getId().equals("javadoc")) { | |||
// do nothing since makes no sense to have javadoc | |||
} else if (element.getId().equals("name")) { | |||
SimpleName sn = ajast.newSimpleName("p"); | |||
d.setStructuralProperty(element,sn); | |||
assertEquals("PointcutDeclaration's name property should" + | |||
" now be a SimpleName",sn,d.getStructuralProperty(element)); | |||
} | |||
} | |||
} | |||
} | |||
// -------------- AspectDeclaration tests --------------- | |||
public void testNewAspectDeclaration() { |
@@ -0,0 +1,78 @@ | |||
/******************************************************************** | |||
* 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 | |||
* Eduardo Piveta - initial version | |||
* Helen Hawkins - ammended to fit within JUnit framework | |||
*******************************************************************/ | |||
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.AjNaiveASTFlattener; | |||
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit; | |||
public class AjNaiveASTFlattenerTest extends TestCase { | |||
public void testNoPointcutArgs() { | |||
check("public aspect A { pointcut y(): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y():call(* *.*(..));\n}\n"); | |||
} | |||
public void testOneIntPointcutArg() { | |||
check("public aspect A { pointcut y(int a): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(int a):call(* *.*(..));\n}\n"); | |||
} | |||
public void testOneIntOneDoublePointcutArg() { | |||
check("public aspect A { pointcut y(int a, double b): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(int a, double b):call(* *.*(..));\n}\n"); | |||
} | |||
public void testOneTypedPointcutArg() { | |||
check("public aspect A { pointcut y(X a): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(X a):call(* *.*(..));\n}\n"); | |||
} | |||
public void testTwoTypedPointcutArgs() { | |||
check("public aspect A { pointcut y(X a, X b): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(X a, X b):call(* *.*(..));\n}\n"); | |||
} | |||
public void testOneTypedAndOneIntPointcutArg() { | |||
check("public aspect A { pointcut y(X a, int b): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(X a, int b):call(* *.*(..));\n}\n"); | |||
} | |||
public void testOneIntAndOneTypedPointcutArg() { | |||
check("public aspect A { pointcut y(int a, X b): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(int a, X b):call(* *.*(..));\n}\n"); | |||
} | |||
public void testOneIntOneDoubleAndOneTypedPointcutArg() { | |||
check("public aspect A { pointcut y(int a, double b, Y c): call(* *.*(..));}", | |||
"public aspect A {\n pointcut y(int a, double b, Y c):call(* *.*(..));\n}\n"); | |||
} | |||
private void check(String source, String expectedOutput) { | |||
ASTParser parser = ASTParser.newParser(AST.JLS2); | |||
parser.setCompilerOptions(new HashMap()); | |||
parser.setSource(source.toCharArray()); | |||
CompilationUnit cu2 = (CompilationUnit) parser.createAST(null); | |||
AjNaiveASTFlattener visitor = new AjNaiveASTFlattener(); | |||
cu2.accept(visitor); | |||
String result = visitor.getResult(); | |||
System.err.println(result); | |||
assertTrue("Expected:\n"+ expectedOutput + "====Actual:\n" + result, | |||
expectedOutput.equals(result)); | |||
} | |||
} |
@@ -29,6 +29,7 @@ public class AjcTests extends TestCase { | |||
suite.addTestSuite(ASTVisitorTest.class); | |||
suite.addTestSuite(ASTitdTest.class); | |||
suite.addTestSuite(AjASTTest.class); | |||
suite.addTestSuite(AjNaiveASTFlattenerTest.class); | |||
return suite; | |||
} | |||