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);
-// }
-// }
}
}
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());
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;
}
}
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");
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
*
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);
// 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() ,
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;
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() {
<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>