01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2005 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.parser;
20:
21: import xtc.Constants;
22:
23: /**
24: * A module name as a node.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.5 $
28: */
29: public class ModuleName extends Name {
30:
31: /**
32: * Create a new module name.
33: *
34: * @param name The name.
35: */
36: public ModuleName(String name) {
37: super (name);
38: }
39:
40: public boolean equals(Object o) {
41: if (this == o)
42: return true;
43: if (!(o instanceof ModuleName))
44: return false;
45: return name.equals(((ModuleName) o).name);
46: }
47:
48: /**
49: * Rename this module name. If this module name is a key in the
50: * specified module map, this method returns a new module name that
51: * equals the mapping's value. The new module name's {@link
52: * Constants#ORIGINAL original} property is set to be this module
53: * name's original name (i.e., this module name's original property
54: * if it has that property or this module name if it does not).
55: * Otherwise, this method returns this module name.
56: *
57: * @param renaming The module map.
58: * @return The renamed module name.
59: */
60: public ModuleName rename(ModuleMap renaming) {
61: if (renaming.containsKey(this )) {
62: ModuleName original = this .hasProperty(Constants.ORIGINAL) ? (ModuleName) this
63: .getProperty(Constants.ORIGINAL)
64: : this ;
65: ModuleName newName = new ModuleName(renaming.get(this).name);
66: newName.setProperty(Constants.ORIGINAL, original);
67: return newName;
68:
69: } else {
70: return this;
71: }
72: }
73:
74: }
|