Skip to content

Package: TypeExpressionState

TypeExpressionState

nameinstructionbranchcomplexitylinemethod
TypeExpressionState()
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%
parse(RouterSoftware, TempVariableType, Buffer, TypeFileParser)
M: 34 C: 37
52%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 4 C: 11
73%
M: 0 C: 1
100%
posixCharacterReplacement(String)
M: 0 C: 101
100%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 0 C: 22
100%
M: 0 C: 1
100%

Coverage

1: package parser.states.typestates;
2:
3: import java.util.ArrayList;
4:
5: import basic.Buffer;
6: import model.RouterSoftware;
7: import parser.ParserException;
8: import parser.TypeFileParser;
9: import parser.states.GlobalFunctions;
10: import parser.tempparserobjects.TempVariableType;
11: import symbols.AbstractSymbol;
12: import symbols.ColonSignSymbol;
13: import symbols.StringSymbol;
14:
15: /**
16: *
17: * @author Muri
18: *
19: */
20: public class TypeExpressionState extends AbstractTypeState {
21:
22:         /**
23:          *
24:          * @param tVT
25:          * tempVariableType
26:          * @param buffer
27:          * buffer
28:          * @param tFP
29:          * typeFileParser
30:          * @throws InterruptedException
31:          * InterruptedException
32:          * @throws ParserException
33:          * ParserException
34:          */
35:         @Override
36:         public void parse(final RouterSoftware rs, final TempVariableType tVT,
37:                         final Buffer<AbstractSymbol> buffer, final TypeFileParser tFP)
38:                         throws InterruptedException, ParserException {
39:                 final AbstractSymbol nextSymbol = buffer.peek();
40:•                if (nextSymbol instanceof StringSymbol) {
41:                         String expression = ((StringSymbol) nextSymbol).getText();
42:                         expression = this.posixCharacterReplacement(expression);
43:                         tVT.setRegEx(GlobalFunctions.generateRegEx(expression));
44:                         buffer.remove();
45:•                        if (buffer.peek() instanceof ColonSignSymbol) {
46:                                 tFP.setState(new TypeErrormessageState());
47:                                 buffer.remove();
48:                         } else {
49:                                 throw new ParserException(
50:                                                 "no expected symbol: " + buffer.peek().getClass().getCanonicalName()
51:                                                                 + " expected ColonSignSymbol");
52:                         }
53:                 } else {
54:                         throw new ParserException(
55:                                         "no valid symbol: " + buffer.peek().getClass().getCanonicalName());
56:                 }
57:
58:         }
59:
60:         /**
61:          * This method replaces the POSIX character classes with the appropriated ASCII code.
62:          *
63:          * @param expression
64:          * the expression
65:          * @return new expression
66:          */
67:         public String posixCharacterReplacement(final String expression) {
68:
69:                 final StringBuffer newExpression = new StringBuffer();
70:                 final ArrayList<String> expStringParts = new ArrayList<String>();
71:                 String remainingString = expression;
72:                 Boolean stringIsNotEmpty = true;
73:                 final PosixHashMap hashMap = new PosixHashMap();
74:
75:•                while (stringIsNotEmpty) {
76:                         final String[] splitString1 = remainingString.split("\\[:", 2);
77:•                        if (splitString1.length == 2) {
78:                                 final String[] splitString2 = splitString1[1].split(":\\]", 2);
79:
80:                                 splitString2[0] = hashMap.getHashMap().get(splitString2[0]);
81:
82:•                                if (!splitString1[0].isEmpty()) {
83:                                         expStringParts.add(splitString1[0]);
84:                                 }
85:                                 expStringParts.add(splitString2[0]);
86:                                 remainingString = splitString2[1];
87:                         } else {
88:•                                if (!splitString1[0].isEmpty()) {
89:                                         expStringParts.add(splitString1[0]);
90:                                 }
91:                                 stringIsNotEmpty = false;
92:                         }
93:                 }
94:
95:•                for (int i = 0; i < expStringParts.size(); i++) {
96:                         newExpression.append(expStringParts.get(i));
97:                 }
98:
99:                 return newExpression.toString();
100:         }
101:
102: }