01: /*
02: * Spoon - http://spoon.gforge.inria.fr/
03: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
04: *
05: * This software is governed by the CeCILL-C License under French law and
06: * abiding by the rules of distribution of free software. You can use, modify
07: * and/or redistribute the software under the terms of the CeCILL-C license as
08: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13: *
14: * The fact that you are presently reading this means that you have had
15: * knowledge of the CeCILL-C license and that you accept its terms.
16: */
17:
18: package spoon.reflect.factory;
19:
20: import java.io.Serializable;
21: import java.util.Collection;
22:
23: import spoon.processing.FactoryAccessor;
24: import spoon.reflect.Factory;
25: import spoon.reflect.declaration.CtElement;
26:
27: /**
28: * This class is the superclass for all the sub-factories of
29: * {@link spoon.reflect.Factory}.
30: */
31: public abstract class SubFactory implements Serializable,
32: FactoryAccessor {
33:
34: private static final long serialVersionUID = 1L;
35:
36: Factory factory;
37:
38: /**
39: * The sub-factory constructor takes an instance of the parent factory.
40: */
41: public SubFactory(Factory factory) {
42: super ();
43: this .factory = factory;
44: }
45:
46: /**
47: * Sets the parent factory (discouraged).
48: */
49: public void setFactory(Factory factory) {
50: this .factory = factory;
51: }
52:
53: public Factory getFactory() {
54: return factory;
55: }
56:
57: /**
58: * Generically sets the parent of a set of elements or lists of elements.
59: *
60: * @param parent
61: * the parent
62: * @param elements
63: * some {@link CtElement} or lists of {@link CtElement}
64: */
65: protected void setParent(CtElement parent, Object... elements) {
66: for (Object o : elements) {
67: if (o instanceof CtElement) {
68: ((CtElement) o).setParent(parent);
69: } else if (o instanceof Collection) {
70: for (Object o2 : (Collection<?>) o) {
71: ((CtElement) o2).setParent(parent);
72: }
73: }
74: }
75: }
76:
77: }
|