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.support.reflect.declaration;
19:
20: import java.util.Set;
21: import java.util.TreeSet;
22:
23: import spoon.reflect.declaration.CtPackage;
24: import spoon.reflect.declaration.CtSimpleType;
25: import spoon.reflect.reference.CtPackageReference;
26: import spoon.reflect.visitor.CtVisitor;
27:
28: /**
29: * The implementation for {@link spoon.reflect.declaration.CtPackage}.
30: *
31: * @author Renaud Pawlak
32: */
33: public class CtPackageImpl extends CtNamedElementImpl implements
34: CtPackage {
35: private static final long serialVersionUID = 1L;
36:
37: Set<CtPackage> packs = new TreeSet<CtPackage>();
38:
39: Set<CtSimpleType<?>> types = new TreeSet<CtSimpleType<?>>();
40:
41: public CtPackageImpl() {
42: super ();
43: }
44:
45: public void accept(CtVisitor v) {
46: v.visitCtPackage(this );
47: }
48:
49: public CtPackage getDeclaringPackage() {
50: if (parent == null)
51: return null;
52: return getParent(CtPackage.class);
53: }
54:
55: public CtPackage getPackage(String name) {
56: for (CtPackage p : packs) {
57: if (p.getSimpleName().equals(name))
58: return p;
59: }
60: return null;
61: }
62:
63: public Set<CtPackage> getPackages() {
64: return packs;
65: }
66:
67: public String getQualifiedName() {
68: if (getDeclaringPackage() == null)
69: return getSimpleName();
70: return getDeclaringPackage().getQualifiedName() + "."
71: + getSimpleName();
72: }
73:
74: public CtSimpleType<?> getType(String simpleName) {
75: for (CtSimpleType<?> t : types) {
76: if (t.getSimpleName().equals(simpleName)) {
77: return t;
78: }
79: }
80: return null;
81: }
82:
83: public Set<CtSimpleType<?>> getTypes() {
84: return types;
85: }
86:
87: public void setPackages(Set<CtPackage> packs) {
88: this .packs = packs;
89: }
90:
91: public void setTypes(Set<CtSimpleType<?>> types) {
92: this .types = types;
93: }
94:
95: @Override
96: public CtPackageReference getReference() {
97: return getFactory().Package().createReference(this);
98: }
99: }
|