View Javadoc
1   /*
2    * Themis: Java Project Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
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   * Finally construct.
27   */
28  public class ThemisAnalysisFinally
29          implements ThemisAnalysisContainer, ThemisAnalysisAdoptable {
30      /**
31       * The parent.
32       */
33      private ThemisAnalysisContainer theParent;
34  
35      /**
36       * The headers.
37       */
38      private final Deque<ThemisAnalysisElement> theHeaders;
39  
40      /**
41       * The contents.
42       */
43      private final Deque<ThemisAnalysisElement> theContents;
44  
45      /**
46       * The number of lines.
47       */
48      private final int theNumLines;
49  
50      /**
51       * The dataMap.
52       */
53      private final ThemisAnalysisDataMap theDataMap;
54  
55      /**
56       * Constructor.
57       *
58       * @param pParser the parser
59       * @param pOwner  the owning try
60       * @param pLine   the initial finally line
61       * @throws OceanusException on error
62       */
63      ThemisAnalysisFinally(final ThemisAnalysisParser pParser,
64                            final ThemisAnalysisContainer pOwner,
65                            final ThemisAnalysisLine pLine) throws OceanusException {
66          /* Record the parent */
67          theParent = pOwner;
68          theDataMap = new ThemisAnalysisDataMap(theParent.getDataMap());
69  
70          /* Create the arrays */
71          theHeaders = ThemisAnalysisBuilder.parseHeaders(pParser, pLine);
72          final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
73          theNumLines = theHeaders.size();
74  
75          /* Create a parser */
76          theContents = new ArrayDeque<>();
77          final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
78          myParser.processLines();
79      }
80  
81      @Override
82      public Deque<ThemisAnalysisElement> getContents() {
83          return theContents;
84      }
85  
86      @Override
87      public ThemisAnalysisContainer getParent() {
88          return theParent;
89      }
90  
91      @Override
92      public void setParent(final ThemisAnalysisContainer pParent) {
93          theParent = pParent;
94          theDataMap.setParent(pParent.getDataMap());
95      }
96  
97      @Override
98      public ThemisAnalysisDataMap getDataMap() {
99          return theDataMap;
100     }
101 
102     @Override
103     public int getNumLines() {
104         return theNumLines;
105     }
106 }