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.Deque;
23  
24  /**
25   * Array Initialisation.
26   */
27  public class ThemisAnalysisArrayInit
28          implements ThemisAnalysisContainer, ThemisAnalysisAdoptable {
29      /**
30       * The ArrayInit sequence.
31       */
32      static final String ARRAYINIT = "= " + ThemisAnalysisChar.BRACE_OPEN;
33  
34      /**
35       * The Parent.
36       */
37      private ThemisAnalysisContainer theParent;
38  
39      /**
40       * The contents.
41       */
42      private final Deque<ThemisAnalysisElement> theContents;
43  
44      /**
45       * Constructor.
46       *
47       * @param pParser the parser
48       * @param pLine   the initial class line
49       * @throws OceanusException on error
50       */
51      ThemisAnalysisArrayInit(final ThemisAnalysisParser pParser,
52                              final ThemisAnalysisLine pLine) throws OceanusException {
53          /* Store parent */
54          theParent = pParser.getParent();
55  
56          /* Parse the body */
57          theContents = ThemisAnalysisBuilder.processBody(pParser);
58      }
59  
60      @Override
61      public Deque<ThemisAnalysisElement> getContents() {
62          return theContents;
63      }
64  
65      @Override
66      public ThemisAnalysisContainer getParent() {
67          return theParent;
68      }
69  
70      @Override
71      public void setParent(final ThemisAnalysisContainer pParent) {
72          theParent = pParent;
73      }
74  
75      @Override
76      public void postProcessLines() {
77          /* Disable the processing of the lines */
78      }
79  
80      @Override
81      public int getNumLines() {
82          return theContents.size();
83      }
84  
85      /**
86       * Check for embedded arrayInit.
87       *
88       * @param pLine the line to check
89       * @return true/false
90       */
91      static boolean checkArrayInit(final ThemisAnalysisLine pLine) {
92          /* Check for arrayInit */
93          return pLine.endsWithSequence(ARRAYINIT);
94      }
95  }