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
22 import java.util.ArrayDeque;
23 import java.util.Deque;
24
25
26
27
28 public class ThemisAnalysisBlock
29 implements ThemisAnalysisContainer, ThemisAnalysisAdoptable {
30
31
32
33 private final ThemisAnalysisLine theHeader;
34
35
36
37
38 private final ThemisAnalysisProperties theProperties;
39
40
41
42
43 private final Deque<ThemisAnalysisElement> theContents;
44
45
46
47
48 private final int theNumLines;
49
50
51
52
53 private ThemisAnalysisContainer theParent;
54
55
56
57
58 private final ThemisAnalysisDataMap theDataMap;
59
60
61
62
63
64
65
66
67 ThemisAnalysisBlock(final ThemisAnalysisParser pParser,
68 final ThemisAnalysisLine pLine) throws OceanusException {
69
70 theHeader = pLine;
71 theNumLines = 2;
72
73
74 theProperties = pLine.getProperties();
75 theParent = pParser.getParent();
76 theDataMap = new ThemisAnalysisDataMap(theParent.getDataMap());
77
78
79 final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
80
81
82 theContents = new ArrayDeque<>();
83 final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
84 myParser.processLines();
85 }
86
87 @Override
88 public Deque<ThemisAnalysisElement> getContents() {
89 return theContents;
90 }
91
92 @Override
93 public ThemisAnalysisContainer getParent() {
94 return theParent;
95 }
96
97 @Override
98 public void setParent(final ThemisAnalysisContainer pParent) {
99 theParent = pParent;
100 theDataMap.setParent(pParent.getDataMap());
101 }
102
103 @Override
104 public ThemisAnalysisDataMap getDataMap() {
105 return theDataMap;
106 }
107
108 @Override
109 public int getNumLines() {
110 return theNumLines;
111 }
112
113
114
115
116
117
118 public boolean isSynchronized() {
119 return theProperties.hasModifier(ThemisAnalysisModifier.SYNCHRONIZED);
120 }
121
122 @Override
123 public String toString() {
124
125 final StringBuilder myBuilder = new StringBuilder();
126
127
128 if (theHeader.getProperties().hasModifier(ThemisAnalysisModifier.STATIC)) {
129 myBuilder.append(ThemisAnalysisModifier.STATIC);
130 myBuilder.append(ThemisAnalysisChar.BLANK);
131 }
132 if (theHeader.getProperties().hasModifier(ThemisAnalysisModifier.SYNCHRONIZED)) {
133 myBuilder.append(ThemisAnalysisModifier.SYNCHRONIZED);
134 myBuilder.append(ThemisAnalysisChar.BLANK);
135 }
136
137
138 myBuilder.append(theHeader);
139 return myBuilder.toString();
140 }
141
142
143
144
145
146
147
148 static boolean checkBlock(final ThemisAnalysisLine pLine) {
149
150 if (!pLine.endsWithChar(ThemisAnalysisChar.BRACE_OPEN)) {
151 return false;
152 }
153
154
155 if (pLine.getProperties().hasModifier(ThemisAnalysisModifier.SYNCHRONIZED)
156 && pLine.startsWithChar(ThemisAnalysisChar.PARENTHESIS_OPEN)) {
157 return true;
158 }
159
160
161 return pLine.getLength() == 1;
162 }
163 }