1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.themis.solver.proj;
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;
23 import io.github.tonywasher.joceanus.themis.parser.base.ThemisInstance.ThemisClassInstance;
24 import io.github.tonywasher.joceanus.themis.parser.base.ThemisInstance.ThemisMethodInstance;
25 import io.github.tonywasher.joceanus.themis.solver.proj.ThemisSolverDef.ThemisSolverClassDef;
26 import io.github.tonywasher.joceanus.themis.solver.proj.ThemisSolverDef.ThemisSolverFileDef;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34 public class ThemisSolverClass
35 implements ThemisSolverClassDef {
36
37
38
39 private static final MetisFieldSet<ThemisSolverClass> FIELD_DEFS = MetisFieldSet.newFieldSet(ThemisSolverClass.class);
40
41
42
43
44 static {
45 FIELD_DEFS.declareLocalField(ThemisDataResource.DATA_METHODS, ThemisSolverClass::getMethods);
46 FIELD_DEFS.declareLocalField(ThemisDataResource.DATA_UNDERLYING, ThemisSolverClass::getUnderlyingClass);
47 }
48
49
50
51
52 private final String theFullName;
53
54
55
56
57 private final ThemisSolverFileDef theFile;
58
59
60
61
62 private final ThemisClassInstance theClass;
63
64
65
66
67 private final List<ThemisSolverMethod> theMethods;
68
69
70
71
72 private final List<String> theAncestors;
73
74
75
76
77 private final boolean isStandard;
78
79
80
81
82
83
84
85 ThemisSolverClass(final ThemisSolverFileDef pFile,
86 final ThemisClassInstance pClass) {
87
88 theFile = pFile;
89 theClass = pClass;
90 theAncestors = new ArrayList<>();
91
92
93 theFullName = theClass.getFullName();
94 isStandard = pFile.getOwningPackage().isStandard();
95
96
97 theMethods = new ArrayList<>();
98 final ThemisInstance myNode = (ThemisInstance) theClass;
99 for (ThemisInstance myMethod : myNode.discoverChildren(ThemisMethodInstance.class::isInstance)) {
100 final ThemisSolverMethod mySolverMethod = new ThemisSolverMethod(this, (ThemisMethodInstance) myMethod);
101 theMethods.add(mySolverMethod);
102 }
103 }
104
105 @Override
106 public MetisFieldSet<ThemisSolverClass> getDataFieldSet() {
107 return FIELD_DEFS;
108 }
109
110 @Override
111 public String formatObject(final OceanusDataFormatter pFormatter) {
112 return toString();
113 }
114
115
116
117
118
119
120 public String getName() {
121 return theClass.getName();
122 }
123
124 @Override
125 public String getFullName() {
126 return theFullName;
127 }
128
129 @Override
130 public ThemisSolverFileDef getOwningFile() {
131 return theFile;
132 }
133
134 @Override
135 public ThemisClassInstance getUnderlyingClass() {
136 return theClass;
137 }
138
139
140
141
142
143
144 public boolean isStandard() {
145 return isStandard;
146 }
147
148
149
150
151
152
153 public boolean isTopLevel() {
154 return theClass.isTopLevel();
155 }
156
157
158
159
160
161
162 public List<ThemisSolverMethod> getMethods() {
163 return theMethods;
164 }
165
166
167
168
169
170
171 public String getPackageName() {
172 return theFile.getOwningPackage().toString();
173 }
174
175 @Override
176 public boolean equals(final Object pThat) {
177
178 if (this == pThat) {
179 return true;
180 }
181 if (pThat == null) {
182 return false;
183 }
184
185
186 if (!(pThat instanceof ThemisSolverClass myThat)) {
187 return false;
188 }
189
190
191 return theFullName.equals(myThat.getFullName());
192 }
193
194 @Override
195 public int hashCode() {
196 return theFullName.hashCode();
197 }
198
199 @Override
200 public String toString() {
201 return theFullName;
202 }
203
204
205
206
207
208
209 public List<String> getAncestors() {
210 return theAncestors;
211 }
212
213
214
215
216
217
218 public void addAncestor(final String pAncestor) {
219 theAncestors.add(pAncestor);
220 }
221 }