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