8000 Use subclass for denoting a constant field in ABI usage · sakerbuild/saker.java.compiler@4faaa00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4faaa00

Browse files
committed
Use subclass for denoting a constant field in ABI usage
1 parent 2fc5c9a commit 4faaa00

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

impl/src/main/saker/java/compiler/impl/compile/handler/usage/TopLevelAbiUsage.java

Lines changed: 30 additions & 25 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ public int compareTo(MethodABIInfo o) {
135135
if (cmp != 0) {
136136
return cmp;
137137
}
138-
cmp = methodName.compareTo(o.methodName);
139-
if (cmp != 0) {
140-
return cmp;
141-
}
142-
return 0;
138+
return methodName.compareTo(o.methodName);
143139
}
144140

145141
@Override
@@ -193,28 +189,48 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
193189
}
194190
}
195191

196-
public static final class FieldABIInfo implements Comparable<FieldABIInfo>, Externalizable {
192+
public static class FieldABIInfo implements Comparable<FieldABIInfo>, Externalizable {
197193
private static final long serialVersionUID = 1L;
198194

199195
protected String classCanonicalName;
200196
protected String fieldName;
201-
protected boolean hasConstantValue;
202197

203198
/**
204199
* For {@link Externalizable}.
205200
*/
206201
public FieldABIInfo() {
207202
}
208203

209-
private FieldABIInfo(String classCanonicalName, String fieldName, boolean hasConstantValue) {
204+
private FieldABIInfo(String classCanonicalName, String fieldName) {
210205
this.classCanonicalName = classCanonicalName;
211206
this.fieldName = fieldName;
212-
this.hasConstantValue = hasConstantValue;
213207
}
214208

215209
public static FieldABIInfo create(ClassSignature enclosingclass, FieldSignature signature) {
216-
return new FieldABIInfo(enclosingclass.getCanonicalName(), signature.getSimpleName(),
217-
signature.getConstantValue() != null);
210+
if (signature.getConstantValue() != null) {
211+
return new ConstantFieldABIInfo(enclosingclass.getCanonicalName(), signature.getSimpleName());
212+
}
213+
return new FieldABIInfo(enclosingclass.getCanonicalName(), signature.getSimpleName());
214+
}
215+
216+
private static class ConstantFieldABIInfo extends FieldABIInfo {
217+
private static final long serialVersionUID = 1L;
218+
219+
/**
220+
* For {@link Externalizable}.
221+
*/
222+
public ConstantFieldABIInfo() {
223+
}
224+
225+
protected ConstantFieldABIInfo(String classCanonicalName, String fieldName) {
226+
super(classCanonicalName, fieldName);
227+
}
228+
229+
@Override
230+
public boolean hasConstantValue() {
231+
return true;
232+
}
233+
218234
}
219235

220236
public String getClassCanonicalName() {
@@ -226,7 +242,7 @@ public String getFieldName() {
226242
}
227243

228244
public boolean hasConstantValue() {
229-
return hasConstantValue;
245+
return false;
230246
}
231247

232248
@Override
@@ -239,11 +255,7 @@ public int compareTo(FieldABIInfo o) {
239255
if (cmp != 0) {
240256
return cmp;
241257
}
242-
cmp = Boolean.compare(hasConstantValue, o.hasConstantValue);
243-
if (cmp != 0) {
244-
return cmp;
245-
}
246-
return 0;
258+
return Boolean.compare(hasConstantValue(), o.hasConstantValue());
247259
}
248260

249261
@Override
@@ -252,7 +264,6 @@ public int hashCode() {
252264
int result = 1;
253265
result = prime * result + ((classCanonicalName == null) ? 0 : classCanonicalName.hashCode());
254266
result = prime * result + ((fieldName == null) ? 0 : fieldName.hashCode());
255-
result = prime * result + (hasConstantValue ? 1231 : 1237);
256267
return result;
257268
}
258269

@@ -275,33 +286,27 @@ public boolean equals(Object obj) {
275286
return false;
276287
} else if (!fieldName.equals(other.fieldName))
277288
return false;
278-
if (hasConstantValue != other.hasConstantValue)
279-
return false;
280289
return true;
281290
}
282291

283292
@Override
284293
public String toString() {
285294
return getClass().getSimpleName() + "["
286295
+ (classCanonicalName != null ? "classCanonicalName=" + classCanonicalName + ", " : "")
287-
+ (fieldName != null ? "fieldName=" + fieldName + ", " : "") + "hasConstantValue="
288-
+ hasConstantValue + "]";
296+
+ (fieldName != null ? "fieldName=" + fieldName + ", " : "") + "]";
289297
}
290298

291299
@Override
292300
public void writeExternal(ObjectOutput out) throws IOException {
293301
out.writeObject(classCanonicalName);
294302
out.writeObject(fieldName);
295-
out.writeBoolean(hasConstantValue);
296303
}
297304

298305
@Override
299306
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
300307
classCanonicalName = (String) in.readObject();
301308
fieldName = (String) in.readObject();
302-
hasConstantValue = in.readBoolean();
303309
}
304-
305310
}
306311

307312
public Map<ClassABIInfo, ? extends AbiUsage> getClasses();

0 commit comments

Comments
 (0)
0