Bug 124077 - Problem with compiling annotations
Summary: Problem with compiling annotations
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-17 01:38 EST by Dhana CLA
Modified: 2006-01-30 03:00 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dhana CLA 2006-01-17 01:38:20 EST
Hi,

I wrote a custom annotation and have used my custom annotation in my java class. I was able to compile the same sucessfully with jdk1.5.0_06. I wrote an aspect with annotations and when tried to compile the same iam  getting errors. Pls find attached my sample code and the error which i am getting.

My Custom Annotation
********************

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation{
}

My Java Class using my Custom Annotation
****************************************
public class  AnnotationTestClass{

	static AnnotationTestClass objTest;

	public static void main(String[] args) 	{
		objTest = new AnnotationTestClass();
		objTest.methodA();
	}

	@MyAnnotation
	public void methodA(){
		System.out.println("This is methodA");
		objTest.methodB();
	}

	@MyAnnotation
	public void methodB(){
		System.out.println("This is methodB");
	}
}

My Aspect to cut the annotated methods
**************************************
public aspect AnnotationTestAspect{

	pointcut annotatePointcut() : call(@MyAnnotation * *(..));

	before() : annotatePointcut(){
		System.out.println("Joinpoint : " + thisJoinPoint);
	}
}

I have an execute.lst file as below,
AnnotationTestAspect.java
AnnotationTestClass.java
MyAnnotation.java

When compiled as follows, i get the following errors,

D:\Study\AspectJ\13-01-06>ajc @executeList.lst
D:\Study\AspectJ\13-01-06\AnnotationTestAspect.java:3 [error] annotation type patterns are only supported at Java 5 compliance level or above
pointcut annotatePointcut() : call(@MyAnnotation * *(..));
                                    ^^^^^^^^^^
D:\Study\AspectJ\13-01-06\AnnotationTestClass.java:10 [error] Syntax error, annotations are only available if source level is 5.0
@MyAnnotation
^^^^^^^^^^^
D:\Study\AspectJ\13-01-06\AnnotationTestClass.java:16 [error] Syntax error, annotations are only available if source level is 5.0
@MyAnnotation
^^^^^^^^^^^
D:\Study\AspectJ\13-01-06\MyAnnotation.java:3 [error] Syntax error, annotations are only available if source level is 5.0
@Retention(RetentionPolicy.SOURCE)
^^^^^^^^^
D:\Study\AspectJ\13-01-06\MyAnnotation.java:4 [error] Syntax error, annotation declarations are only available if source level is 5.0
public @interface MyAnnotation{
                  ^^^^^^^^^^^
In ajc.bat the java home is set to the home of jdk1.5.0_06.

Please let me what is the problem.

Regards
R.S.Dhanalakshmi
Comment 1 Andrew Clement CLA 2006-01-17 03:09:34 EST
Unlike javac, ajc does not default to 1.5 compliance level.  You need to compile with the -1.5 flag:

ajc -1.5 @executeList.lst
Comment 2 Andrew Clement CLA 2006-01-30 03:00:26 EST
I presume switching on the -1.5 flag fixed this... if not then feel free to reopen.