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.solver.reflect;
18  
19  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
20  import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
21  import io.github.tonywasher.joceanus.themis.parser.base.ThemisDataResource;
22  import io.github.tonywasher.joceanus.themis.parser.base.ThemisInstance.ThemisClassInstance;
23  import io.github.tonywasher.joceanus.themis.parser.base.ThemisModifierList;
24  import io.github.tonywasher.joceanus.themis.parser.node.ThemisNodeImport;
25  import io.github.tonywasher.joceanus.themis.parser.node.ThemisNodeModifierList;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * External Class representation.
32   */
33  public class ThemisReflectExternal
34          implements ThemisClassInstance {
35      /**
36       * Report fields.
37       */
38      private static final MetisFieldSet<ThemisReflectExternal> FIELD_DEFS = MetisFieldSet.newFieldSet(ThemisReflectExternal.class);
39  
40      /*
41       * Declare Fields.
42       */
43      static {
44          FIELD_DEFS.declareLocalField(ThemisDataResource.DATA_NAME, ThemisReflectExternal::getName);
45      }
46  
47      /**
48       * The javaLang prefix.
49       */
50      static final String JAVALANG = "java.lang.";
51  
52      /**
53       * The name of the class.
54       */
55      private final String theName;
56  
57      /**
58       * The full name of the class.
59       */
60      private final String theFullName;
61  
62      /**
63       * The modifierList.
64       */
65      private final ThemisModifierList theModifiers;
66  
67      /**
68       * The ancestors.
69       */
70      private final List<String> theAncestors;
71  
72      /**
73       * The class instance.
74       */
75      private ThemisClassInstance theClassInstance;
76  
77      /**
78       * Constructor.
79       *
80       * @param pImport the import definition
81       */
82      public ThemisReflectExternal(final ThemisNodeImport pImport) {
83          theName = pImport.getShortName();
84          theFullName = pImport.getFullName();
85          theModifiers = new ThemisNodeModifierList(new ArrayList<>());
86          theAncestors = new ArrayList<>();
87      }
88  
89      /**
90       * Constructor.
91       *
92       * @param pClazz the loaded class instance
93       */
94      ThemisReflectExternal(final ThemisClassInstance pClazz) {
95          theName = pClazz.getName();
96          theFullName = pClazz.getFullName();
97          theModifiers = pClazz.getModifiers();
98          theAncestors = new ArrayList<>();
99          theClassInstance = pClazz;
100     }
101 
102     @Override
103     public MetisFieldSet<ThemisReflectExternal> getDataFieldSet() {
104         return FIELD_DEFS;
105     }
106 
107     @Override
108     public String formatObject(final OceanusDataFormatter pFormatter) {
109         return getName();
110     }
111 
112     @Override
113     public String getName() {
114         return theName;
115     }
116 
117     @Override
118     public String getFullName() {
119         return theFullName;
120     }
121 
122     @Override
123     public ThemisModifierList getModifiers() {
124         return theModifiers;
125     }
126 
127     @Override
128     public boolean isTopLevel() {
129         return true;
130     }
131 
132     /**
133      * Obtain the class instance.
134      *
135      * @return the class instance
136      */
137     public ThemisClassInstance getClassInstance() {
138         return theClassInstance;
139     }
140 
141     /**
142      * Set the class instance.
143      *
144      * @param pClassInstance the class instance
145      */
146     public void setClassInstance(final ThemisClassInstance pClassInstance) {
147         theClassInstance = pClassInstance;
148     }
149 
150     /**
151      * Obtain the list of ancestors.
152      *
153      * @return the list
154      */
155     public List<String> getAncestors() {
156         return theAncestors;
157     }
158 
159     /**
160      * Add ancestor.
161      *
162      * @param pAncestor the ancestor
163      */
164     public void addAncestor(final ThemisReflectExternal pAncestor) {
165         theAncestors.add(pAncestor.getFullName());
166     }
167 }