Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import liquidjava.specification.Refinement;

@SuppressWarnings("unused")
public class ErrorSyntax1 {
public class ErrorSyntaxRefinement {
public static void main(String[] args) {
@Refinement("_ < 100 +")
int value = 90 + 4;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Syntax Error
package testSuite;

import liquidjava.specification.StateRefinement;

public class ErrorSyntaxStateRefinement {

@StateRefinement(from="$", to="#")
void test() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected void handleAlias(String ref, CtElement element) throws LJError {
}
} catch (LJError e) {
// add location info to error
SourcePosition pos = Utils.getRefinementAnnotationPosition(element, ref);
SourcePosition pos = Utils.getAnnotationPosition(element, ref);
e.setPosition(pos);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected Expression parse(String ref, CtElement element) throws LJError {
return RefinementsParser.createAST(ref, prefix);
} catch (LJError e) {
// add location info to error
SourcePosition pos = Utils.getRefinementAnnotationPosition(element, ref);
SourcePosition pos = Utils.getAnnotationPosition(element, ref);
e.setPosition(pos);
throw e;
}
Expand Down
23 changes: 17 additions & 6 deletions liquidjava-verifier/src/main/java/liquidjava/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package liquidjava.utils;

import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import liquidjava.utils.constants.Types;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.factory.Factory;
import spoon.reflect.reference.CtTypeReference;
Expand Down Expand Up @@ -35,11 +38,19 @@ public static String qualifyName(String prefix, String name) {
return String.format("%s.%s", prefix, name);
}

public static SourcePosition getRefinementAnnotationPosition(CtElement element, String refinement) {
return element.getAnnotations().stream().filter(a -> {
String value = a.getValue("value").toString();
String unquoted = value.substring(1, value.length() - 1);
return unquoted.equals(refinement);
}).findFirst().map(CtElement::getPosition).orElse(element.getPosition());
public static SourcePosition getAnnotationPosition(CtElement element, String refinement) {
return element.getAnnotations().stream()
.filter(a -> isLiquidJavaAnnotation(a) && hasRefinementValue(a, "\"" + refinement + "\"")).findFirst()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work well if the error is just on the "to" of a state refinement?

Copy link
Collaborator Author

@rcosta358 rcosta358 Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, It can be in either the value field of a @Refinement or in the from or to of a @StateRefinement. This logic is simply to get the position of the annotation that actually contains the refinement that caused error, e.g. we could have multiple state refinements and we want to get the position of the right one.

private static boolean hasRefinementValue(CtAnnotation<?> annotation, String refinement) {
Map<String, ?> values = annotation.getValues();
return Stream.of("value", "to", "from")
.anyMatch(key -> refinement.equals(String.valueOf(values.get(key))));
}

.map(CtElement::getPosition).orElse(element.getPosition());
}

private static boolean isLiquidJavaAnnotation(CtAnnotation<?> annotation) {
return annotation.getAnnotationType().getQualifiedName().startsWith("liquidjava.specification");
}

private static boolean hasRefinementValue(CtAnnotation<?> annotation, String refinement) {
Map<String, ?> values = annotation.getValues();
return Stream.of("value", "to", "from")
.anyMatch(key -> refinement.equals(String.valueOf(values.get(key))));
}
}