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.parser.decl;
18  
19  import com.github.javaparser.ast.body.EnumDeclaration;
20  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
21  import io.github.tonywasher.joceanus.themis.parser.base.ThemisInstance.ThemisClassInstance;
22  import io.github.tonywasher.joceanus.themis.parser.base.ThemisInstance.ThemisDeclarationInstance;
23  import io.github.tonywasher.joceanus.themis.parser.base.ThemisModifierList;
24  import io.github.tonywasher.joceanus.themis.parser.base.ThemisParserDef;
25  import io.github.tonywasher.joceanus.themis.parser.node.ThemisNodeSimpleName;
26  
27  import java.util.List;
28  
29  /**
30   * Enum Declaration.
31   */
32  public class ThemisDeclEnum
33          extends ThemisBaseDeclaration<EnumDeclaration>
34          implements ThemisDeclarationInstance, ThemisClassInstance {
35      /**
36       * The Name.
37       */
38      private final String theName;
39  
40      /**
41       * The fullName.
42       */
43      private final String theFullName;
44  
45      /**
46       * The modifiers.
47       */
48      private final ThemisModifierList theModifiers;
49  
50      /**
51       * The enumConstants.
52       */
53      private final List<ThemisDeclarationInstance> theValues;
54  
55      /**
56       * The body.
57       */
58      private final List<ThemisDeclarationInstance> theBody;
59  
60      /**
61       * The implements.
62       */
63      private final List<ThemisTypeInstance> theImplements;
64  
65      /**
66       * The annotations.
67       */
68      private final List<ThemisExpressionInstance> theAnnotations;
69  
70      /**
71       * Constructor.
72       *
73       * @param pParser      the parser
74       * @param pDeclaration the declaration
75       * @throws OceanusException on error
76       */
77      ThemisDeclEnum(final ThemisParserDef pParser,
78                     final EnumDeclaration pDeclaration) throws OceanusException {
79          /* Store values */
80          super(pParser, pDeclaration);
81          theName = ((ThemisNodeSimpleName) pParser.parseNode(pDeclaration.getName())).getName();
82          theFullName = pDeclaration.getFullyQualifiedName().orElse(null);
83          theModifiers = pParser.parseModifierList(pDeclaration.getModifiers());
84          theAnnotations = pParser.parseExprList(pDeclaration.getAnnotations());
85          theImplements = pParser.parseTypeList(pDeclaration.getImplementedTypes());
86          theValues = pParser.parseDeclarationList(pDeclaration.getEntries());
87  
88          /* Register the class */
89          pParser.registerClass(this);
90  
91          /* Finally parse the underlying declarations */
92          theBody = pParser.parseDeclarationList(pDeclaration.getMembers());
93      }
94  
95      @Override
96      public String getName() {
97          return theName;
98      }
99  
100     @Override
101     public String getFullName() {
102         return theFullName;
103     }
104 
105     @Override
106     public boolean isTopLevel() {
107         return getNode().isTopLevelType();
108     }
109 
110     @Override
111     public ThemisModifierList getModifiers() {
112         return theModifiers;
113     }
114 
115     /**
116      * Obtain the values.
117      *
118      * @return the values
119      */
120     public List<ThemisDeclarationInstance> getValues() {
121         return theValues;
122     }
123 
124     @Override
125     public List<ThemisDeclarationInstance> getBody() {
126         return theBody;
127     }
128 
129     @Override
130     public List<ThemisTypeInstance> getImplements() {
131         return theImplements;
132     }
133 
134     @Override
135     public List<ThemisExpressionInstance> getAnnotations() {
136         return theAnnotations;
137     }
138 }