~ubuntu-branches/ubuntu/wily/aspectj/wily-proposed

« back to all changes in this revision

Viewing changes to org.aspectj/modules/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.2.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110315235431-iq2gxbsx08kpwuiw
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
17
17
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
 
18
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
18
19
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
19
20
import org.aspectj.org.eclipse.jdt.internal.compiler.flow.FlowInfo;
20
21
import org.aspectj.org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext;
24
25
 
25
26
public class DeclareAnnotationDeclaration extends DeclareDeclaration {
26
27
 
27
 
   private Annotation annotation;
28
 
   
29
 
   public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation annotation)  {
30
 
          super(result,symbolicDeclare);
31
 
          this.annotation = annotation;
32
 
          
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());
36
 
          
37
 
   }
38
 
   
39
 
   public void analyseCode(ClassScope classScope,
40
 
                        InitializationFlowContext initializationContext, FlowInfo flowInfo) {
 
28
        private Annotation annotation;
 
29
        private boolean isRemover = false;
 
30
 
 
31
        public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation annotation) {
 
32
                super(result, symbolicDeclare);
 
33
                this.annotation = annotation;
 
34
 
 
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)
 
38
                }
 
39
                this.isRemover = symbolicDeclare.isRemover();
 
40
                symbolicDeclare.setAnnotationString(annotation.toString());
 
41
                symbolicDeclare.setAnnotationLocation(annotation.sourceStart, annotation.sourceEnd);
 
42
        }
 
43
 
 
44
        public void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo flowInfo) {
41
45
                super.analyseCode(classScope, initializationContext, flowInfo);
42
46
 
 
47
                if (isRemover) {
 
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)");
 
51
                        }
 
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)");
 
55
                        }
 
56
                }
43
57
                long bits = annotation.resolvedType.getAnnotationTagBits();
44
 
                
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
 
58
 
 
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);
 
68
                                }
 
69
                        }
 
70
                        if (k.equals(DeclareAnnotation.AT_FIELD)) {
 
71
                                if ((bits & TagBits.AnnotationForMethod) != 0) {
 
72
                                        classScope.problemReporter().disallowedTargetForAnnotation(annotation);
 
73
                                }
 
74
                        }
57
75
                }
58
 
                
59
 
    }
60
 
        
61
 
        
62
 
   public Annotation getDeclaredAnnotation() {
63
 
                return annotation;
64
 
   }
65
 
        
 
76
 
 
77
        }
 
78
 
 
79
        public Annotation getDeclaredAnnotation() {
 
80
                return annotation;
 
81
        }
 
82
 
66
83
        protected boolean shouldDelegateCodeGeneration() {
67
 
                return true;  // declare annotation needs a method to be written out.
68
 
        }
69
 
   
70
 
   private void addAnnotation(Annotation ann) {
71
 
        if (this.annotations == null) {
72
 
                this.annotations = new Annotation[1];
73
 
        } else {
74
 
                Annotation[] old = this.annotations;
75
 
                this.annotations = new Annotation[old.length + 1];
76
 
                System.arraycopy(old,0,this.annotations,1,old.length);
77
 
        }
78
 
        this.annotations[0] = ann;
79
 
   }
80
 
   
 
84
                return true; // declare annotation needs a method to be written out.
 
85
        }
 
86
 
 
87
        protected boolean shouldBeSynthetic() {
 
88
                return false;
 
89
        }
 
90
 
 
91
        private void addAnnotation(Annotation ann) {
 
92
                if (this.annotations == null) {
 
93
                        this.annotations = new Annotation[1];
 
94
                }
 
95
                else {
 
96
                        Annotation[] old = this.annotations;
 
97
                        this.annotations = new Annotation[old.length + 1];
 
98
                        System.arraycopy(old, 0, this.annotations, 1, old.length);
 
99
                }
 
100
                this.annotations[0] = ann;
 
101
        }
 
102
 
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));
85
107
                }
86
108
        }
87
 
        
 
109
 
 
110
        public boolean isRemover() {
 
111
                return isRemover;
 
112
        }
88
113
}