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.factory;
019:
020: import java.util.Collection;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import spoon.reflect.Factory;
025: import spoon.reflect.declaration.CtMethod;
026: import spoon.reflect.eval.PartialEvaluator;
027: import spoon.reflect.eval.SymbolicEvaluationPath;
028: import spoon.reflect.eval.SymbolicEvaluator;
029: import spoon.reflect.eval.SymbolicEvaluatorObserver;
030: import spoon.reflect.eval.SymbolicInstance;
031: import spoon.reflect.eval.observer.SymbolicEvaluationPathsMaker;
032: import spoon.reflect.reference.CtTypeReference;
033: import spoon.support.reflect.eval.VisitorPartialEvaluator;
034: import spoon.support.reflect.eval.VisitorSymbolicEvaluator;
035:
036: /**
037: * A factory to create some evaluation utilities on the Spoon metamodel.
038: */
039: public class EvalFactory extends SubFactory {
040:
041: private static final long serialVersionUID = 1L;
042:
043: /**
044: * Creates the evaluation factory.
045: */
046: public EvalFactory(Factory factory) {
047: super (factory);
048: }
049:
050: /**
051: * Creates a partial evaluator on the Spoon meta-model.
052: */
053: public PartialEvaluator createPartialEvaluator() {
054: return new VisitorPartialEvaluator();
055: }
056:
057: /**
058: * Creates a symbolic evaluator on the Spoon meta-model.
059: *
060: * @param observers
061: * the observers to be notified of the the evaluation progress
062: */
063: public SymbolicEvaluator createSymbolicEvaluator(
064: SymbolicEvaluatorObserver... observers) {
065: return new VisitorSymbolicEvaluator(observers);
066: }
067:
068: /**
069: * Creates a new symbolic instance.
070: *
071: * @param evaluator
072: * the evaluator
073: * @param concreteType
074: * the type of the instance
075: * @param isType
076: * tells if it is a type instance or a regular instance
077: */
078: public <T> SymbolicInstance<T> createSymbolicInstance(
079: SymbolicEvaluator evaluator,
080: CtTypeReference<T> concreteType, boolean isType) {
081: return new SymbolicInstance<T>(evaluator, concreteType, isType);
082: }
083:
084: /**
085: * Gets the symbolic evaluation paths of the program, as calculated by
086: * {@link spoon.reflect.eval.SymbolicEvaluator}.
087: *
088: * @param entryPoints
089: * the entry point methods
090: * @return a map containing the paths for each entry point
091: */
092: @SuppressWarnings("unchecked")
093: public Map<CtMethod<?>, Collection<SymbolicEvaluationPath>> createSymbolicEvaluationPaths(
094: Collection<CtMethod<?>> entryPoints) {
095: Map<CtMethod<?>, Collection<SymbolicEvaluationPath>> results = new HashMap<CtMethod<?>, Collection<SymbolicEvaluationPath>>();
096: for (CtMethod<?> m : entryPoints) {
097: SymbolicEvaluationPathsMaker pathsMaker = new SymbolicEvaluationPathsMaker();
098: SymbolicEvaluator evaluator = createSymbolicEvaluator(pathsMaker);
099: evaluator.invoke(m);
100: results.put(m, pathsMaker.getPaths());
101: }
102: return results;
103: }
104: }
|