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