aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-10-25 13:04:26 +0000
committeravasseur <avasseur>2005-10-25 13:04:26 +0000
commite1d674faa6a8f4d3f9ca051b88aab36d635eaf1b (patch)
tree09d1432ba5c2a3895c63c0870efd2cf401e844ba
parentcc6862f2b54c3333d645a0efb28f5366b0a2bcc3 (diff)
downloadaspectj-e1d674faa6a8f4d3f9ca051b88aab36d635eaf1b.tar.gz
aspectj-e1d674faa6a8f4d3f9ca051b88aab36d635eaf1b.zip
ajdtcore for abstract @Pointcut
-rw-r--r--loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java18
-rw-r--r--loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java2
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java36
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java42
-rw-r--r--tests/java5/ataspectj/ataspectj/ConcreteAtAspectTest.java2
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml2
6 files changed, 64 insertions, 38 deletions
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
index ebfdce180..cdccc0e09 100644
--- a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
+++ b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
@@ -113,23 +113,6 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
messageHandler = bcelWorld.getMessageHandler();
// after adding aspects
weaver.prepareForWeave();
-// // weave and flush what was registered so far
-// for (Iterator iterator = m_codeGens.iterator(); iterator.hasNext();) {
-// ConcreteAspectCodeGen concreteAspectCodeGen = (ConcreteAspectCodeGen) iterator.next();
-// byte[] partiallyWoven = concreteAspectCodeGen.getBytes(this);
-// this.generatedClassHandler.acceptClass(
-// concreteAspectCodeGen.m_concreteAspect.name,
-// partiallyWoven
-// );
-// ResolvedType aspect = weaver.addLibraryAspect(concreteAspectCodeGen.m_concreteAspect.name);
-// //generate key for SC
-// String aspectCode = readAspect(concreteAspectCodeGen.m_concreteAspect.name, loader);
-// if(namespace==null){
-// namespace=new StringBuffer(aspectCode);
-// }else{
-// namespace = namespace.append(";"+aspectCode);
-// }
-// }
}
}
@@ -161,7 +144,6 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
Enumeration xmls = weavingContext.getResources(st.nextToken());
// System.out.println("? registerDefinitions: found-aop.xml=" + xmls.hasMoreElements() + ", loader=" + loader);
-
while (xmls.hasMoreElements()) {
URL xml = (URL) xmls.nextElement();
MessageUtil.info(messageHandler, "using " + xml.getFile());
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java b/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
index b90ddeda0..85b718ac5 100644
--- a/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
+++ b/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
@@ -152,7 +152,7 @@ public class ConcreteAspectCodeGen {
if ("()V".equals(method.getSignature())) {
elligibleAbstractions.add(method.getName());
} else {
- reportError("Abstract member '" + method.getName() + "' cannot be concretized as a pointcut (illegal signature): " + stringify());
+ reportError("Abstract method '" + method.getName() + "' cannot be concretized as a pointcut (illegal signature, must have no arguments, must return void): " + stringify());
return false;
}
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java
index abe77d9f0..533919a92 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java
@@ -88,12 +88,17 @@ public class PointcutDeclaration extends AjMethodDeclaration {
if (Modifier.isAbstract(this.declaredModifiers)) {
if (!(typeDec instanceof AspectDeclaration)) {
- typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
- "The abstract pointcut " + new String(declaredName) +
- " can only be defined in an aspect");
- ignoreFurtherInvestigation = true;
- return;
- } else if (!Modifier.isAbstract(typeDec.modifiers)) {
+ // check for @Aspect
+ if (isAtAspectJ(typeDec)) {
+ ;//no need to check abstract class as JDT does that
+ } else {
+ typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
+ "The abstract pointcut " + new String(declaredName) +
+ " can only be defined in an aspect");
+ ignoreFurtherInvestigation = true;
+ return;
+ }
+ } else if (!Modifier.isAbstract(typeDec.modifiers)) {
typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
"The abstract pointcut " + new String(declaredName) +
" can only be defined in an abstract aspect");
@@ -107,9 +112,22 @@ public class PointcutDeclaration extends AjMethodDeclaration {
pointcutDesignator.postParse(typeDec, this);
}
}
-
-
- /**
+
+ private boolean isAtAspectJ(TypeDeclaration typeDec) {
+ if (typeDec.annotations == null)
+ return false;
+
+ for (int i = 0; i < typeDec.annotations.length; i++) {
+ Annotation annotation = typeDec.annotations[i];
+ if ("Lorg/aspectj/lang/annotation/Aspect;".equals(new String(annotation.resolvedType.signature()))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
* Called from the AtAspectJVisitor to create the @Pointcut annotation
* (and corresponding method) for this pointcut
*
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java
index 7aae00ecd..3a7fe62e3 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java
@@ -490,8 +490,13 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
String pointcutExpression = getStringLiteralFor("value",ajAnnotations.pointcutAnnotation,pcLocation);
try {
ISourceContext context = new EclipseSourceContext(unit.compilationResult,pcLocation[0]);
- Pointcut pc = new PatternParser(pointcutExpression,context).parsePointcut();
- pcDecl.pointcutDesignator = new PointcutDesignator(pc);
+ Pointcut pc = null;//abstract
+ if (pointcutExpression == null || pointcutExpression.length() == 0) {
+ ;//will have to ensure abstract ()V method
+ } else {
+ pc = new PatternParser(pointcutExpression,context).parsePointcut();
+ }
+ pcDecl.pointcutDesignator = (pc==null)?null:new PointcutDesignator(pc);
pcDecl.setGenerateSyntheticPointcutMethod();
TypeDeclaration onType = (TypeDeclaration) typeStack.peek();
pcDecl.postParse(onType);
@@ -506,11 +511,14 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
// bindings[i] = new FormalBinding(type, name, i, arg.sourceStart, arg.sourceEnd, "unknown");
// }
swap(onType,methodDeclaration,pcDecl);
- pc.resolve(new EclipseScope(bindings,methodDeclaration.scope));
- HasIfPCDVisitor ifFinder = new HasIfPCDVisitor();
- pc.traverse(ifFinder, null);
- containsIfPcd = ifFinder.containsIfPcd;
- } catch(ParserException pEx) {
+ if (pc != null) {
+ // has an expression
+ pc.resolve(new EclipseScope(bindings,methodDeclaration.scope));
+ HasIfPCDVisitor ifFinder = new HasIfPCDVisitor();
+ pc.traverse(ifFinder, null);
+ containsIfPcd = ifFinder.containsIfPcd;
+ }
+ } catch(ParserException pEx) {
methodDeclaration.scope.problemReporter().parseError(
pcLocation[0] + pEx.getLocation().getStart(),
pcLocation[0] + pEx.getLocation().getEnd() ,
@@ -543,7 +551,25 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
methodDeclaration.returnType.sourceEnd,
"Pointcuts without an if() expression should have an empty method body");
}
- }
+
+ if (pcDecl.pointcutDesignator == null) {
+ if (Modifier.isAbstract(methodDeclaration.modifiers)
+ //those 2 checks makes sense for aop.xml concretization but NOT for regular abstraction of pointcut
+ //&& returnsVoid
+ //&& (methodDeclaration.arguments == null || methodDeclaration.arguments.length == 0)) {
+ ) {
+ ;//fine
+ } else {
+ methodDeclaration.scope.problemReporter().signalError(methodDeclaration.returnType.sourceStart,
+ methodDeclaration.returnType.sourceEnd,
+ "Method annotated with @Pointcut() for abstract pointcut must be abstract");
+ }
+ } else if (Modifier.isAbstract(methodDeclaration.modifiers)) {
+ methodDeclaration.scope.problemReporter().signalError(methodDeclaration.returnType.sourceStart,
+ methodDeclaration.returnType.sourceEnd,
+ "Method annotated with non abstract @Pointcut(\""+pointcutExpression+"\") is abstract");
+ }
+ }
private void copyAllFields(MethodDeclaration from, MethodDeclaration to) {
to.annotations = from.annotations;
diff --git a/tests/java5/ataspectj/ataspectj/ConcreteAtAspectTest.java b/tests/java5/ataspectj/ataspectj/ConcreteAtAspectTest.java
index 180ec4f2b..2d673ca9f 100644
--- a/tests/java5/ataspectj/ataspectj/ConcreteAtAspectTest.java
+++ b/tests/java5/ataspectj/ataspectj/ConcreteAtAspectTest.java
@@ -40,7 +40,7 @@ public class ConcreteAtAspectTest extends TestCase {
abstract void pc();
// must be abstract
// for concrete-aspect, must further be no-arg, void
- // but can be more complex for non-xml inheritance
+ // !!! but can be more complex for non-xml inheritance !!! ie not error for AJDTcore
@Before("pc()")
public void before() {
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml
index fd2b922f1..d3bf28f77 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml
+++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml
@@ -134,7 +134,7 @@
<ajc-test dir="java5/ataspectj" title="Concrete@Aspect">
<compile
files="ataspectj/ConcreteAtAspectTest.java,ataspectj/TestHelper.java"
- options="-1.5 -Xdev:NoAtAspectJProcessing -XnoWeave"
+ options="-1.5 -XnoWeave"
/>
<run class="ataspectj.ConcreteAtAspectTest" ltw="ataspectj/aop-concreteataspect.xml"/>
</ajc-test>