KickJava   Java API By Example, From Geeks To Geeks.

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


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.crosscuts.joinpoints.*;
28
29 import org.aspectj.compiler.base.ast.*;
30 import org.aspectj.compiler.base.cst.*;
31
32 import org.aspectj.compiler.base.JavaCompiler;
33 import org.aspectj.compiler.crosscuts.AspectJCompiler;
34
35 /**
36  * @grammar declare error|warning: pointcut: message;
37  * @child Pcd pcd
38  * @child Expr message
39  * @property boolean isWarning
40  */

41
42 public class ShowErrorDec extends Dec implements JpPlannerMaker {
43
44     public Modifiers getModifiers() { return getAST().makeModifiers(0); }
45     
46     public String JavaDoc getId() { return "declare"; }
47     public String JavaDoc toShortString() {
48         return getKind() + ": " + pcd.toShortString();
49     }
50     public String JavaDoc getKind() {
51         return "declare " + (isWarning ? "warning" : "error");
52     }
53
54
55     public void checkSpec() {
56         pcd.checkStatic();
57         
58         if (! (message instanceof StringLiteralExpr) ) {
59             message.showError("error message must be a constant string");
60         }
61     }
62
63     public JpPlanner makePlanner(PlanData planData) {
64         return new ErrorPlanner(getPcd().makePlanner(planData));
65     }
66         
67     private String JavaDoc getMessageString() {
68         if (! (message instanceof StringLiteralExpr)) return "";
69         return ((StringLiteralExpr)message).getStringValue();
70     }
71     
72     private class ErrorPlanner extends WrappedJpPlanner {
73         public ErrorPlanner(JpPlanner planner) { super(planner); }
74
75         public JpPlan makePlan(JoinPoint jp) {
76             //??? this is controversial design
77
if (jp.getSourceLocation() == null) return JpPlan.NO_PLAN;
78             if (alwaysMatches(jp)) {
79                 showErrorAt(jp);
80             }
81             return JpPlan.NO_PLAN;
82         }
83
84         public boolean isStaticPlanner() { return true; }
85     }
86     
87     public void showErrorAt(JoinPoint point) {
88         if (isWarning) {
89             getCompiler().showWarning(point.getSourceLocation(), getMessageString());
90         } else {
91             getCompiler().showError(point.getSourceLocation(), getMessageString());
92         }
93     }
94     
95     //BEGIN: Generated from @child and @property
96
protected Pcd pcd;
97     public Pcd getPcd() { return pcd; }
98     public void setPcd(Pcd _pcd) {
99         if (_pcd != null) _pcd.setParent(this);
100         pcd = _pcd;
101     }
102     
103     protected Expr message;
104     public Expr getMessage() { return message; }
105     public void setMessage(Expr _message) {
106         if (_message != null) _message.setParent(this);
107         message = _message;
108     }
109     
110     protected boolean isWarning;
111     public boolean getIsWarning() { return isWarning; }
112     public void setIsWarning(boolean _isWarning) { isWarning = _isWarning; }
113     
114     public ShowErrorDec(SourceLocation location, Pcd _pcd, Expr _message, boolean _isWarning) {
115         super(location);
116         setPcd(_pcd);
117         setMessage(_message);
118         setIsWarning(_isWarning);
119     }
120     protected ShowErrorDec(SourceLocation source) {
121         super(source);
122     }
123     
124     public ASTObject copyWalk(CopyWalker walker) {
125         ShowErrorDec ret = new ShowErrorDec(getSourceLocation());
126         ret.preCopy(walker, this);
127         if (pcd != null) ret.setPcd( (Pcd)walker.process(pcd) );
128         if (message != null) ret.setMessage( (Expr)walker.process(message) );
129         ret.isWarning = isWarning;
130         return ret;
131     }
132     
133     public ASTObject getChildAt(int childIndex) {
134         switch(childIndex) {
135         case 0: return pcd;
136         case 1: return message;
137         default: return super.getChildAt(childIndex);
138         }
139     }
140      public String JavaDoc getChildNameAt(int childIndex) {
141         switch(childIndex) {
142         case 0: return "pcd";
143         case 1: return "message";
144         default: return super.getChildNameAt(childIndex);
145         }
146     }
147      public void setChildAt(int childIndex, ASTObject child) {
148         switch(childIndex) {
149         case 0: setPcd((Pcd)child); return;
150         case 1: setMessage((Expr)child); return;
151         default: super.setChildAt(childIndex, child); return;
152         }
153     }
154      public int getChildCount() {
155         return 2;
156     }
157     
158     public String JavaDoc getDefaultDisplayName() {
159         return "ShowErrorDec(isWarning: "+isWarning+")";
160     }
161     
162     //END: Generated from @child and @property
163
}
164
165
166
167
Popular Tags