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.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 ThemisReflectRecord
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 ThemisReflectRecord(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(ThemisReflectUtils.buildModifiers(theClass));
60
61 /* Map the type parameters */
62 final NodeList<TypeParameter> myParams = ThemisReflectBaseUtils.buildTypeParams(theClass.getTypeParameters());
63 setTypeParameters(myParams);
64
65 /* Set implements lists */
66 setImplementedTypes(ThemisReflectUtils.buildImplements(theClass));
67
68 /* Set members */
69 setMembers(ThemisReflectMemberUtils.buildMembers(theClass));
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 }