001: /*
002: * Spoon - http://spoon.gforge.inria.fr/
003: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004: *
005: * This software is governed by the CeCILL-C License under French law and
006: * abiding by the rules of distribution of free software. You can use, modify
007: * and/or redistribute the software under the terms of the CeCILL-C license as
008: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013: *
014: * The fact that you are presently reading this means that you have had
015: * knowledge of the CeCILL-C license and that you accept its terms.
016: */
017:
018: package spoon.reflect.visitor;
019:
020: import java.lang.annotation.Annotation;
021: import java.util.Collection;
022:
023: import spoon.reflect.code.CtAbstractInvocation;
024: import spoon.reflect.code.CtArrayAccess;
025: import spoon.reflect.code.CtAssert;
026: import spoon.reflect.code.CtAssignment;
027: import spoon.reflect.code.CtBinaryOperator;
028: import spoon.reflect.code.CtBlock;
029: import spoon.reflect.code.CtBreak;
030: import spoon.reflect.code.CtCFlowBreak;
031: import spoon.reflect.code.CtCase;
032: import spoon.reflect.code.CtCatch;
033: import spoon.reflect.code.CtCodeElement;
034: import spoon.reflect.code.CtCodeSnippetExpression;
035: import spoon.reflect.code.CtCodeSnippetStatement;
036: import spoon.reflect.code.CtConditional;
037: import spoon.reflect.code.CtContinue;
038: import spoon.reflect.code.CtDo;
039: import spoon.reflect.code.CtExpression;
040: import spoon.reflect.code.CtFieldAccess;
041: import spoon.reflect.code.CtFor;
042: import spoon.reflect.code.CtForEach;
043: import spoon.reflect.code.CtIf;
044: import spoon.reflect.code.CtInvocation;
045: import spoon.reflect.code.CtLiteral;
046: import spoon.reflect.code.CtLocalVariable;
047: import spoon.reflect.code.CtLoop;
048: import spoon.reflect.code.CtNewArray;
049: import spoon.reflect.code.CtNewClass;
050: import spoon.reflect.code.CtOperatorAssignment;
051: import spoon.reflect.code.CtReturn;
052: import spoon.reflect.code.CtStatement;
053: import spoon.reflect.code.CtStatementList;
054: import spoon.reflect.code.CtSwitch;
055: import spoon.reflect.code.CtSynchronized;
056: import spoon.reflect.code.CtTargetedExpression;
057: import spoon.reflect.code.CtThrow;
058: import spoon.reflect.code.CtTry;
059: import spoon.reflect.code.CtUnaryOperator;
060: import spoon.reflect.code.CtVariableAccess;
061: import spoon.reflect.code.CtWhile;
062: import spoon.reflect.declaration.CtAnnotation;
063: import spoon.reflect.declaration.CtAnnotationType;
064: import spoon.reflect.declaration.CtAnonymousExecutable;
065: import spoon.reflect.declaration.CtClass;
066: import spoon.reflect.declaration.CtConstructor;
067: import spoon.reflect.declaration.CtElement;
068: import spoon.reflect.declaration.CtEnum;
069: import spoon.reflect.declaration.CtExecutable;
070: import spoon.reflect.declaration.CtField;
071: import spoon.reflect.declaration.CtGenericElement;
072: import spoon.reflect.declaration.CtInterface;
073: import spoon.reflect.declaration.CtMethod;
074: import spoon.reflect.declaration.CtModifiable;
075: import spoon.reflect.declaration.CtNamedElement;
076: import spoon.reflect.declaration.CtPackage;
077: import spoon.reflect.declaration.CtParameter;
078: import spoon.reflect.declaration.CtSimpleType;
079: import spoon.reflect.declaration.CtType;
080: import spoon.reflect.declaration.CtTypeParameter;
081: import spoon.reflect.declaration.CtTypedElement;
082: import spoon.reflect.declaration.CtVariable;
083: import spoon.reflect.declaration.ModifierKind;
084: import spoon.reflect.reference.CtArrayTypeReference;
085: import spoon.reflect.reference.CtExecutableReference;
086: import spoon.reflect.reference.CtFieldReference;
087: import spoon.reflect.reference.CtGenericElementReference;
088: import spoon.reflect.reference.CtLocalVariableReference;
089: import spoon.reflect.reference.CtPackageReference;
090: import spoon.reflect.reference.CtParameterReference;
091: import spoon.reflect.reference.CtReference;
092: import spoon.reflect.reference.CtTypeParameterReference;
093: import spoon.reflect.reference.CtTypeReference;
094: import spoon.reflect.reference.CtVariableReference;
095:
096: /**
097: * This class provides an abstract implementation of the visitor that allows its
098: * subclasses to scans the metamodel elements by recursively using their
099: * (abstract) supertype scanning methods.
100: */
101: public abstract class CtInheritanceScanner implements CtVisitor {
102:
103: /**
104: * Default constructor.
105: */
106: public CtInheritanceScanner() {
107: }
108:
109: public <T> void visitCtCodeSnippetExpression(
110: CtCodeSnippetExpression<T> expression) {
111: }
112:
113: public void visitCtCodeSnippetStatement(
114: CtCodeSnippetStatement statement) {
115: }
116:
117: /**
118: * Generically scans a collection of meta-model elements.
119: */
120: public void scan(Collection<? extends CtElement> elements) {
121: if (elements != null) {
122: for (CtElement e : elements) {
123: scan(e);
124: }
125: }
126: }
127:
128: /**
129: * Generically scans a meta-model element.
130: */
131: public void scan(CtElement element) {
132: if (element != null)
133: element.accept(this );
134: }
135:
136: /**
137: * Generically scans a meta-model element reference.
138: */
139: public void scan(CtReference reference) {
140: if (reference != null)
141: reference.accept(this );
142: }
143:
144: /**
145: * Scans an abstract invocation.
146: */
147: public <T> void scanCtAbstractInvocation(CtAbstractInvocation<T> a) {
148: }
149:
150: /**
151: * Scans an abstract control flow break.
152: */
153: public void scanCtCFlowBreak(CtCFlowBreak flowBreak) {
154: scanCtCodeElement(flowBreak);
155: }
156:
157: /**
158: * Scans an abstract code element.
159: */
160: public void scanCtCodeElement(CtCodeElement e) {
161: scanCtElement(e);
162: }
163:
164: /**
165: * Scans an abstract element.
166: */
167: public void scanCtElement(CtElement e) {
168: }
169:
170: /**
171: * Scans an abstract executable.
172: */
173: public <R> void scanCtExecutable(CtExecutable<R> e) {
174: scanCtGenericElement(e);
175: scanCtNamedElement(e);
176: }
177:
178: /**
179: * Scans an abstract expression.
180: */
181: public <T> void scanCtExpression(CtExpression<T> expression) {
182: scanCtCodeElement(expression);
183: scanCtTypedElement(expression);
184: }
185:
186: /**
187: * Scans an abstract generic element.
188: */
189: public void scanCtGenericElement(CtGenericElement e) {
190: scanCtElement(e);
191: }
192:
193: /**
194: * Scans an abstract generic element reference.
195: */
196: public void scanCtGenericElementReference(
197: CtGenericElementReference reference) {
198: }
199:
200: /**
201: * Scans an abstract loop.
202: */
203: public void scanCtLoop(CtLoop loop) {
204: scanCtStatement(loop);
205: }
206:
207: /**
208: * Scans an abstract modifiable element.
209: */
210: public void scanCtModifiable(CtModifiable m) {
211: for (ModifierKind modifier : m.getModifiers()) {
212: scanCtModifier(modifier);
213: }
214: }
215:
216: /**
217: * Scans a modifier (enumeration).
218: */
219: public void scanCtModifier(ModifierKind m) {
220: }
221:
222: /**
223: * Scans an abstract named element.
224: */
225: public void scanCtNamedElement(CtNamedElement e) {
226: scanCtElement(e);
227: scanCtModifiable(e);
228: }
229:
230: /**
231: * Scans an abstract reference.
232: */
233: public void scanCtReference(CtReference reference) {
234:
235: }
236:
237: /**
238: * Scans an abstract simple type.
239: */
240: public <T> void scanCtSimpleType(CtSimpleType<T> t) {
241: scanCtNamedElement(t);
242: }
243:
244: /**
245: * Scans an abstract statement.
246: */
247: public void scanCtStatement(CtStatement s) {
248: scanCtCodeElement(s);
249: }
250:
251: /**
252: * Scans an abstract targeted expression.
253: */
254: public <T, E extends CtExpression<?>> void scanCtTargetedExpression(
255: CtTargetedExpression<T, E> targetedExpression) {
256: scanCtExpression(targetedExpression);
257: }
258:
259: /**
260: * Scans an abstract type.
261: */
262: public <T> void scanCtType(CtType<T> type) {
263: scanCtSimpleType(type);
264: scanCtGenericElement(type);
265: }
266:
267: /**
268: * Scans an abstract typed element.
269: */
270: public <T> void scanCtTypedElement(CtTypedElement<T> e) {
271: }
272:
273: /**
274: * Scans an abstract variable declaration.
275: */
276: public <T> void scanCtVariable(CtVariable<T> v) {
277: scanCtNamedElement(v);
278: scanCtTypedElement(v);
279: }
280:
281: /**
282: * Scans an abstract variable reference.
283: */
284: public <T> void scanCtVariableReference(
285: CtVariableReference<T> reference) {
286: scanCtReference(reference);
287: }
288:
289: /**
290: * Generically scans a collection of meta-model references.
291: */
292: public void scanReferences(
293: Collection<? extends CtReference> references) {
294: if (references != null) {
295: for (CtReference r : references) {
296: scan(r);
297: }
298: }
299: }
300:
301: public <A extends Annotation> void visitCtAnnotation(
302: CtAnnotation<A> annotation) {
303: scanCtElement(annotation);
304: }
305:
306: public <A extends Annotation> void visitCtAnnotationType(
307: CtAnnotationType<A> annotationType) {
308: scanCtSimpleType(annotationType);
309: }
310:
311: public void visitCtAnonymousExecutable(CtAnonymousExecutable e) {
312: scanCtElement(e);
313: scanCtModifiable(e);
314: }
315:
316: public <T, E extends CtExpression<?>> void visitCtArrayAccess(
317: CtArrayAccess<T, E> arrayAccess) {
318: scanCtTargetedExpression(arrayAccess);
319: }
320:
321: public <T> void visitCtArrayTypeReference(
322: CtArrayTypeReference<T> reference) {
323: visitCtTypeReference(reference);
324: }
325:
326: public <T> void visitCtAssert(CtAssert<T> asserted) {
327: scanCtStatement(asserted);
328: }
329:
330: public <T, A extends T> void visitCtAssignment(
331: CtAssignment<T, A> assignement) {
332: scanCtExpression(assignement);
333: scanCtStatement(assignement);
334: }
335:
336: public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) {
337: scanCtExpression(operator);
338: }
339:
340: public <R> void visitCtBlock(CtBlock<R> block) {
341: scanCtStatement(block);
342: }
343:
344: public void visitCtBreak(CtBreak breakStatement) {
345: scanCtCFlowBreak(breakStatement);
346: }
347:
348: public <E> void visitCtCase(CtCase<E> caseStatement) {
349: scanCtStatement(caseStatement);
350: }
351:
352: public void visitCtCatch(CtCatch catchBlock) {
353: scanCtCodeElement(catchBlock);
354: }
355:
356: public <T> void visitCtClass(CtClass<T> ctClass) {
357: scanCtType(ctClass);
358: }
359:
360: public <T> void visitCtConditional(CtConditional<T> conditional) {
361: scanCtExpression(conditional);
362: }
363:
364: public <T> void visitCtConstructor(CtConstructor<T> c) {
365: scanCtExecutable(c);
366: }
367:
368: public void visitCtContinue(CtContinue continueStatement) {
369: scanCtCFlowBreak(continueStatement);
370: }
371:
372: public void visitCtDo(CtDo doLoop) {
373: scanCtLoop(doLoop);
374: }
375:
376: public <T extends Enum<?>> void visitCtEnum(CtEnum<T> ctEnum) {
377: visitCtClass(ctEnum);
378: }
379:
380: public <T> void visitCtExecutableReference(
381: CtExecutableReference<T> reference) {
382: scanCtReference(reference);
383: scanCtGenericElementReference(reference);
384: }
385:
386: public <T> void visitCtField(CtField<T> f) {
387: scanCtNamedElement(f);
388: scanCtVariable(f);
389: }
390:
391: public <T> void visitCtFieldAccess(CtFieldAccess<T> fieldAccess) {
392: scanCtTargetedExpression(fieldAccess);
393: visitCtVariableAccess(fieldAccess);
394: }
395:
396: public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
397: scanCtVariableReference(reference);
398: }
399:
400: public void visitCtFor(CtFor forLoop) {
401: scanCtLoop(forLoop);
402: }
403:
404: public void visitCtForEach(CtForEach foreach) {
405: scanCtLoop(foreach);
406: }
407:
408: public void visitCtIf(CtIf ifElement) {
409: scanCtStatement(ifElement);
410: }
411:
412: public <T> void visitCtInterface(CtInterface<T> intrface) {
413: scanCtType(intrface);
414: }
415:
416: public <T> void visitCtInvocation(CtInvocation<T> invocation) {
417: scanCtTargetedExpression(invocation);
418: scanCtStatement(invocation);
419: scanCtAbstractInvocation(invocation);
420: }
421:
422: public <T> void visitCtLiteral(CtLiteral<T> literal) {
423: scanCtExpression(literal);
424: }
425:
426: public <T> void visitCtLocalVariable(
427: CtLocalVariable<T> localVariable) {
428: scanCtVariable(localVariable);
429: scanCtStatement(localVariable);
430: }
431:
432: public <T> void visitCtLocalVariableReference(
433: CtLocalVariableReference<T> reference) {
434: scanCtVariableReference(reference);
435: }
436:
437: public <T> void visitCtMethod(CtMethod<T> m) {
438: scanCtExecutable(m);
439: scanCtTypedElement(m);
440: }
441:
442: public <T> void visitCtNewArray(CtNewArray<T> newArray) {
443: scanCtExpression(newArray);
444: }
445:
446: public <T> void visitCtNewClass(CtNewClass<T> newClass) {
447: scanCtAbstractInvocation(newClass);
448: scanCtTypedElement(newClass);
449: scanCtTargetedExpression(newClass);
450: }
451:
452: public <T, A extends T> void visitCtOperatorAssignement(
453: CtOperatorAssignment<T, A> assignment) {
454: visitCtAssignment(assignment);
455: }
456:
457: public void visitCtPackage(CtPackage ctPackage) {
458: scanCtNamedElement(ctPackage);
459: }
460:
461: public void visitCtPackageReference(CtPackageReference reference) {
462: scanCtReference(reference);
463: }
464:
465: public <T> void visitCtParameter(CtParameter<T> parameter) {
466: scanCtNamedElement(parameter);
467: scanCtVariable(parameter);
468: }
469:
470: public <T> void visitCtParameterReference(
471: CtParameterReference<T> reference) {
472: scanCtVariableReference(reference);
473: }
474:
475: public <R> void visitCtReturn(CtReturn<R> returnStatement) {
476: scanCtCFlowBreak(returnStatement);
477: }
478:
479: public <R> void visitCtStatementList(CtStatementList<R> statements) {
480: scanCtCodeElement(statements);
481: }
482:
483: public <E> void visitCtSwitch(CtSwitch<E> switchStatement) {
484: scanCtStatement(switchStatement);
485: }
486:
487: public void visitCtSynchronized(CtSynchronized synchro) {
488: scanCtStatement(synchro);
489: }
490:
491: public void visitCtThrow(CtThrow throwStatement) {
492: scanCtCFlowBreak(throwStatement);
493: }
494:
495: public void visitCtTry(CtTry tryBlock) {
496: scanCtStatement(tryBlock);
497: }
498:
499: public void visitCtTypeParameter(CtTypeParameter typeParameter) {
500: scanCtElement(typeParameter);
501: }
502:
503: public void visitCtTypeParameterReference(
504: CtTypeParameterReference ref) {
505: visitCtTypeReference(ref);
506: }
507:
508: public <T> void visitCtTypeReference(CtTypeReference<T> reference) {
509: scanCtGenericElementReference(reference);
510: scanCtReference(reference);
511: }
512:
513: public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) {
514: scanCtExpression(operator);
515: }
516:
517: public <T> void visitCtVariableAccess(
518: CtVariableAccess<T> variableAccess) {
519: scanCtExpression(variableAccess);
520: }
521:
522: public void visitCtWhile(CtWhile whileLoop) {
523: scanCtLoop(whileLoop);
524: }
525:
526: }
|