Skip to content

Package: TypeFileParser

TypeFileParser

nameinstructionbranchcomplexitylinemethod
TypeFileParser(RouterSoftware, Buffer)
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
createNVT(String, RegEx, String, Position)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getExtensionsMap()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getState()
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%
getTypeFile()
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%
getVariableTypeList()
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%
gettTE()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
parse()
M: 0 C: 70
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
setState(AbstractTypeState)
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%

Coverage

1: /**
2: *
3: */
4: package parser;
5:
6: import java.util.ArrayList;
7: import java.util.HashMap;
8: import java.util.Map;
9:
10: import basic.Buffer;
11: import model.Comment;
12: import model.Position;
13: import model.RouterSoftware;
14: import model.type.NamedVariableType;
15: import model.type.RegEx;
16: import model.type.TypeFile;
17: import parser.states.typestates.AbstractTypeState;
18: import parser.states.typestates.TypeInitialState;
19: import parser.tempparserobjects.TempTypeExtension;
20: import parser.tempparserobjects.TempTypeExtensionWithoutCondition;
21: import parser.tempparserobjects.TempVariableType;
22: import symbols.AbstractSymbol;
23: import symbols.EndSymbol;
24:
25: /**
26: * @author hfw410wi - Mark Wittig
27: *
28: */
29: public final class TypeFileParser extends AbstractFileParser {
30:
31:         /**
32:          * The associated RouterSoftware.
33:          */
34:         private final RouterSoftware rs;
35:         /**
36:          * the state of this parser.
37:          */
38:         private transient AbstractTypeState state;
39:
40:         /**
41:          * Temporary Object, which is used to fill the final object when every information is collected.
42:          */
43:         private final transient TempVariableType tVT;
44:         /**
45:          * Temporary Object, which is used to fill the final object when every information is collected.
46:          */
47:         private final transient parser.tempparserobjects.TempTypeExtension tTE;
48:
49:         /**
50:          * List of VariableTypes.
51:          */
52:         private final transient Map<String, NamedVariableType> variableTypeList;
53:
54:         /**
55:          * The final AssignmentFile.
56:          */
57:         private final transient TypeFile typeFile;
58:         /**
59:          * The List of TypExtensions.
60:          */
61:         private final transient Map<String, ArrayList<TempTypeExtension>> tempextensionsMap;
62:
63:         /**
64:          * The TypeFileParser will automatically generate a TypeFile after instantiation which can be
65:          * obtained via getTypeFile().
66:          *
67:          * @param rs
68:          * The {@link RouterSoftware} to use.
69:          * @param buffer
70:          * Buffer<Symbol>
71:          * @throws ParserException
72:          * Parser Exception
73:          * @throws InterruptedException
74:          * InterruptedException
75:          */
76:         public TypeFileParser(final RouterSoftware rs, final Buffer<AbstractSymbol> buffer)
77:                         throws InterruptedException, ParserException {
78:                 super(buffer);
79:                 this.rs = rs;
80:                 this.state = new TypeInitialState();
81:                 this.tVT = new TempVariableType();
82:                 this.tTE = new TempTypeExtensionWithoutCondition();
83:                 this.variableTypeList = new HashMap<String, NamedVariableType>();
84:                 this.tempextensionsMap = new HashMap<String, ArrayList<TempTypeExtension>>();
85:                 setFinished(false);
86:                 setComments(new ArrayList<Comment>());
87:                 this.typeFile = parse();
88:
89:         }
90:
91:         /**
92:          *
93:          * @throws InterruptedException
94:          * InterruptedException
95:          * @throws ParserException
96:          * ParserException
97:          * @return TypeFile
98:          */
99:         private TypeFile parse() throws InterruptedException, ParserException {
100:
101:•                while (!this.isFinished()) {
102:•                        if (this.tVT.isReady()) {
103:                                 final NamedVariableType var = createNVT(this.tVT.getName(), this.tVT.getRegEx(),
104:                                                 this.tVT.getErrorMessage(), this.tVT.getPosition());
105:
106:                                 this.getVariableTypeList().put(this.tVT.getName(), var);
107:                                 this.tVT.setReady(false);
108:                         }
109:•                        if (this.getBuffer().peek() instanceof EndSymbol) {
110:                                 this.setFinished(true);
111:
112:                         } else {
113:                                 final AbstractTypeState currentState = this.getState();
114:                                 currentState.parse(this.rs, this.tVT, this.getBuffer(), this);
115:                         }
116:                 }
117:
118:                 return new TypeFile(this.getVariableTypeList(), this.getComments(),
119:                                 this.tempextensionsMap);
120:         }
121:
122:         /**
123:          * yet another totally senseless function for PMD to be quiet. Suppresses "Avoid instantiating
124:          * new objects inside loops" warning.
125:          *
126:          * @param name
127:          * name
128:          * @param expression
129:          * expression
130:          * @param errorMessage
131:          * errorMessage
132:          * @param position
133:          * position
134:          * @return NamedVariableType
135:          */
136:         private NamedVariableType createNVT(final String name, final RegEx expression,
137:                         final String errorMessage, final Position position) {
138:                 return new NamedVariableType(name, expression, errorMessage, position);
139:         }
140:
141:         /**
142:          * @return the state
143:          */
144:         private AbstractTypeState getState() {
145:                 return this.state;
146:         }
147:
148:         /**
149:          * @param state
150:          * the state to set
151:          */
152:         public void setState(final AbstractTypeState state) {
153:                 this.state = state;
154:         }
155:
156:         /**
157:          * @return the variableTypeList
158:          */
159:         private Map<String, NamedVariableType> getVariableTypeList() {
160:                 return this.variableTypeList;
161:         }
162:
163:         /**
164:          * Returns the desired Type File which is automatically created right after instantiation.
165:          *
166:          * @return the typeFile
167:          */
168:         public TypeFile getTypeFile() {
169:                 return this.typeFile;
170:         }
171:
172:         /**
173:          * @return the extensionsMap
174:          */
175:         public Map<String, ArrayList<TempTypeExtension>> getExtensionsMap() {
176:                 return this.tempextensionsMap;
177:         }
178:
179:         /**
180:          * @return the tTE
181:          */
182:         public parser.tempparserobjects.TempTypeExtension gettTE() {
183:                 return this.tTE;
184:         }
185:
186: }