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   * Temporary Method Body.
27   */
28  public class ThemisAnalysisMethodBody
29          implements ThemisAnalysisContainer, ThemisAnalysisAdoptable {
30      /**
31       * The ArrayInit sequence.
32       */
33      static final String ARRAYINIT = "= " + ThemisAnalysisChar.BRACE_OPEN;
34  
35      /**
36       * The Parent.
37       */
38      private ThemisAnalysisContainer theParent;
39  
40      /**
41       * The Header.
42       */
43      private final ThemisAnalysisLine theHeader;
44  
45      /**
46       * The contents.
47       */
48      private final Deque<ThemisAnalysisElement> theContents;
49  
50      /**
51       * Constructor.
52       *
53       * @param pParser the parser
54       * @param pLine   the initial class line
55       * @throws OceanusException on error
56       */
57      ThemisAnalysisMethodBody(final ThemisAnalysisParser pParser,
58                               final ThemisAnalysisLine pLine) throws OceanusException {
59          /* Store parameters */
60          theHeader = pLine;
61  
62          /* Store parent */
63          theParent = pParser.getParent();
64  
65          /* Parse the body */
66          final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
67  
68          /* Create a parser */
69          theContents = new ArrayDeque<>();
70          final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
71  
72          /* Parse the lines */
73          myParser.processLines();
74      }
75  
76      /**
77       * Obtain the header.
78       *
79       * @return the header
80       */
81      ThemisAnalysisLine getHeader() {
82          return theHeader;
83      }
84  
85      @Override
86      public Deque<ThemisAnalysisElement> getContents() {
87          return theContents;
88      }
89  
90      @Override
91      public ThemisAnalysisContainer getParent() {
92          return theParent;
93      }
94  
95      @Override
96      public void setParent(final ThemisAnalysisContainer pParent) {
97          theParent = pParent;
98      }
99  
100     @Override
101     public void postProcessLines() {
102         /* Disable the processing of the lines */
103     }
104 
105     @Override
106     public int getNumLines() {
107         return theContents.size();
108     }
109 
110     /**
111      * Check for embedded methodBody.
112      *
113      * @param pLine the line to check
114      * @return true/false
115      */
116     static boolean checkMethodBody(final ThemisAnalysisLine pLine) {
117         /* Check for braceOpen */
118         return pLine.endsWithChar(ThemisAnalysisChar.BRACE_OPEN);
119     }
120 }