001: /*
002: * Author: Mike Atkinson
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package net.sourceforge.jrefactory.ast;
010:
011: import java.util.*;
012: import net.sourceforge.jrefactory.ast.Node;
013: import net.sourceforge.jrefactory.parser.JavaParser;
014: import net.sourceforge.jrefactory.parser.JavaParserTreeConstants;
015: import net.sourceforge.jrefactory.parser.JavaParserVisitor;
016: import net.sourceforge.jrefactory.parser.NamedToken;
017: import net.sourceforge.jrefactory.parser.Token;
018:
019: /**
020: * Description of the Class
021: *
022: * @author Mike Atkinson
023: * @since jRefactory 2.9.0, created October 16, 2003
024: */
025: public class ASTClassOrInterfaceType extends ASTName {
026: /**
027: * Constructor for the ASTClassOrInterfaceType node.
028: *
029: * @param identifier The id of this node (JJTCLASSORINTERFACETYPE).
030: */
031: public ASTClassOrInterfaceType(int identifier) {
032: super (identifier);
033: }
034:
035: /**
036: * Constructor for the ASTClassOrInterfaceType node.
037: *
038: * @param parser The JavaParser that created this ASTClassOrInterfaceType node.
039: * @param identifier The id of this node (JJTCLASSORINTERFACETYPE).
040: */
041: public ASTClassOrInterfaceType(JavaParser parser, int identifier) {
042: super (parser, identifier);
043: }
044:
045: /**
046: * Constructor for the ASTClassOrInterfaceType node.
047: *
048: * @param name The name of the class or interface.
049: */
050: public ASTClassOrInterfaceType(ASTName name) {
051: super (JavaParserTreeConstants.JJTCLASSORINTERFACETYPE);
052: children = name.children;
053: }
054:
055: /**
056: * Accept the visitor. *
057: *
058: * @param visitor An implementation of JavaParserVisitor that processes the ASTClassOrInterfaceType node.
059: * @param data Some data being passed between the visitor methods.
060: * @return Usually the data parameter (possibly modified).
061: */
062: public Object jjtAccept(JavaParserVisitor visitor, Object data) {
063: return visitor.visit(this , data);
064: }
065:
066: /**
067: * Determines if two names start with the same series of items
068: *
069: * @param otherName Description of Parameter
070: * @return Description of the Returned Value
071: */
072: public boolean startsWith(ASTClassOrInterfaceType otherName) {
073: // To start with the other name, the other name must be less than or equal in parts
074: if (otherName.getNameSize() > getNameSize()) {
075: return false;
076: }
077:
078: // Look for the point where they are different
079: int last = Math.min(otherName.getNameSize(), getNameSize());
080: for (int ndx = 0; ndx < last; ndx++) {
081: if (!getNamePart(ndx).equals(otherName.getNamePart(ndx))) {
082: return false;
083: }
084: }
085:
086: // They must be the same
087: return true;
088: }
089:
090: /**
091: * Change starting part. Presumes that otherName is less than the length of the current name.
092: *
093: * @param oldBase Description of Parameter
094: * @param newBase Description of Parameter
095: * @return Description of the Returned Value
096: */
097: public ASTClassOrInterfaceType changeStartingPart(
098: ASTClassOrInterfaceType oldBase,
099: ASTClassOrInterfaceType newBase) {
100: ASTClassOrInterfaceType result = new ASTClassOrInterfaceType(
101: JavaParserTreeConstants.JJTCLASSORINTERFACETYPE);
102:
103: int last = newBase.getNameSize();
104: for (int ndx = 0; ndx < last; ndx++) {
105: result.addNamePart(newBase.getNamePart(ndx));
106: }
107:
108: int end = getNameSize();
109: int start = oldBase.getNameSize();
110: for (int ndx = start; ndx < end; ndx++) {
111: result.addNamePart(getNamePart(ndx));
112: }
113: result.setLineAndColumnInfo(getBeginLine(), getBeginColumn(),
114: getEndLine(), getEndColumn());
115:
116: return result;
117: }
118:
119: /**
120: * Change starting part. Presumes that otherName is less than the length of the current name.
121: *
122: * @param oldBase Description of Parameter
123: * @param newBase Description of Parameter
124: * @return Description of the Returned Value
125: */
126: public ASTClassOrInterfaceType changeStartingPart(
127: ASTClassOrInterfaceType oldBase, ASTName newBase) {
128: ASTClassOrInterfaceType result = new ASTClassOrInterfaceType(
129: JavaParserTreeConstants.JJTCLASSORINTERFACETYPE);
130:
131: int last = newBase.getNameSize();
132: for (int ndx = 0; ndx < last; ndx++) {
133: result.addNamePart(newBase.getNamePart(ndx));
134: }
135:
136: int end = getNameSize();
137: int start = oldBase.getNameSize();
138: for (int ndx = start; ndx < end; ndx++) {
139: result.addNamePart(getNamePart(ndx));
140: }
141: result.setLineAndColumnInfo(getBeginLine(), getBeginColumn(),
142: getEndLine(), getEndColumn());
143:
144: return result;
145: }
146: }
|