001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.casetool.patternimplementor;
012:
013: public class SourceCode extends java.util.Vector {
014:
015: public String toString() {
016: String retval = new String();
017:
018: retval = toText(true);
019: retval = retval + "-----------------\nNumber of classes : "
020: + nofClasses() + "\n";
021:
022: /*
023: * if(nofClasses() > 4) { retval = retval + getClass(0); }
024: */
025: return retval.trim();
026: }
027:
028: public String getClassName() {
029: for (int i = 0; i < size(); i++) {
030: if (elementAt(i) instanceof ClassDelimiter) {
031: return ((ClassDelimiter) elementAt(i)).getName();
032: }
033: }
034: return null;
035: }
036:
037: public String toText() {
038: return toText(false);
039: }
040:
041: public String toText(boolean includingClassDelimiter) {
042: String retval = new String();
043: for (int i = 0; i < size(); i++) {
044: if (includingClassDelimiter) {
045: retval = retval + elementAt(i).toString() + "\n";
046: } else {
047: if (!(elementAt(i) instanceof ClassDelimiter)) {
048: retval = retval + elementAt(i).toString() + "\n";
049: }
050: }
051:
052: }
053: return retval;
054: }
055:
056: public void add() {
057: add("");
058: }
059:
060: public boolean add(Object sc) {
061: if (sc != null) {
062: return super .add(sc);
063: }
064:
065: return false;
066: }
067:
068: public void add(SourceCode sc) {
069: for (int i = 0; i < sc.size(); i++) {
070: add(sc.elementAt(i));
071: }
072: }
073:
074: public void beginClass(String name) {
075: if (name.indexOf(".java") == -1) {
076: add(new ClassDelimiter(name + ".java"));
077: } else {
078: add(new ClassDelimiter(name));
079: }
080: }
081:
082: /*
083: * class Context { private String context; Context(String context){
084: * this.context = context; } public String toString() { return "// context :
085: * "+context; } }
086: */
087: public int nofClasses() {
088: int counter = 0;
089:
090: //System.out.println(".................................");
091: for (int i = 0; i < size(); i++) {
092: if (elementAt(i) instanceof ClassDelimiter) {
093: counter++;
094: }
095: }
096:
097: return counter;
098: }
099:
100: /**
101: *
102: * @param index -
103: * index of the class to be returned
104: * @return the index:th class. The classes are numbered from 0 to
105: * nofClasses-1. If the index given outside the possible range, an
106: * empty SourceCode will be returned.
107: */
108: public SourceCode getClass(int index) {
109: int counter = -1;
110: SourceCode retval = new SourceCode();
111:
112: //System.out.println(".................................");
113: for (int i = 0; i < size(); i++) {
114: if (elementAt(i) instanceof ClassDelimiter) {
115: counter++;
116:
117: if (counter == index) {
118: int j = i + 1;
119: retval.add(elementAt(i));
120:
121: while ((j < size())
122: && !(elementAt(j) instanceof ClassDelimiter)) {
123: retval.add(elementAt(j));
124: j++;
125: }
126:
127: return retval;
128: }
129: }
130: }
131:
132: return retval;
133: }
134:
135: /*
136: * public void setContext(String context) { add(new Context(context)); }
137: */
138: class ClassDelimiter {
139:
140: private String name;
141:
142: ClassDelimiter(String name) {
143: this .name = name;
144: }
145:
146: public String toString() {
147: return "8<--------- " + name + " -----------";
148: }
149:
150: public String getName() {
151: return name;
152: }
153: }
154: }
|