Search in sources :

Example 1 with SourceRange

use of org.activityinfo.model.formula.SourceRange in project activityinfo by bedatadriven.

the class Linter method applyMarks.

private void applyMarks(ParsedFormula formula) {
    if (!formula.isValid()) {
        for (FormulaError error : formula.getErrors()) {
            if (error.hasSourceRange()) {
                SourceRange range = error.getSourceRange();
                MarkOptions options = MarkOptions.create();
                options.setClassName("CodeMirror-lint-mark-error");
                options.setTitle(error.getMessage());
                TextMarker marker = editor.getDoc().markText(pos(range.getStart()), pos(range.getEnd()), options);
                markers.add(marker);
            }
        }
    } else {
        for (FieldReference fieldReference : formula.getReferences()) {
            SourceRange range = fieldReference.getSourceRange();
            MarkOptions options = MarkOptions.create();
            options.setClassName(FormulaResources.INSTANCE.styles().fieldAnnotation());
            options.setTitle(fieldReference.getDescription());
            TextMarker marker = editor.getDoc().markText(pos(range.getStart()), pos(range.getEnd()), options);
            markers.add(marker);
        }
    }
}
Also used : FieldReference(org.activityinfo.analysis.FieldReference) FormulaError(org.activityinfo.model.formula.FormulaError) SourceRange(org.activityinfo.model.formula.SourceRange)

Example 2 with SourceRange

use of org.activityinfo.model.formula.SourceRange in project activityinfo by bedatadriven.

the class FormulaValidatorTest method badNumberOfArguments.

@Test
public void badNumberOfArguments() {
    FormulaValidator validator = validate("IF(1)");
    assertThat(validator.getErrors(), hasSize(1));
    assertThat(validator.getErrors().get(0).getSourceRange(), equalTo(new SourceRange(new SourcePos(0, 0), 5)));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) SourceRange(org.activityinfo.model.formula.SourceRange) SourcePos(org.activityinfo.model.formula.SourcePos) Test(org.junit.Test)

Aggregations

SourceRange (org.activityinfo.model.formula.SourceRange)2 FieldReference (org.activityinfo.analysis.FieldReference)1 FormulaValidator (org.activityinfo.analysis.FormulaValidator)1 FormulaError (org.activityinfo.model.formula.FormulaError)1 SourcePos (org.activityinfo.model.formula.SourcePos)1 Test (org.junit.Test)1