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.xanalysis.solver.reflect;
18  
19  import com.github.javaparser.ast.NodeList;
20  import com.github.javaparser.ast.body.RecordDeclaration;
21  import com.github.javaparser.ast.expr.SimpleName;
22  import com.github.javaparser.ast.type.TypeParameter;
23  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
24  
25  import java.util.Optional;
26  
27  /**
28   * Resolved record JavaParser representation.
29   */
30  public class ThemisXAnalysisReflectRecord
31          extends RecordDeclaration {
32      /**
33       * The underlying class.
34       */
35      private final Class<?> theClass;
36  
37      /**
38       * The fully qualified name.
39       */
40      private final String theFullName;
41  
42      /**
43       * Constructor.
44       *
45       * @param pClazz the class definition.
46       * @throws OceanusException on error
47       */
48      ThemisXAnalysisReflectRecord(final Class<?> pClazz) throws OceanusException {
49          /* Store the class */
50          theClass = pClazz;
51  
52          /* Store the fully qualified name */
53          theFullName = theClass.getCanonicalName();
54  
55          /* Set the name */
56          setName(new SimpleName(theClass.getSimpleName()));
57  
58          /* Set the modifiers */
59          setModifiers(ThemisXAnalysisReflectUtils.buildModifiers(theClass));
60  
61          /* Set implements lists */
62          setImplementedTypes(ThemisXAnalysisReflectUtils.buildImplements(theClass));
63  
64          /* Set members */
65          setMembers(ThemisXAnalysisReflectMemberUtils.buildMembers(theClass));
66  
67          /* Map the type parameters */
68          final NodeList<TypeParameter> myParams = ThemisXAnalysisReflectBaseUtils.buildTypeParams(theClass.getTypeParameters());
69          setTypeParameters(myParams);
70      }
71  
72      @Override
73      public Optional<String> getFullyQualifiedName() {
74          return Optional.of(theFullName);
75      }
76  
77      @Override
78      public boolean isTopLevelType() {
79          return !theClass.isMemberClass();
80      }
81  }