25
26
public class DeclareAnnotationDeclaration extends DeclareDeclaration {
27
private Annotation annotation;
29
public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation annotation) {
30
super(result,symbolicDeclare);
31
this.annotation = annotation;
33
addAnnotation(annotation);
34
if (symbolicDeclare==null) return; // there is an error that will already be getting reported (e.g. incorrect pattern on decaf/decac)
35
symbolicDeclare.setAnnotationString(annotation.toString());
39
public void analyseCode(ClassScope classScope,
40
InitializationFlowContext initializationContext, FlowInfo flowInfo) {
28
private Annotation annotation;
29
private boolean isRemover = false;
31
public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation annotation) {
32
super(result, symbolicDeclare);
33
this.annotation = annotation;
35
addAnnotation(annotation);
36
if (symbolicDeclare == null) {
37
return; // there is an error that will already be getting reported (e.g. incorrect pattern on decaf/decac)
39
this.isRemover = symbolicDeclare.isRemover();
40
symbolicDeclare.setAnnotationString(annotation.toString());
41
symbolicDeclare.setAnnotationLocation(annotation.sourceStart, annotation.sourceEnd);
44
public void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo flowInfo) {
41
45
super.analyseCode(classScope, initializationContext, flowInfo);
48
if (((DeclareAnnotation) declareDecl).getKind() != DeclareAnnotation.AT_FIELD) {
49
classScope.problemReporter().signalError(this.sourceStart(), this.sourceEnd,
50
"Annotation removal only supported for declare @field (compiler limitation)");
52
else if (isRemover && !(annotation instanceof MarkerAnnotation)) {
53
classScope.problemReporter().signalError(this.sourceStart(), this.sourceEnd,
54
"Annotation removal does not allow values to be specified for the annotation (compiler limitation)");
43
57
long bits = annotation.resolvedType.getAnnotationTagBits();
45
if ((bits&TagBits.AnnotationTarget)!=0) {
46
// The annotation is stored against a method. For declare @type we need to
47
// confirm the annotation targets the right types. Earlier checking will
59
if ((bits & TagBits.AnnotationTarget) != 0) {
60
// The annotation is stored against a method. For declare @type we need to
61
// confirm the annotation targets the right types. Earlier checking will
48
62
// have not found this problem because an annotation for target METHOD will
49
63
// not be reported on as we *do* store it against a method in this case
50
DeclareAnnotation.Kind k = ((DeclareAnnotation)declareDecl).getKind();
51
if (k.equals(DeclareAnnotation.AT_TYPE))
52
if ((bits&TagBits.AnnotationForMethod)!=0)
53
classScope.problemReporter().disallowedTargetForAnnotation(annotation);
54
if (k.equals(DeclareAnnotation.AT_FIELD))
55
if ((bits&TagBits.AnnotationForMethod)!=0)
56
classScope.problemReporter().disallowedTargetForAnnotation(annotation);
64
DeclareAnnotation.Kind k = ((DeclareAnnotation) declareDecl).getKind();
65
if (k.equals(DeclareAnnotation.AT_TYPE)) {
66
if ((bits & TagBits.AnnotationForMethod) != 0) {
67
classScope.problemReporter().disallowedTargetForAnnotation(annotation);
70
if (k.equals(DeclareAnnotation.AT_FIELD)) {
71
if ((bits & TagBits.AnnotationForMethod) != 0) {
72
classScope.problemReporter().disallowedTargetForAnnotation(annotation);
62
public Annotation getDeclaredAnnotation() {
79
public Annotation getDeclaredAnnotation() {
66
83
protected boolean shouldDelegateCodeGeneration() {
67
return true; // declare annotation needs a method to be written out.
70
private void addAnnotation(Annotation ann) {
71
if (this.annotations == null) {
72
this.annotations = new Annotation[1];
74
Annotation[] old = this.annotations;
75
this.annotations = new Annotation[old.length + 1];
76
System.arraycopy(old,0,this.annotations,1,old.length);
78
this.annotations[0] = ann;
84
return true; // declare annotation needs a method to be written out.
87
protected boolean shouldBeSynthetic() {
91
private void addAnnotation(Annotation ann) {
92
if (this.annotations == null) {
93
this.annotations = new Annotation[1];
96
Annotation[] old = this.annotations;
97
this.annotations = new Annotation[old.length + 1];
98
System.arraycopy(old, 0, this.annotations, 1, old.length);
100
this.annotations[0] = ann;
81
103
public void postParse(TypeDeclaration typeDec) {
82
104
super.postParse(typeDec);
83
if (declareDecl != null){
84
((DeclareAnnotation)declareDecl).setAnnotationMethod(new String(selector));
105
if (declareDecl != null) {
106
((DeclareAnnotation) declareDecl).setAnnotationMethod(new String(selector));
110
public boolean isRemover() {