Skip to content

Package: TypeExtensionProcessor

TypeExtensionProcessor

nameinstructionbranchcomplexitylinemethod
TypeExtensionProcessor(TempTypeExtension, Map)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
createTypeExtension(TypeFileManager)
M: 171 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 31 C: 0
0%
M: 1 C: 0
0%
getTypes()
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%

Coverage

1: /**
2: *
3: */
4: package parser;
5:
6: import java.util.Iterator;
7: import java.util.Map;
8:
9: import model.type.NamedVariableType;
10: import model.type.RegEx;
11: import model.type.RegExPart;
12: import model.type.TypeDoesNotExistException;
13: import model.type.TypeExtension;
14: import model.type.TypeExtensionWithCondition;
15: import model.type.TypeExtensionWithoutCondition;
16: import model.type.TypeFileManager;
17: import parser.tempparserobjects.TempTypeExtension;
18: import parser.tempparserobjects.TempTypeExtensionWithCondition;
19:
20: /**
21: * @author Hendrik
22: *
23: */
24: public class TypeExtensionProcessor {
25:         /**
26:          * the temp Extension.
27:          */
28:         private final TempTypeExtension tempExt;
29:
30:         /**
31:          * the list of Types.
32:          */
33:         private final Map<String, NamedVariableType> types;
34:
35:         /**
36:          *
37:          * @param temp
38:          * the TempTypExtension
39:          * @param types
40:          * the types
41:          * @throws TypeDoesNotExistException
42:          * TypeDoesNotExistException
43:          */
44:         public TypeExtensionProcessor(final TempTypeExtension temp,
45:                         final Map<String, NamedVariableType> types)
46:                         throws TypeDoesNotExistException {
47:                 this.tempExt = temp;
48:                 this.types = types;
49:
50:         }
51:
52:         /**
53:          * create a association to the type for a TypeExtention.
54:          *
55:          * @param typeFileManager
56:          * The type file manager
57:          *
58:          * @return the type extension
59:          *
60:          * @throws TypeDoesNotExistException
61:          * if Type does not exist
62:          */
63:         public TypeExtension createTypeExtension(final TypeFileManager typeFileManager)
64:                         throws TypeDoesNotExistException {
65:                 final Map<String, NamedVariableType> globalTypes = typeFileManager.getAlltypes();
66:•                if (this.types.containsKey(this.tempExt.getName())) {
67:•                        if (tempExt.hasCondition()) {
68:                                 // expression
69:                                 final Iterator<RegExPart> i = this.tempExt.getRegEx().getParts().iterator();
70:                                 final RegEx expression = new RegEx();
71:•                                while (i.hasNext()) {
72:                                         expression.getParts().add(i.next());
73:                                 }
74:
75:                                 final String conditionIdentifier =
76:                                                 ((TempTypeExtensionWithCondition) this.tempExt).getVariable();
77:•                                if (globalTypes.get(conditionIdentifier) == null) {
78:                                         throw new TypeDoesNotExistException(
79:                                                         basic.PrinterConstants.TYPENOTEXISTEXC + conditionIdentifier);
80:                                 }
81:
82:                                 final TypeExtensionWithCondition extension =
83:                                                 new TypeExtensionWithCondition(this.types.get(this.tempExt.getName()),
84:                                                                 typeFileManager, expression, globalTypes.get(conditionIdentifier),
85:                                                                 ((TempTypeExtensionWithCondition) this.tempExt).getValue());
86:                                 extension.setMeldung(this.types.get(this.tempExt.getName()).getErrorMessage()
87:                                                 + this.tempExt.getMeldung());
88:                                 return extension;
89:                         } else {
90:                                 final TypeExtension extension =
91:                                                 new TypeExtensionWithoutCondition(this.types.get(this.tempExt.getName()));
92:                                 final StringBuffer message = new StringBuffer();
93:                                 message.append(this.types.get(this.tempExt.getName()).getErrorMessage());
94:                                 message.append(this.tempExt.getMeldung());
95:                                 extension.setMeldung(message.toString());
96:                                 extension.setMeldung(this.types.get(this.tempExt.getName()).getErrorMessage()
97:                                                 .concat(this.tempExt.getMeldung()));
98:                                 final Iterator<RegExPart> i = this.tempExt.getRegEx().getParts().iterator();
99:•                                while (i.hasNext()) {
100:                                         extension.getExpression().getParts().add(i.next());
101:                                 }
102:                                 return extension;
103:                         }
104:                 } else {
105:                         throw new TypeDoesNotExistException("Typeerweiterung fehlgeschlagen.");
106:                 }
107:         }
108:
109:         /**
110:          * @return the types
111:          */
112:         protected Map<String, NamedVariableType> getTypes() {
113:                 return this.types;
114:         }
115:
116: }