Skip to content

Package: IdentifierState

IdentifierState

nameinstructionbranchcomplexitylinemethod
IdentifierState(Scanner, Integer, Integer, String)
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%
action(Character, Buffer, String)
M: 0 C: 84
100%
M: 0 C: 12
100%
M: 0 C: 7
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
finish(Buffer, String)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: package scanner;
2:
3: import basic.Buffer;
4: import model.Position;
5: import symbols.AbstractSymbol;
6: import symbols.BracketOpenSymbol;
7: import symbols.IdentifierSymbol;
8:
9: /**
10: * This class represents the IdentifierState.
11: *
12: * @author HFW410
13: *
14: */
15: public class IdentifierState extends AbstractState {
16:         /**
17:          * represents the collected Identifier Character as String.
18:          */
19:         private String collectedIdentifier;
20:
21:         /**
22:          * This constructor is used to initialize the IdentifierState.
23:          *
24:          * @param myScanner
25:          * is the used scanner.
26:          * @param beginningColumn
27:          * is the Begin Column of the Symbol
28:          * @param beginningRow
29:          * is the beginning Row of the Symbol
30:          * @param collectedIdentifier
31:          * the collected Identifier Character as String.
32:          */
33:         public IdentifierState(final Scanner myScanner, final Integer beginningColumn,
34:                         final Integer beginningRow, final String collectedIdentifier) {
35:                 super(myScanner, beginningColumn, beginningRow);
36:                 this.collectedIdentifier = collectedIdentifier;
37:         }
38:
39:         @Override
40:         public AbstractState action(final Character character,
41:                         final Buffer<AbstractSymbol> currentResult, final String dataPath)
42:                         throws InterruptedException {
43:                 final AbstractState state;
44:•                if (Character.isLetter(character.charValue())
45:•                                && Character.isUpperCase(character.charValue()) || Character.isDigit(character)
46:•                                || character.equals(ScannerConstants.PERCENTAGE)
47:•                                || character.equals(ScannerConstants.UNDERSCORE)) {
48:                         this.collectedIdentifier = this.collectedIdentifier + character.toString();
49:                         this.getMyScanner().skip();
50:                         state = this;
51:•                } else if (character.equals(ScannerConstants.BRACKETOPENSIGN)) {
52:                         this.finish(currentResult, dataPath);
53:                         currentResult.put(new BracketOpenSymbol(new Position(this.getBeginningRow(),
54:                                         this.getMyScanner().getColumnCounter(), dataPath)));
55:                         this.getMyScanner().skip();
56:                         state = new IdentifierTypeVariableState1(this.getMyScanner(),
57:                                         this.getBeginningColumn(), this.getBeginningRow());
58:
59:                 } else {
60:                         this.finish(currentResult, dataPath);
61:                         state = this.getMyScanner().getSelectionState();
62:                 }
63:                 return state;
64:         }
65:
66:         @Override
67:         protected void finish(final Buffer<AbstractSymbol> currentResult, final String dataPath)
68:                         throws InterruptedException {
69:                 currentResult.put(new IdentifierSymbol(this.collectedIdentifier,
70:                                 new Position(this.getBeginningRow(), this.getBeginningColumn(), dataPath)));
71:         }
72:
73: }