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   * Lambda Block.
27   */
28  public class ThemisAnalysisLambda
29          implements ThemisAnalysisContainer, ThemisAnalysisAdoptable {
30      /**
31       * The lambda sequence.
32       */
33      static final String LAMBDA = "-> " + ThemisAnalysisChar.BRACE_OPEN;
34  
35      /**
36       * The Parent.
37       */
38      private ThemisAnalysisContainer theParent;
39  
40      /**
41       * The contents.
42       */
43      private final Deque<ThemisAnalysisElement> theContents;
44  
45      /**
46       * The dataMap.
47       */
48      private final ThemisAnalysisDataMap theDataMap;
49  
50      /**
51       * Constructor.
52       *
53       * @param pParser the parser
54       * @param pLine   the initial class line
55       * @throws OceanusException on error
56       */
57      ThemisAnalysisLambda(final ThemisAnalysisParser pParser,
58                           final ThemisAnalysisLine pLine) throws OceanusException {
59          /* Store parent */
60          theParent = pParser.getParent();
61          theDataMap = new ThemisAnalysisDataMap(theParent.getDataMap());
62  
63          /* Parse the body */
64          final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
65  
66          /* Create a parser */
67          theContents = new ArrayDeque<>();
68          final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
69  
70          /* Parse the lines */
71          myParser.processLines();
72      }
73  
74      @Override
75      public Deque<ThemisAnalysisElement> getContents() {
76          return theContents;
77      }
78  
79      @Override
80      public ThemisAnalysisContainer getParent() {
81          return theParent;
82      }
83  
84      @Override
85      public void setParent(final ThemisAnalysisContainer pParent) {
86          theParent = pParent;
87          theDataMap.setParent(pParent.getDataMap());
88      }
89  
90      @Override
91      public ThemisAnalysisDataMap getDataMap() {
92          return theDataMap;
93      }
94  
95      @Override
96      public int getNumLines() {
97          return 0;
98      }
99  
100     /**
101      * Check for embedded lambda.
102      *
103      * @param pLine the line to check
104      * @return true/false
105      */
106     static boolean checkLambda(final ThemisAnalysisLine pLine) {
107         /* Check for lambda */
108         return pLine.endsWithSequence(LAMBDA);
109     }
110 }