1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.themis.lethe.analysis;
18
19 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20 import io.github.tonywasher.joceanus.themis.lethe.analysis.ThemisAnalysisFile.ThemisAnalysisObject;
21 import io.github.tonywasher.joceanus.themis.lethe.analysis.ThemisAnalysisGeneric.ThemisAnalysisGenericBase;
22
23 import java.util.ArrayDeque;
24 import java.util.ArrayList;
25 import java.util.Deque;
26 import java.util.List;
27
28
29
30
31 public class ThemisAnalysisEnum
32 implements ThemisAnalysisObject {
33
34
35
36 private final String theShortName;
37
38
39
40
41 private final String theFullName;
42
43
44
45
46 private final List<ThemisAnalysisReference> theAncestors;
47
48
49
50
51 private final Deque<ThemisAnalysisElement> theContents;
52
53
54
55
56 private final ThemisAnalysisDataMap theDataMap;
57
58
59
60
61 private final List<String> theValues;
62
63
64
65
66 private int theNumLines;
67
68
69
70
71 private ThemisAnalysisProperties theProperties;
72
73
74
75
76
77
78
79
80 ThemisAnalysisEnum(final ThemisAnalysisParser pParser,
81 final ThemisAnalysisLine pLine) throws OceanusException {
82
83 theShortName = pLine.stripNextToken();
84 theProperties = pLine.getProperties();
85 theValues = new ArrayList<>();
86 final ThemisAnalysisContainer myParent = pParser.getParent();
87 final ThemisAnalysisDataMap myParentDataMap = myParent.getDataMap();
88 theDataMap = new ThemisAnalysisDataMap(myParentDataMap);
89
90
91 if (!(myParent instanceof ThemisAnalysisObject)
92 && (!(myParent instanceof ThemisAnalysisFile))) {
93 final int myId = myParentDataMap.getLocalId(theShortName);
94 theFullName = myParent.determineFullChildName(myId + theShortName);
95
96
97 } else {
98 theFullName = myParent.determineFullChildName(theShortName);
99 }
100
101
102 ThemisAnalysisLine myLine = pLine;
103 if (ThemisAnalysisGeneric.isGeneric(pLine)) {
104
105 theProperties = theProperties.setGenericVariables(new ThemisAnalysisGenericBase(pParser, myLine));
106 myLine = (ThemisAnalysisLine) pParser.popNextLine();
107 }
108
109
110 theDataMap.declareObject(this);
111
112
113 final Deque<ThemisAnalysisElement> myHeaders = ThemisAnalysisBuilder.parseHeaders(pParser, myLine);
114 theNumLines = myHeaders.size() + 1;
115
116
117 final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
118
119
120 theContents = new ArrayDeque<>();
121 final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
122
123
124 theProperties.resolveGeneric(myParser);
125
126
127 theAncestors = myParser.parseAncestors(myHeaders);
128 initialProcessingPass(myParser);
129 }
130
131
132
133
134
135
136
137 void initialProcessingPass(final ThemisAnalysisParser pParser) throws OceanusException {
138
139 boolean look4Enum = true;
140
141
142 while (pParser.hasLines()) {
143
144 final ThemisAnalysisLine myLine = (ThemisAnalysisLine) pParser.popNextLine();
145
146
147 boolean processed = pParser.processCommentsAndBlanks(myLine);
148
149
150 if (!processed && look4Enum) {
151 look4Enum = processEnumValue(pParser, myLine);
152 processed = true;
153 }
154
155
156 if (!processed) {
157 processed = pParser.processClass(myLine)
158 || pParser.processLanguage(myLine)
159 || pParser.processBlocks(myLine);
160 }
161
162
163 if (!processed) {
164
165 theContents.add(myLine);
166 }
167 }
168 }
169
170
171
172
173
174
175
176
177
178 private boolean processEnumValue(final ThemisAnalysisParser pParser,
179 final ThemisAnalysisLine pLine) throws OceanusException {
180
181 ThemisAnalysisLine myLine = pLine;
182 final String myToken = myLine.stripNextToken();
183 theNumLines++;
184 if (myLine.startsWithChar(ThemisAnalysisChar.PARENTHESIS_OPEN)) {
185 final ThemisAnalysisScanner myScanner = new ThemisAnalysisScanner(pParser);
186 final Deque<ThemisAnalysisElement> myDef = myScanner.scanForParenthesis(myLine);
187 myLine = (ThemisAnalysisLine) pParser.popNextLine();
188 theNumLines += myDef.size() - 1;
189 }
190 theValues.add(myToken);
191 return myLine.endsWithChar(ThemisAnalysisChar.COMMA);
192 }
193
194 @Override
195 public String getShortName() {
196 return theShortName;
197 }
198
199 @Override
200 public String getFullName() {
201 return theFullName;
202 }
203
204 @Override
205 public ThemisAnalysisDataMap getDataMap() {
206 return theDataMap;
207 }
208
209 @Override
210 public ThemisAnalysisProperties getProperties() {
211 return theProperties;
212 }
213
214 @Override
215 public Deque<ThemisAnalysisElement> getContents() {
216 return theContents;
217 }
218
219 @Override
220 public ThemisAnalysisContainer getParent() {
221 return this;
222 }
223
224 @Override
225 public List<ThemisAnalysisReference> getAncestors() {
226 return theAncestors;
227 }
228
229 @Override
230 public int getNumLines() {
231 return theNumLines;
232 }
233
234
235
236
237
238
239 public int getNumEnums() {
240 return theValues.size();
241 }
242
243 @Override
244 public String toString() {
245 return getShortName();
246 }
247 }