001: package Schmortopf.FileStructure.Descriptions;
002:
003: import java.util.Vector;
004: import Schmortopf.Utility.Vectorizable;
005: import Schmortopf.Utility.StringUtilities;
006:
007: public class GenericTypeRestrictionDescription implements Vectorizable {
008:
009: public static final int WildCardCaptureIsNone = 0; // No wildcard capture
010: public static final int WildCardCaptureIsExtends = 1; // <? extends className>
011: public static final int WildCardCaptureIsSuper = 2; // <? super className>
012:
013: public int wildcardType = WildCardCaptureIsNone;
014: public StringWithPosition className = new StringWithPosition();
015:
016: public GenericTypeRestrictionDescription() {
017: } // Constructor
018:
019: public GenericTypeRestrictionDescription(final int theWildCardType,
020: final StringWithPosition theClassName) {
021: this .wildcardType = theWildCardType;
022: this .className = theClassName;
023: } // Constructor
024:
025: /**
026: * Implementation of the Vectorizable interface.
027: * Sets the object's content to the passed vectorRepresentation.
028: */
029: public void createFromVectorRepresentation(final Vector rep) {
030: int repCounter = 0;
031: Vector classNameRepresentation = (Vector) rep
032: .elementAt(repCounter++);
033: this .className = new StringWithPosition();
034: this .className
035: .createFromVectorRepresentation(classNameRepresentation);
036: this .wildcardType = ((Integer) rep.elementAt(repCounter++))
037: .intValue();
038: }
039:
040: /**
041: * Implementation of the Vectorizable interface.
042: * Returns the VectorRepresentation of the object's datacontent
043: */
044: public Vector getVectorRepresentation() throws Exception {
045: final Vector rep = new Vector();
046: rep.addElement(this .className.getVectorRepresentation());
047: rep.addElement(new Integer(this .wildcardType));
048: return rep;
049: } // getVectorRepresentation
050:
051: /**
052: * Returns the text description without <> brackets.
053: */
054: public String getJavaSourceCompatibleTextDescription() {
055: StringBuffer buf = new StringBuffer();
056: switch (wildcardType) {
057: case WildCardCaptureIsNone:
058: buf.append(this .className.content);
059: break;
060: case WildCardCaptureIsExtends:
061: buf.append("? extends ");
062: buf.append(this .className.content);
063: break;
064: case WildCardCaptureIsSuper:
065: buf.append("? super ");
066: buf.append(this .className.content);
067: break;
068: default:
069: buf.append("undefined");
070: } // switch
071: return buf.toString();
072: } // getJavaSourceCompatibleTextDescription
073:
074: /**
075: * Returns the text description without <> brackets.
076: *
077: * Used for the name of method leafs in the fileComponentsTree
078: * and the CodeCompletion menu.
079: */
080: public String getShortTextDescription() {
081: StringBuffer buf = new StringBuffer();
082: String lastIdentifier = this
083: .getLastIdentifier(this .className.content);
084: switch (wildcardType) {
085: case WildCardCaptureIsNone:
086: buf.append(lastIdentifier);
087: break;
088: case WildCardCaptureIsExtends:
089: buf.append("? extends ");
090: buf.append(lastIdentifier);
091: break;
092: case WildCardCaptureIsSuper:
093: buf.append("? super ");
094: buf.append(lastIdentifier);
095: break;
096: default:
097: buf.append("undefined");
098: } // switch
099: return buf.toString();
100: } // getShortTextDescription
101:
102: /**
103: * Returns the last token in a string delimited by points.
104: */
105: private String getLastIdentifier(String fullyQualifiedName) {
106: String[] tokens = StringUtilities.SplitString(
107: fullyQualifiedName, ".");
108: return tokens[tokens.length - 1]; // The last token
109: }
110:
111: public String toString() {
112: return "GenericTypeRestrictionDescription for class "
113: + this .className.content + " and wildcardtype= "
114: + this .wildcardType;
115: } // toString
116:
117: } // GenericTypeRestrictionDescription
|