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.ThemisAnalysisIf.ThemisIteratorChain;
21 import io.github.tonywasher.joceanus.themis.lethe.analysis.ThemisAnalysisStatement.ThemisAnalysisStatementHolder;
22
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.ListIterator;
27
28
29
30
31 public class ThemisAnalysisField
32 implements ThemisAnalysisProcessed, ThemisAnalysisStatementHolder {
33
34
35
36 private final String theName;
37
38
39
40
41 private final ThemisAnalysisReference theDataType;
42
43
44
45
46 private final ThemisAnalysisProperties theProperties;
47
48
49
50
51 private final ThemisAnalysisStatement theInitial;
52
53
54
55
56 private final int theNumLines;
57
58
59
60
61
62
63
64
65
66
67 ThemisAnalysisField(final ThemisAnalysisParser pParser,
68 final String pName,
69 final ThemisAnalysisReference pDataType,
70 final ThemisAnalysisLine pLine) throws OceanusException {
71
72 theName = pName;
73 theDataType = pDataType;
74 theProperties = pLine.getProperties();
75
76
77 if (pLine.startsWithChar(ThemisAnalysisChar.SEMICOLON)) {
78
79 theNumLines = 1;
80 theInitial = null;
81
82
83 } else {
84
85 pLine.stripStartChar(ThemisAnalysisChar.EQUAL);
86
87
88 theInitial = new ThemisAnalysisStatement(pParser, pLine);
89 theNumLines = theInitial.getNumLines();
90 }
91 }
92
93
94
95
96
97
98
99
100
101
102 ThemisAnalysisField(final ThemisAnalysisParser pParser,
103 final String pName,
104 final ThemisAnalysisReference pDataType,
105 final ThemisAnalysisEmbedded pEmbedded) throws OceanusException {
106
107 theName = pName;
108 theDataType = pDataType;
109
110
111 final ThemisAnalysisLine myLine = pEmbedded.getHeader();
112 theProperties = myLine.getProperties();
113
114
115 myLine.stripStartChar(ThemisAnalysisChar.EQUAL);
116
117
118 theInitial = new ThemisAnalysisStatement(pEmbedded);
119 theNumLines = theInitial.getNumLines();
120 }
121
122
123
124
125
126
127
128
129 ThemisAnalysisField(final ThemisAnalysisDataMap pDataMap,
130 final ThemisAnalysisStack pStack) throws OceanusException {
131
132 final ThemisAnalysisLine myLine = (ThemisAnalysisLine) pStack.popNextLine();
133 ThemisAnalysisProperties myProps = ThemisAnalysisProperties.NULL;
134
135
136 final String nextToken = myLine.peekNextToken();
137
138
139 if (ThemisAnalysisModifier.FINAL.getModifier().equals(nextToken)) {
140
141 myProps = myProps.setModifier(ThemisAnalysisModifier.FINAL);
142 myLine.stripStartSequence(nextToken);
143 }
144
145
146 theDataType = ThemisAnalysisParser.parseDataType(pDataMap, myLine);
147 theName = myLine.stripNextToken();
148 myLine.stripStartChar(ThemisAnalysisChar.EQUAL);
149 pStack.pushLine(myLine);
150 theProperties = myProps;
151
152
153 theInitial = new ThemisAnalysisStatement(null, pStack);
154 theNumLines = theInitial.getNumLines();
155 }
156
157
158
159
160
161
162
163
164 ThemisAnalysisField(final ThemisAnalysisField pPrevious,
165 final ThemisAnalysisStack pStack) throws OceanusException {
166
167 final ThemisAnalysisLine myLine = (ThemisAnalysisLine) pStack.popNextLine();
168 theDataType = pPrevious.theDataType;
169 theName = myLine.stripNextToken();
170 myLine.stripStartChar(ThemisAnalysisChar.EQUAL);
171 pStack.pushLine(myLine);
172 theProperties = ThemisAnalysisProperties.NULL;
173
174
175 theInitial = new ThemisAnalysisStatement(null, pStack);
176 theNumLines = theInitial.getNumLines();
177 }
178
179
180
181
182
183
184 public String getName() {
185 return theName;
186 }
187
188 @Override
189 public Iterator<ThemisAnalysisStatement> statementIterator() {
190 return theInitial == null
191 ? Collections.emptyIterator()
192 : Collections.singleton(theInitial).iterator();
193 }
194
195 @Override
196 public int getNumLines() {
197 return theNumLines;
198 }
199
200 @Override
201 public String toString() {
202 return theDataType.toString() + " " + getName();
203 }
204
205
206
207
208
209
210
211 public static Iterator<ThemisAnalysisStatement> statementIteratorForFields(final List<ThemisAnalysisField> pList) {
212 final ListIterator<ThemisAnalysisField> myIterator = pList.listIterator(pList.size());
213 Iterator<ThemisAnalysisStatement> myCurr = Collections.emptyIterator();
214 while (myIterator.hasPrevious()) {
215 final ThemisAnalysisField myField = myIterator.previous();
216 myCurr = new ThemisIteratorChain<>(myField.statementIterator(), myCurr);
217 }
218 return myCurr;
219 }
220 }