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.processing;
019:
020: import java.util.Set;
021:
022: import spoon.reflect.Factory;
023: import spoon.reflect.declaration.CtElement;
024:
025: /**
026: * This class defines an abstract processor to be subclassed by the user for
027: * defining new manual processors. A manual processor should override the init
028: * method (called once) and scan the meta-model manually.
029: */
030: public abstract class AbstractManualProcessor implements
031: Processor<CtElement> {
032:
033: Factory factory;
034:
035: /**
036: * Empty constructor only for all processors (invoked by Spoon).
037: */
038: @SuppressWarnings("unchecked")
039: public AbstractManualProcessor() {
040: }
041:
042: /**
043: * Invalid method in this context.
044: */
045: protected void addProcessedElementType(
046: Class<? extends CtElement> elementType) {
047: }
048:
049: public Environment getEnvironment() {
050: return getFactory().getEnvironment();
051: }
052:
053: final public Factory getFactory() {
054: return this .factory;
055: }
056:
057: /**
058: * Invalid method in this context.
059: */
060: public final Set<Class<? extends CtElement>> getProcessedElementTypes() {
061: return null;
062: }
063:
064: /**
065: * Invalid method in this context.
066: */
067: public final TraversalStrategy getTraversalStrategy() {
068: return TraversalStrategy.PRE_ORDER;
069: }
070:
071: public void init() {
072: }
073:
074: /**
075: * Invalid method in this context.
076: */
077: public final boolean isPrivileged() {
078: return false;
079: }
080:
081: /**
082: * Always returns false in this context.
083: */
084: public final boolean isToBeProcessed(CtElement candidate) {
085: return false;
086: }
087:
088: /**
089: * Does nothing in this context.
090: */
091: public final void process(CtElement element) {
092: }
093:
094: public void processingDone() {
095: // do nothing by default
096: }
097:
098: public final void setFactory(Factory factory) {
099: this .factory = factory;
100: }
101:
102: public final void initProperties(ProcessorProperties properties) {
103: AbstractProcessor.initProperties(this, properties);
104: }
105:
106: }
|