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.ThemisAnalysisContainer.ThemisAnalysisAdoptable;
21 import io.github.tonywasher.joceanus.themis.lethe.analysis.ThemisAnalysisFile.ThemisAnalysisObject;
22
23 import java.util.ArrayDeque;
24 import java.util.Collections;
25 import java.util.Deque;
26 import java.util.List;
27
28
29
30
31 public class ThemisAnalysisAnonClass
32 implements ThemisAnalysisObject, ThemisAnalysisAdoptable {
33
34
35
36 static final String ANON = "() " + ThemisAnalysisChar.BRACE_OPEN;
37
38
39
40
41 static final String DIAMOND = "<>";
42
43
44
45
46 private final String theFullName;
47
48
49
50
51 private final String theBaseName;
52
53
54
55
56 private final List<ThemisAnalysisReference> theAncestors;
57
58
59
60
61 private final Deque<ThemisAnalysisElement> theContents;
62
63
64
65
66 private ThemisAnalysisContainer theParent;
67
68
69
70
71 private final ThemisAnalysisDataMap theDataMap;
72
73
74
75
76
77
78
79
80 ThemisAnalysisAnonClass(final ThemisAnalysisParser pParser,
81 final ThemisAnalysisLine pLine) throws OceanusException {
82
83 pLine.stripEndSequence(ANON);
84
85
86 if (pLine.endsWithSequence(DIAMOND)) {
87 pLine.stripEndSequence(DIAMOND);
88 }
89
90
91 theBaseName = pLine.stripLastToken();
92 pLine.stripEndSequence(ThemisAnalysisKeyWord.NEW.getKeyWord());
93
94
95 theParent = pParser.getParent();
96 final ThemisAnalysisDataMap myParentDataMap = theParent.getDataMap();
97
98
99 final int myId = myParentDataMap.getLocalId("");
100 theFullName = theParent.determineFullChildName(Integer.toString(myId));
101
102
103 theDataMap = new ThemisAnalysisDataMap(myParentDataMap);
104
105
106 final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
107
108
109 theContents = new ArrayDeque<>();
110 final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
111
112
113 final ThemisAnalysisLine myBaseLine = new ThemisAnalysisLine(theBaseName.toCharArray(), 0, theBaseName.length());
114 final ThemisAnalysisReference myAncestor = ThemisAnalysisParser.parseDataType(theDataMap, myBaseLine);
115 theAncestors = Collections.singletonList(myAncestor);
116 myParser.processLines();
117 }
118
119 @Override
120 public String getShortName() {
121 return toString();
122 }
123
124 @Override
125 public String getFullName() {
126 return theFullName;
127 }
128
129 @Override
130 public ThemisAnalysisProperties getProperties() {
131 return null;
132 }
133
134 @Override
135 public Deque<ThemisAnalysisElement> getContents() {
136 return theContents;
137 }
138
139 @Override
140 public ThemisAnalysisContainer getParent() {
141 return this;
142 }
143
144 @Override
145 public void setParent(final ThemisAnalysisContainer pParent) {
146 theParent = pParent;
147 theDataMap.setParent(pParent.getDataMap());
148 }
149
150 @Override
151 public ThemisAnalysisDataMap getDataMap() {
152 return theDataMap;
153 }
154
155 @Override
156 public List<ThemisAnalysisReference> getAncestors() {
157 return theAncestors;
158 }
159
160 @Override
161 public int getNumLines() {
162 return 0;
163 }
164
165 @Override
166 public String toString() {
167 return ThemisAnalysisKeyWord.NEW.toString() + " " + theBaseName + "()";
168 }
169
170
171
172
173
174
175
176 static boolean checkAnon(final ThemisAnalysisLine pLine) {
177
178 if (!pLine.endsWithSequence(ANON)) {
179 return false;
180 }
181
182
183 final ThemisAnalysisLine myLine = new ThemisAnalysisLine(pLine);
184 myLine.stripEndSequence(ANON);
185
186
187 if (myLine.endsWithSequence(DIAMOND)) {
188 myLine.stripEndSequence(DIAMOND);
189 }
190
191
192 myLine.stripLastToken();
193 final String myKey = myLine.peekLastToken();
194 return ThemisAnalysisKeyWord.NEW.getKeyWord().equals(myKey);
195 }
196 }