Skip to content

Commit 2e77dfa

Browse files
add more javadoc
1 parent 9cacea7 commit 2e77dfa

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

liquidjava-verifier/src/main/java/liquidjava/rj_language/Predicate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private static Expression resolveStaticFinalConstants(Expression root, CtElement
9898
}
9999
if (StaticConstants.userTypeExists(en.getTypeName(), context))
100100
continue; // likely a user-defined enum/class — let SMT translation handle it
101+
// unresolvable reference — throw an error with a helpful message and import suggestion if possible
101102
SourcePosition pos = context == null ? null : Utils.getLJAnnotationPosition(context, en.toString());
102103
String suggested = StaticConstants.findImportCandidate(en.getTypeName(), en.getConstName(), context);
103104
String hint = suggested != null ? "add: import " + suggested + ";"

liquidjava-verifier/src/main/java/liquidjava/utils/StaticConstants.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ public final class StaticConstants {
2323
private StaticConstants() {
2424
}
2525

26-
/** Resolve a Spoon field reference to its compile-time constant value, source AST first then reflection. */
26+
/**
27+
* Resolve a Spoon {@code static final} field reference to its compile-time value, so reads like
28+
* {@code Integer.MAX_VALUE} or {@code MyConfig.LIMIT} fold to literals before SMT translation.
29+
*
30+
* <p>Tries the source AST first ({@link CtLiteral} initializer in Spoon's model), then reflection via
31+
* {@link CtFieldReference#getActualField()} + {@link #readStaticFinal}. Returns {@code null} if the field
32+
* isn't static-final, has a non-literal initializer, or any lookup step fails.
33+
*
34+
* @see #resolve(String, String, CtElement) sibling for refinement-string {@code Type.CONST} references
35+
*/
2736
public static Object resolve(CtFieldReference<?> ref) {
2837
if (!ref.isStatic() || !ref.isFinal())
2938
return null;
@@ -132,6 +141,15 @@ public static Predicate asLiteralPredicate(Object value) {
132141
return null;
133142
}
134143

144+
/**
145+
* Reflectively read {@code className.fieldName} as a {@code public static final} constant — e.g.
146+
* {@code lookup("java.lang.Integer", "MAX_VALUE")} returns {@code 2147483647}, which is how
147+
* {@code Integer.MAX_VALUE} gets baked into the AST before SMT translation.
148+
*
149+
* <p>Returns {@code null} on any failure ({@link ClassNotFoundException}, {@link NoSuchFieldException},
150+
* {@link LinkageError}, {@link SecurityException}, or non-static-final) so callers can fall through to the
151+
* next resolution strategy without a try/catch. Only public fields are visible to {@link Class#getField}.
152+
*/
135153
private static Object lookup(String className, String fieldName) {
136154
try {
137155
return readStaticFinal(Class.forName(className).getField(fieldName));

0 commit comments

Comments
 (0)