Skip to content

Package: Scanner

Scanner

nameinstructionbranchcomplexitylinemethod
Scanner(Buffer)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getBuffer()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getColumnCounter()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getCurrentExpression()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getRowCounter()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
handleRowEnd()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
increaseColumnCounter()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isPackageDescriptionFileScanner()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
scan(InputStream, String)
M: 4 C: 92
96%
M: 3 C: 13
81%
M: 3 C: 6
67%
M: 1 C: 17
94%
M: 0 C: 1
100%
setCurrentExpression(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
skip()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
toPackageDescriptionFileScanner()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toSymbolSequence(InputStream, String, Scanner)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: package scanner;
2:
3: import java.io.BufferedReader;
4: import java.io.IOException;
5: import java.io.InputStream;
6: import java.io.InputStreamReader;
7:
8: import model.Position;
9: import symbols.AbstractSymbol;
10: import symbols.EndSymbol;
11: import symbols.WrongTypeError;
12: import basic.Buffer;
13: import basic.PrinterConstants;
14:
15: /**
16: * This interface represents the Scanner.
17: *
18: * @author HFW410
19: *
20: */
21: public abstract class Scanner {
22:
23:         /**
24:          * This attribute represents a buffer of Symbols.
25:          */
26:         private final Buffer<AbstractSymbol> buffer;
27:
28:         /**
29:          * This attribute represents the counter for the rows to show rownumbers.
30:          */
31:         private Integer rowCounter;
32:         /**
33:          * This attributer representes the counter for the columns to show columnnumbers.
34:          */
35:         private Integer columnCounter;
36:         /**
37:          * This attribute represents the currentExpression as String.
38:          */
39:         private String currentExpression;
40:
41:         /**
42:          * This is the constructoer to set the attributes.
43:          *
44:          * @param buffer
45:          * is the symbolbuffer.
46:          */
47:         public Scanner(final Buffer<AbstractSymbol> buffer) {
48:                 this.buffer = buffer;
49:                 this.currentExpression = ScannerConstants.EMPTYSTRING;
50:                 this.columnCounter = ScannerConstants.FIRST_POSITION;
51:                 this.rowCounter = ScannerConstants.FIRST_POSITION;
52:         }
53:
54:         /**
55:          * this methode will be used to call the Scanner.
56:          *
57:          * @param input
58:          * is the input stream.
59:          * @param dataPath
60:          * is the path of the file, which will be scanned.
61:          * @param scanner
62:          * is the Scanner, which is used.
63:          * @throws ScannerException
64:          * is the Exception from all scanners.
65:          * @throws InterruptedException
66:          * if there is any problem with the buffer.
67:          * @throws IOException
68:          * from the Stream.
69:          */
70:         protected static void toSymbolSequence(final InputStream input, final String dataPath,
71:                         final Scanner scanner) throws ScannerException, InterruptedException, IOException {
72:                 scanner.scan(input, dataPath);
73:         }
74:
75:         /**
76:          * This method will be used to create a Symbolsequence.
77:          *
78:          * @param input
79:          * is the inputstream.
80:          * @param dataPath
81:          * is the dataPath to the file.
82:          * @throws ScannerException
83:          * is the Exception from all scanners.
84:          * @throws InterruptedException
85:          * for a Interruption in the method
86:          * @throws IOException
87:          * is the Exception for the input or output
88:          */
89:         private void scan(final InputStream input, final String dataPath) throws ScannerException,
90:                         InterruptedException, IOException {
91:•                if (input == null) {
92:                         throw new ScannerException(ScannerConstants.NO_STREAM_EXCEPTION);
93:                 } else {
94:                         final BufferedReader reader =
95:                                         new BufferedReader(new InputStreamReader(input, PrinterConstants.ENCODING));
96:                         String line = reader.readLine();
97:                         // handle BOM properly
98:•                        if (this.rowCounter == ScannerConstants.FIRST_POSITION
99:                                         && this.columnCounter == ScannerConstants.FIRST_POSITION) {
100:•                                if (line != null && !line.isEmpty() && line.charAt(0) == ScannerConstants.UTF8_BOM) {
101:                                         line = line.substring(1);
102:                                 }
103:                         }
104:                         AbstractState state = this.getSelectionState();
105:•                        while (line != null) {
106:                                 this.setCurrentExpression(line + '\n');
107:•                                while (this.getCurrentExpression().length() > 0) {
108:                                         state =
109:                                                         state.action(this.getCurrentExpression().charAt(0), this.getBuffer(),
110:                                                                         dataPath);
111:                                 }
112:                                 line = reader.readLine();
113:                         }
114:                         state.finish(this.getBuffer(), dataPath);
115:                         this.getBuffer().put(
116:                                         new EndSymbol(new Position(this.getRowCounter(), this.getColumnCounter(),
117:                                                         dataPath)));
118:                 }
119:         }
120:
121:         /**
122:          *
123:          * @return the CulumnCounter
124:          */
125:         protected Integer getColumnCounter() {
126:                 return this.columnCounter;
127:         }
128:
129:         /**
130:          *
131:          * @return the RowCounter
132:          */
133:         protected Integer getRowCounter() {
134:                 return this.rowCounter;
135:         }
136:
137:         /**
138:          * this method increase the columnCounter.
139:          */
140:         private void increaseColumnCounter() {
141:                 this.columnCounter = this.columnCounter + 1;
142:         }
143:
144:         /**
145:          * this method increase the RowCounter.
146:          */
147:         protected void handleRowEnd() {
148:                 this.rowCounter = this.rowCounter + 1;
149:                 this.columnCounter = ScannerConstants.FIRST_POSITION;
150:         }
151:
152:         /**
153:          *
154:          * @return the Buffer
155:          */
156:         private Buffer<AbstractSymbol> getBuffer() {
157:                 return this.buffer;
158:         }
159:
160:         /**
161:          *
162:          * @return the current Expression
163:          */
164:         private String getCurrentExpression() {
165:                 return this.currentExpression;
166:         }
167:
168:         /**
169:          * set the currentExpression.
170:          *
171:          * @param currentExpression
172:          * is the currentExpression
173:          */
174:         private void setCurrentExpression(final String currentExpression) {
175:                 this.currentExpression = currentExpression;
176:         }
177:
178:         /**
179:          * This method skips the first character and increments the Column Counter.
180:          */
181:         protected void skip() {
182:                 this.currentExpression = this.currentExpression.substring(1);
183:                 this.increaseColumnCounter();
184:         }
185:
186:         /**
187:          * @return the SelectionState of the special scanner.
188:          */
189:         protected abstract AbstractState getSelectionState();
190:
191:         /**
192:          * @param beginningRow
193:          * is the beginning row of the symbol
194:          * @param beginningColumn
195:          * is the beginning column of the symbol
196:          * @return AbstractState a reststate of the special scanner with the given beginning row and
197:          * column.
198:          */
199:         protected abstract AbstractState getRestState(Integer beginningRow, Integer beginningColumn);
200:
201:         // TODO: Statische Methode toSymbolSequence, da neuen Scanner erstellen und to Symbolsequence
202:         // aufrufen, aber wie neuen Scanner erstellen?
203:
204:         /**
205:          * @return an error, if the symbol is not a descriptionfile scanner
206:          */
207:         protected PackageDescriptionFileScanner toPackageDescriptionFileScanner() {
208:                 throw new WrongTypeError(ScannerConstants.WTE_DESCRIPTIONFILESCANNER);
209:         }
210:
211:         /**
212:          *
213:          * @return true if the Scanner is a PackageDescriptionFilescanner.
214:          */
215:         protected Boolean isPackageDescriptionFileScanner() {
216:                 return Boolean.FALSE;
217:         }
218: }