Source code: fzi/injectj/weavepoint/AbstractWeavepoint.java
1 // This file is part of the Inject/J project
2 // (C) 1999-2001 Forschungszentrum Informatik (FZI) Karlsruhe
3 // Please visit our website at http://injectj.fzi.de
4
5 package fzi.injectj.weavepoint;
6
7 import fzi.injectj.node.JavaSource;
8 import fzi.injectj.language.*;
9 import fzi.injectj.navigation.*;
10 import fzi.injectj.node.StatementList;
11 import fzi.injectj.util.StringUtil;
12 import fzi.injectj.util.Environment;
13
14 /** This is the base class for all weavepoint representations, like class, method
15 * member access or explicit weavepoints. All possible commands in these weavepoints
16 * are declared here. The default implementation for these commands does nothing but
17 * throwing a WeaveException, indicating that this command isn't allowed for the
18 * given weavepoint type. If a weavepoint type allows a specific command, the
19 * default implementation must be overridden.
20 * For example, the AbstractWeavepoint subclass representing a member access
21 * only has to override methods before(), after(), replace() and delete(), since a
22 * member access doesn't support commands like addToImports().
23 *
24 * @author Volker Kuttruff
25 */
26 public abstract class AbstractWeavepoint extends Type
27 {
28
29 /** Accepts a visitor. This is part of the GoF design pattern "Visitor". After
30 * accepting a visitor, this method calls the appropriate visit method.
31 * For example, the subclass representing a class weavepoint will call
32 * visit(Class...), while a subclass representing a method weavepoint will call
33 * visit(Method...).
34 *
35 * @param visitor the visitor object to accept.
36 * @param description the weavepoint description will be passed to the visitor's
37 * visit()-method.
38 * @param statementList the statement list which should be executed if the visitor
39 * navigated to the described weavepoint.
40 * @throws WeaveException thrown if a given weave command isn't supported.
41 * @throws NavigationException thrown if the described weavepoint can't be found
42 * @throws MalformedAliasusageException thrown if a malformed alias usage was found
43 * while executing the statementList
44 * @throws UninitializedTypeException thrown if an uninitialized type was used
45 * @return a visitor-specific return object
46 */
47 public abstract Object accept(Visitor visitor,
48 WeavePointDescription description,
49 StatementList statementList)
50 throws WeaveException, NavigationException, MalformedAliasusageException, UninitializedTypeException;
51
52 /** Implementation of the 'before' command. This method will be called if a
53 * 'before' command was found. The default implementation does nothing but
54 * throwing a WeaveException.
55 *
56 * @param source the Java source to weave before a given weavepoint
57 * @param environment the current environment
58 * @throws WeaveException thrown if an error occured during weaving or if
59 * this command isn't allowed in a weavepoint of this type.
60 */
61 public void before(JavaSource source, Environment environment) throws WeaveException
62 {
63 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
64 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "before");
65 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
66 throw new WeaveException(commandNotAllowed);
67 }
68
69 /** Implementation of the 'after' command. This method will be called if a
70 * 'after' command was found. The default implementation does nothing but
71 * throwing a WeaveException.
72 *
73 * @param source the Java source to weave after a given weavepoint
74 * @param environment the current environment
75 * @throws WeaveException thrown if an error occured during weaving or if
76 * this command isn't allowed in a weavepoint of this type.
77 */
78 public void after(JavaSource source, Environment environment) throws WeaveException
79 {
80 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
81 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "after");
82 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
83 throw new WeaveException(commandNotAllowed);
84 }
85
86 /** Implementation of the 'replace' command. This method will be called if a
87 * 'replace' command was found. The default implementation does nothing but
88 * throwing a WeaveException.
89 *
90 * @param source the Java source to replace with a given weavepoint
91 * @param environment the current environment
92 * @throws WeaveException thrown if an error occured during weaving or if
93 * this command isn't allowed in a weavepoint of this type.
94 */
95 public void replace(JavaSource source, Environment environment) throws WeaveException
96 {
97 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
98 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "replace");
99 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
100 throw new WeaveException(commandNotAllowed);
101 }
102
103 /** Implementation of the 'delete' command. This method will be called if a
104 * 'delete' command was found. The default implementation does nothing but
105 * throwing a WeaveException.
106 *
107 * @param environment the current environment
108 * @throws WeaveException thrown if an error occured during deleting or if
109 * this command isn't allowed in a weavepoint of this type.
110 */
111 public void delete(Environment environment) throws WeaveException
112 {
113 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
114 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "delete");
115 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
116 throw new WeaveException(commandNotAllowed);
117 }
118
119 /** Implementation of the 'add to imports' command. This method will be called if a
120 * 'add to imports' command was found. The default implementation does nothing but
121 * throwing a WeaveException.
122 *
123 * @param source the Java source to add to the imports list (without "imports"
124 * statement), for example "java.util.Vector"
125 * @param environment the current environment
126 * @throws WeaveException thrown if an error occured during weaving or if
127 * this command isn't allowed in a weavepoint of a given type.
128 */
129 public void addToImports(JavaSource source, Environment environment) throws WeaveException
130 {
131 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
132 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add to imports");
133 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
134 throw new WeaveException(commandNotAllowed);
135 }
136
137 /** Implementation of the 'add to extends' command. This method will be called if a
138 * 'add to extends' command was found. The default implementation does nothing but
139 * throwing a WeaveException.
140 *
141 * @param source the Java source to add to the extends list
142 * @param environment the current environment
143 * @throws WeaveException thrown if an error occured during weaving or if
144 * this command isn't allowed in a weavepoint of a given type.
145 */
146 public void addToExtends(JavaSource source, Environment environment) throws WeaveException
147 {
148 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
149 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add to extends");
150 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
151 throw new WeaveException(commandNotAllowed);
152 }
153
154 /** Implementation of the 'add to implements' command. This method will be called if a
155 * 'before' command was found. The default implementation does nothing but
156 * throwing a WeaveException.
157 *
158 * @param source the Java source to add to the implements list
159 * @param environment the current environment
160 * @throws WeaveException thrown if an error occured during weaving or if
161 * this command isn't allowed in a weavepoint of a given type.
162 */
163 public void addToImplements(JavaSource source, Environment environment) throws WeaveException
164 {
165 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
166 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add to implements");
167 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
168 throw new WeaveException(commandNotAllowed);
169 }
170
171 /** Implementation of the 'add to throws' command. This method will be called if a
172 * 'add to throws' command was found. The default implementation does nothing but
173 * throwing a WeaveException.
174 *
175 * @param source the Java source to add to the throws list of a method
176 * @param environment the current environment
177 * @throws WeaveException thrown if an error occured during weaving or if
178 * this command isn't allowed in a weavepoint of a given type.
179 */
180 public void addToThrows(JavaSource source, Environment environment) throws WeaveException
181 {
182 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
183 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add to throws");
184 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
185 throw new WeaveException(commandNotAllowed);
186 }
187
188 /** Implementation of the 'add class' command. This method will be called if a
189 * 'add class' command was found. The default implementation does nothing but
190 * throwing a WeaveException.
191 *
192 * @param source the Java source of the new members
193 * @param description description containing name of the new class
194 * @param addInnerClass determines whether to add an inner class or not
195 * @param environment the current environment
196 * @throws WeaveException thrown if an error occured during weaving or if
197 * this command isn't allowed in a weavepoint of a given type.
198 */
199 public void addClass(JavaSource source, WeavePointDescription description, boolean addInnerClass, Environment environment) throws WeaveException
200 {
201 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
202 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add class");
203 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
204 throw new WeaveException(commandNotAllowed);
205 }
206 /** Implementation of the 'add class' command. This method will be called if a
207 * 'add class' command was found. The default implementation does nothing but
208 * throwing a WeaveException.
209 *
210 * @param source the Java source of the new members
211 * @param description description containing name of the new class
212 * @param addInnerClass determines whether to add an inner class or not
213 * @param environment the current environment
214 * @throws WeaveException thrown if an error occured during weaving or if
215 * this command isn't allowed in a weavepoint of a given type.
216 */
217 public void addInterface(JavaSource source, WeavePointDescription description, Environment environment) throws WeaveException
218 {
219 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
220 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add interface");
221 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
222 throw new WeaveException(commandNotAllowed);
223 }
224
225
226 /** Implementation of the 'add to members' command. This method will be called if a
227 * 'add to members' command was found. The default implementation does nothing but
228 * throwing a WeaveException.
229 *
230 * @param source the Java source to weave to a given class weavepoint
231 * @param environment the current environment
232 * @throws WeaveException thrown if an error occured during weaving or if
233 * this command isn't allowed in a weavepoint of a given type.
234 */
235 public void addToMembers(JavaSource source, Environment environment) throws WeaveException
236 {
237 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
238 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "add to members");
239 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
240 throw new WeaveException(commandNotAllowed);
241 }
242
243 /** Implementation of the 'change modifier' command. This method will be called if a
244 * 'change modifier' command was found. The default implementation does nothing but
245 * throwing a WeaveException.
246 *
247 * @param source the Java source of the new modifier(s).
248 * @param environment the current environment
249 * @throws WeaveException thrown if an error occured during weaving or if
250 * this command isn't allowed in a weavepoint of a given type.
251 */
252 public void changeModifier(JavaSource source, Environment environment) throws WeaveException
253 {
254 String commandNotAllowed = CodeMapper.getText(LabelCode.COMMAND_X_NOT_ALLOWED);
255 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%1", "change modifier");
256 commandNotAllowed = StringUtil.replace(commandNotAllowed, "%2", getTypeName());
257 throw new WeaveException(commandNotAllowed);
258 }
259
260 }