Reputation: 691
when trying to compile an aspect file using ajc and the command line, im getting error when trying to compile *.aj
file (aspect syntax)
It works fine when compiling *.java
aspect (using annotations)
Aspect Annotation - TestAspect.java
:
@Aspect
public class TestAspect {
@Pointcut("execution(* TestTarget.test(..))")
void test() {}
@Before("test()")
public void advice(JoinPoint joinPoint) {
System.out.printf("TestAspect.advice() called on '%s'%n", joinPoint);
}
}
Aspect Syntax - TestAspect.aj
:
public aspect TestAspect {
pointcut test() : execution(* TestTarget.test*(...));
before() : test()
public void advice(JoinPoint joinPoint) {
System.out.printf("TestAspect.advice() called on '%s'%n", joinPoint);
}
}
when compiling TestAspect.aj im using the following command:
ajc -1.8 -sourceroots ./ -cp aspectjrt.jar;
and getting the following errors:
C:\****\TestAspect.aj:3 [error] Syntax error on token "...", "name pattern" expected
pointcut test() : execution(* TestTarget.test*(...));
^
C:\****\TestAspect.aj:6 [error] Syntax error on token "public", "{" expected
public void advice(JoinPoint joinPoint) {
^
C:\****\TestAspect.aj:7 [error] joinPoint cannot be resolved to a variable
System.out.printf("TestAspect.advice() called on '%s'%n", joinPoint);
3 errors
I didn't manage to find any solution while googling for over an hour. even not in the documentation.
I might be missing something, will be glad for some help.
Upvotes: 0
Views: 624
Reputation: 691
solution:
public aspect TestAspect {
pointcut test() : execution(* TestTarget.test*(..));
before() : test() {
System.out.printf("TestAspect.advice() called on '%s'%n", thisJoinPoint);
}
}
1) notice the test()
argument wildcard is only 2 dots instead of 3!
2) advice body doesn't have a method signature and you can reference thisJoinPoint without passing it as a parameter
(note im talking about the *.aj
file)
Upvotes: 1