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.proj;
18  
19  import io.github.tonywasher.joceanus.themis.xanalysis.parser.base.ThemisXAnalysisInstance;
20  import io.github.tonywasher.joceanus.themis.xanalysis.parser.base.ThemisXAnalysisInstance.ThemisXAnalysisClassInstance;
21  import io.github.tonywasher.joceanus.themis.xanalysis.parser.base.ThemisXAnalysisInstance.ThemisXAnalysisMethodInstance;
22  import io.github.tonywasher.joceanus.themis.xanalysis.solver.proj.ThemisXAnalysisSolverDef.ThemisXAnalysisSolverClassDef;
23  import io.github.tonywasher.joceanus.themis.xanalysis.solver.proj.ThemisXAnalysisSolverDef.ThemisXAnalysisSolverFileDef;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * Solver Class.
30   */
31  public class ThemisXAnalysisSolverClass
32          implements ThemisXAnalysisSolverClassDef {
33      /**
34       * The fully qualified name of the class.
35       */
36      private final String theFullName;
37  
38      /**
39       * The owning file.
40       */
41      private final ThemisXAnalysisSolverFileDef theFile;
42  
43      /**
44       * The contained class.
45       */
46      private final ThemisXAnalysisClassInstance theClass;
47  
48      /**
49       * The methods.
50       */
51      private final List<ThemisXAnalysisSolverMethod> theMethods;
52  
53      /**
54       * Is the reference list circular?
55       */
56      private boolean isCircular;
57  
58      /**
59       * Constructor.
60       *
61       * @param pFile  the owning file
62       * @param pClass the parsed class
63       */
64      ThemisXAnalysisSolverClass(final ThemisXAnalysisSolverFileDef pFile,
65                                 final ThemisXAnalysisClassInstance pClass) {
66          /* Store the parameters */
67          theFile = pFile;
68          theClass = pClass;
69  
70          /* Access the full name */
71          theFullName = theClass.getFullName();
72  
73          /* Populate the methodList */
74          theMethods = new ArrayList<>();
75          final ThemisXAnalysisInstance myNode = (ThemisXAnalysisInstance) theClass;
76          for (ThemisXAnalysisInstance myMethod : myNode.discoverChildren(ThemisXAnalysisMethodInstance.class::isInstance)) {
77              final ThemisXAnalysisSolverMethod mySolverMethod = new ThemisXAnalysisSolverMethod(this, (ThemisXAnalysisMethodInstance) myMethod);
78              theMethods.add(mySolverMethod);
79          }
80      }
81  
82      /**
83       * Obtain the name of the class.
84       *
85       * @return the name
86       */
87      public String getName() {
88          return theClass.getName();
89      }
90  
91      @Override
92      public String getFullName() {
93          return theFullName;
94      }
95  
96      @Override
97      public ThemisXAnalysisSolverFileDef getOwningFile() {
98          return theFile;
99      }
100 
101     @Override
102     public ThemisXAnalysisClassInstance getUnderlyingClass() {
103         return theClass;
104     }
105 
106     /**
107      * Is this a top-level class?
108      *
109      * @return true/false
110      */
111     public boolean isTopLevel() {
112         return theClass.isTopLevel();
113     }
114 
115     /**
116      * Obtain the method list.
117      *
118      * @return the method list
119      */
120     public List<ThemisXAnalysisSolverMethod> getMethods() {
121         return theMethods;
122     }
123 
124     /**
125      * Obtain the package.
126      *
127      * @return the packageName
128      */
129     public String getPackageName() {
130         return theFile.getOwningPackage().toString();
131     }
132 
133     @Override
134     public boolean equals(final Object pThat) {
135         /* Handle the trivial cases */
136         if (this == pThat) {
137             return true;
138         }
139         if (pThat == null) {
140             return false;
141         }
142 
143         /* Make sure that the object is a DSMClass */
144         if (!(pThat instanceof ThemisXAnalysisSolverClass myThat)) {
145             return false;
146         }
147 
148         /* Check full name */
149         return theFullName.equals(myThat.getFullName());
150     }
151 
152     @Override
153     public int hashCode() {
154         return theFullName.hashCode();
155     }
156 
157     @Override
158     public String toString() {
159         return theFullName;
160     }
161 }