KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > ast > PointcutDec


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.crosscuts.ast;
26
27 import org.aspectj.compiler.base.ast.*;
28 import org.aspectj.compiler.base.cst.*;
29
30 import java.util.*;
31
32 import org.aspectj.compiler.base.*;
33
34 /**
35  * @grammar modifiers pointcut name(formals) returns resultTypeD: pointcut;
36  * @child Modifiers modifiers
37  * @property String id
38  * @child TypeD resultTypeD
39  * @child Formals formals
40  * @child Pcd pcd
41  */

42
43 public class PointcutDec extends Dec {
44     // ------------------------------
45
// INTRO from InnerInfoPass
46

47     public void walkInnerInfo(InnerInfoPass w) {
48         int context = w.inMember(true);
49         super.walkInnerInfo(w);
50         w.restoreContext(context);
51     }
52     
53     // INTRO from ASTFixerPass
54
public ASTObject postFixAST(final ASTFixerPass fixer) {
55         return null;
56     }
57     
58     public void checkSpec() {
59         if (isStatic()) {
60             getCompiler().warnVersion("1.0beta1", this,
61                 "pointcut declarations may not be static");
62         }
63         
64         if (resultTypeD != null) {
65             getCompiler().warnVersion("1.0beta1", this,
66                 "pointcut declarations don't use returns clause");
67         }
68         
69         if (isAbstract()) {
70             if (isPrivate()) {
71                 showError("abstract private pointcut can never be implemented");
72             }
73         }
74         
75 // if (!getDeclaringType().isAspect() && !isStatic()) {
76
// showError("pointcut declarations outside of aspects must be declared static (since 1.0alpha1)");
77
// }
78
if (!isAbstract() && !(pcd == null || pcd instanceof EmptyPcd)) {
79             for (int i=0; i<formals.size(); i++) {
80                 if (!formals.get(i).isBound) {
81                     //System.out.println(pointcut);
82
formals.get(i).showError("not bound in this PCD");
83                 }
84             }
85         }
86     }
87     
88     //INTRO from ScopePass
89
public void preScope(ScopeWalker walker) {
90         walker.pushScope(makeBlockScope(walker));
91         //XXX want to add thisJoinPoint, ... to scope somehow
92
}
93     public ASTObject postScope(ScopeWalker walker) { walker.popScope(); return this; }
94     
95     public String JavaDoc toShortString() {
96         return modifiers.toShortString() + " " +
97                     getDeclaringType().toShortString() + "." + id +
98                     formals.toShortString();
99     }
100     
101     public String JavaDoc getKind() { return "pointcut"; }
102
103     public SemanticObject makeCorrespondingSemanticObject() {
104         return new PointcutSO(this);
105     }
106
107     public boolean isAbstract(PlanData planData) {
108         if (pcd == null || pcd instanceof EmptyPcd) return true;
109         return false; //pcd.isAbstract(planData);
110
}
111     
112     public boolean conflictsWith(Dec otherDec) {
113         //System.out.println(this + " conflictsWith? " + otherDec);
114
if (!getId().equals(otherDec.getId())) return false;
115         if (!this.isAccessible(otherDec) && !otherDec.isAccessible(this)) return false;
116         
117         return true;
118     }
119     
120     
121     void showOverrideError(Dec other, String JavaDoc message) {
122         String JavaDoc overrideKind = "override";
123         showError(toShortString() + " cannot " + overrideKind + " " +
124                 other.toShortString() + "; " + message);
125     }
126     
127     public boolean checkOverride(Type inType, Dec otherDec) {
128         PointcutDec other = (PointcutDec)otherDec;
129         if (other.getModifiers().isFinal()) {
130             showOverrideError(other, "overridden pointcut is final");
131         } else if (getModifiers().isWeakerThan(other.getModifiers())) {
132             showOverrideError(other,
133                 "attempting to assign weaker access privileges; was " +
134                         other.getModifiers().toShortString());
135         } else if (!getFormals().matches(other.getFormals())) {
136             showOverrideError(other,
137                 "signatures must match exactly; expected "
138                 + other.getFormals().toShortString());
139         }
140         return false;
141     }
142     
143     /*
144     public boolean canOverride(Dec otherDec) {
145         if (this == otherDec) return true;
146         
147         //XXX AAH
148         if (getDeclaringType() == null) return true;
149         
150         if (!getDeclaringType().isStrictSubtypeOf(otherDec.getDeclaringType())) return false;
151         
152         PointcutDec otherPointcutDec = (PointcutDec)otherDec;
153         
154         if (otherDec.isMoreAccessibleThan(this)) return false;
155         
156         // overriding pointcuts must have the exact same signature
157         return getFormals().matches(otherPointcutDec.getFormals());
158     }
159     */

160     
161     //BEGIN: Generated from @child and @property
162
protected Modifiers modifiers;
163     public Modifiers getModifiers() { return modifiers; }
164     public void setModifiers(Modifiers _modifiers) {
165         if (_modifiers != null) _modifiers.setParent(this);
166         modifiers = _modifiers;
167     }
168     
169     protected String JavaDoc id;
170     public String JavaDoc getId() { return id; }
171     public void setId(String JavaDoc _id) { id = _id; }
172     
173     protected TypeD resultTypeD;
174     public TypeD getResultTypeD() { return resultTypeD; }
175     public void setResultTypeD(TypeD _resultTypeD) {
176         if (_resultTypeD != null) _resultTypeD.setParent(this);
177         resultTypeD = _resultTypeD;
178     }
179     
180     protected Formals formals;
181     public Formals getFormals() { return formals; }
182     public void setFormals(Formals _formals) {
183         if (_formals != null) _formals.setParent(this);
184         formals = _formals;
185     }
186     
187     protected Pcd pcd;
188     public Pcd getPcd() { return pcd; }
189     public void setPcd(Pcd _pcd) {
190         if (_pcd != null) _pcd.setParent(this);
191         pcd = _pcd;
192     }
193     
194     public PointcutDec(SourceLocation location, Modifiers _modifiers, String JavaDoc _id, TypeD _resultTypeD, Formals _formals, Pcd _pcd) {
195         super(location);
196         setModifiers(_modifiers);
197         setId(_id);
198         setResultTypeD(_resultTypeD);
199         setFormals(_formals);
200         setPcd(_pcd);
201     }
202     protected PointcutDec(SourceLocation source) {
203         super(source);
204     }
205     
206     public ASTObject copyWalk(CopyWalker walker) {
207         PointcutDec ret = new PointcutDec(getSourceLocation());
208         ret.preCopy(walker, this);
209         if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) );
210         ret.id = id;
211         if (resultTypeD != null) ret.setResultTypeD( (TypeD)walker.process(resultTypeD) );
212         if (formals != null) ret.setFormals( (Formals)walker.process(formals) );
213         if (pcd != null) ret.setPcd( (Pcd)walker.process(pcd) );
214         return ret;
215     }
216     
217     public ASTObject getChildAt(int childIndex) {
218         switch(childIndex) {
219         case 0: return modifiers;
220         case 1: return resultTypeD;
221         case 2: return formals;
222         case 3: return pcd;
223         default: return super.getChildAt(childIndex);
224         }
225     }
226      public String JavaDoc getChildNameAt(int childIndex) {
227         switch(childIndex) {
228         case 0: return "modifiers";
229         case 1: return "resultTypeD";
230         case 2: return "formals";
231         case 3: return "pcd";
232         default: return super.getChildNameAt(childIndex);
233         }
234     }
235      public void setChildAt(int childIndex, ASTObject child) {
236         switch(childIndex) {
237         case 0: setModifiers((Modifiers)child); return;
238         case 1: setResultTypeD((TypeD)child); return;
239         case 2: setFormals((Formals)child); return;
240         case 3: setPcd((Pcd)child); return;
241         default: super.setChildAt(childIndex, child); return;
242         }
243     }
244      public int getChildCount() {
245         return 4;
246     }
247     
248     public String JavaDoc getDefaultDisplayName() {
249         return "PointcutDec(id: "+id+")";
250     }
251     
252     //END: Generated from @child and @property
253
}
254
Popular Tags