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.ThemisAnalysisStatement.ThemisAnalysisStatementHolder;
22
23 import java.util.ArrayDeque;
24 import java.util.Collections;
25 import java.util.Deque;
26 import java.util.Iterator;
27
28
29
30
31 public class ThemisAnalysisDoWhile
32 implements ThemisAnalysisContainer, ThemisAnalysisAdoptable, ThemisAnalysisStatementHolder {
33
34
35
36 private final ThemisAnalysisStatement theCondition;
37
38
39
40
41 private final Deque<ThemisAnalysisElement> theContents;
42
43
44
45
46 private final int theNumLines;
47
48
49
50
51 private final ThemisAnalysisDataMap theDataMap;
52
53
54
55
56 private ThemisAnalysisContainer theParent;
57
58
59
60
61
62
63
64 ThemisAnalysisDoWhile(final ThemisAnalysisParser pParser) throws OceanusException {
65
66 theParent = pParser.getParent();
67 theDataMap = new ThemisAnalysisDataMap(theParent.getDataMap());
68
69
70 final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
71
72
73 final ThemisAnalysisLine myLine = (ThemisAnalysisLine) pParser.popNextLine();
74 myLine.stripStartSequence(ThemisAnalysisKeyWord.WHILE.toString());
75 theCondition = new ThemisAnalysisStatement(pParser, myLine);
76 theNumLines = theCondition.getNumLines() + 1;
77
78
79 theContents = new ArrayDeque<>();
80 final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
81 myParser.processLines();
82 }
83
84 @Override
85 public Deque<ThemisAnalysisElement> getContents() {
86 return theContents;
87 }
88
89 @Override
90 public Iterator<ThemisAnalysisStatement> statementIterator() {
91 return Collections.singleton(theCondition).iterator();
92 }
93
94 @Override
95 public ThemisAnalysisContainer getParent() {
96 return theParent;
97 }
98
99 @Override
100 public void setParent(final ThemisAnalysisContainer pParent) {
101 theParent = pParent;
102 theDataMap.setParent(pParent.getDataMap());
103 }
104
105 @Override
106 public ThemisAnalysisDataMap getDataMap() {
107 return theDataMap;
108 }
109
110 @Override
111 public int getNumLines() {
112 return theNumLines;
113 }
114
115 @Override
116 public String toString() {
117 return theCondition.toString();
118 }
119 }