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.Collections;
24 import java.util.Deque;
25 import java.util.Iterator;
26
27
28
29
30 public class ThemisAnalysisCatch
31 implements ThemisAnalysisContainer, ThemisAnalysisAdoptable {
32
33
34
35 private ThemisAnalysisContainer theParent;
36
37
38
39
40 private final Deque<ThemisAnalysisElement> theHeaders;
41
42
43
44
45 private final Deque<ThemisAnalysisElement> theContents;
46
47
48
49
50 private final ThemisAnalysisCatch theCatch;
51
52
53
54
55 private final int theNumLines;
56
57
58
59
60 private final ThemisAnalysisDataMap theDataMap;
61
62
63
64
65
66
67
68
69
70 ThemisAnalysisCatch(final ThemisAnalysisParser pParser,
71 final ThemisAnalysisContainer pOwner,
72 final ThemisAnalysisLine pLine) throws OceanusException {
73
74 theParent = pOwner;
75 theDataMap = new ThemisAnalysisDataMap(theParent.getDataMap());
76
77
78 theHeaders = ThemisAnalysisBuilder.parseHeaders(pParser, pLine);
79 final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
80 theNumLines = theHeaders.size();
81
82
83 theCatch = (ThemisAnalysisCatch) pParser.processExtra(pOwner, ThemisAnalysisKeyWord.CATCH);
84
85
86 theContents = new ArrayDeque<>();
87 final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
88 myParser.processLines();
89 }
90
91 @Override
92 public Deque<ThemisAnalysisElement> getContents() {
93 return theContents;
94 }
95
96 @Override
97 public ThemisAnalysisContainer getParent() {
98 return theParent;
99 }
100
101 @Override
102 public void setParent(final ThemisAnalysisContainer pParent) {
103 theParent = pParent;
104 theDataMap.setParent(pParent.getDataMap());
105 if (theCatch != null) {
106 theCatch.setParent(pParent);
107 }
108 }
109
110 @Override
111 public ThemisAnalysisDataMap getDataMap() {
112 return theDataMap;
113 }
114
115 @Override
116 public void postProcessExtras() throws OceanusException {
117
118 if (theCatch != null) {
119 theCatch.postProcessLines();
120 }
121 }
122
123
124
125
126
127
128 public ThemisAnalysisCatch getCatch() {
129 return theCatch;
130 }
131
132 @Override
133 public Iterator<ThemisAnalysisContainer> containerIterator() {
134 return theCatch == null
135 ? Collections.emptyIterator()
136 : Collections.singleton((ThemisAnalysisContainer) theCatch).iterator();
137 }
138
139 @Override
140 public int getNumLines() {
141 return theNumLines;
142 }
143
144 @Override
145 public String toString() {
146 return ThemisAnalysisBuilder.formatLines(theHeaders);
147 }
148 }