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