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.ThemisAnalysisFile.ThemisAnalysisObject;
21  import io.github.tonywasher.joceanus.themis.lethe.analysis.ThemisAnalysisGeneric.ThemisAnalysisGenericBase;
22  
23  import java.util.ArrayDeque;
24  import java.util.Deque;
25  import java.util.List;
26  
27  /**
28   * Interface representation.
29   */
30  public class ThemisAnalysisInterface
31          implements ThemisAnalysisObject {
32      /**
33       * The short name of the class.
34       */
35      private final String theShortName;
36  
37      /**
38       * The full name of the class.
39       */
40      private final String theFullName;
41  
42      /**
43       * Is this an annotation definition.
44       */
45      private final boolean isAnnotation;
46  
47      /**
48       * The ancestors.
49       */
50      private final List<ThemisAnalysisReference> theAncestors;
51  
52      /**
53       * The contents.
54       */
55      private final Deque<ThemisAnalysisElement> theContents;
56  
57      /**
58       * The dataMap.
59       */
60      private final ThemisAnalysisDataMap theDataMap;
61  
62      /**
63       * The number of lines.
64       */
65      private final int theNumLines;
66  
67      /**
68       * The properties.
69       */
70      private ThemisAnalysisProperties theProperties;
71  
72      /**
73       * Constructor.
74       *
75       * @param pParser     the parser
76       * @param pAnnotation is this an annoitation definition?
77       * @param pLine       the initial interface line
78       * @throws OceanusException on error
79       */
80      ThemisAnalysisInterface(final ThemisAnalysisParser pParser,
81                              final boolean pAnnotation,
82                              final ThemisAnalysisLine pLine) throws OceanusException {
83          /* Store parameters */
84          theShortName = pLine.stripNextToken();
85          theProperties = pLine.getProperties();
86          isAnnotation = pAnnotation;
87          final ThemisAnalysisContainer myParent = pParser.getParent();
88          final ThemisAnalysisDataMap myParentDataMap = myParent.getDataMap();
89          theDataMap = new ThemisAnalysisDataMap(myParentDataMap);
90  
91          /* If this is a local interface */
92          if (!(myParent instanceof ThemisAnalysisObject)
93                  && (!(myParent instanceof ThemisAnalysisFile))) {
94              final int myId = myParentDataMap.getLocalId(theShortName);
95              theFullName = myParent.determineFullChildName(myId + theShortName);
96  
97              /* else handle standard name */
98          } else {
99              theFullName = myParent.determineFullChildName(theShortName);
100         }
101 
102         /* Handle generic variables */
103         ThemisAnalysisLine myLine = pLine;
104         if (ThemisAnalysisGeneric.isGeneric(pLine)) {
105             /* Declare them to the properties */
106             theProperties = theProperties.setGenericVariables(new ThemisAnalysisGenericBase(pParser, myLine));
107             myLine = (ThemisAnalysisLine) pParser.popNextLine();
108         }
109 
110         /* declare the interface */
111         theDataMap.declareObject(this);
112 
113         /* Parse the headers */
114         final Deque<ThemisAnalysisElement> myHeaders = ThemisAnalysisBuilder.parseHeaders(pParser, myLine);
115         theNumLines = myHeaders.size() + 1;
116 
117         /* Parse the body */
118         final Deque<ThemisAnalysisElement> myLines = ThemisAnalysisBuilder.processBody(pParser);
119 
120         /* Create a parser */
121         theContents = new ArrayDeque<>();
122         final ThemisAnalysisParser myParser = new ThemisAnalysisParser(myLines, theContents, this);
123 
124         /* Resolve the generics */
125         theProperties.resolveGeneric(myParser);
126 
127         /* Parse the ancestors and lines */
128         theAncestors = myParser.parseAncestors(myHeaders);
129         myParser.processLines();
130     }
131 
132     /**
133      * Is this an annotation?
134      *
135      * @return true/false
136      */
137     public boolean isAnnotation() {
138         return isAnnotation;
139     }
140 
141     @Override
142     public String getShortName() {
143         return theShortName;
144     }
145 
146     @Override
147     public String getFullName() {
148         return theFullName;
149     }
150 
151     @Override
152     public ThemisAnalysisDataMap getDataMap() {
153         return theDataMap;
154     }
155 
156     @Override
157     public ThemisAnalysisProperties getProperties() {
158         return theProperties;
159     }
160 
161     @Override
162     public Deque<ThemisAnalysisElement> getContents() {
163         return theContents;
164     }
165 
166     @Override
167     public ThemisAnalysisContainer getParent() {
168         return this;
169     }
170 
171     @Override
172     public List<ThemisAnalysisReference> getAncestors() {
173         return theAncestors;
174     }
175 
176     @Override
177     public int getNumLines() {
178         return theNumLines;
179     }
180 
181     @Override
182     public String toString() {
183         return getShortName();
184     }
185 }