Search in sources :

Example 1 with AmbiguousSymbolException

use of org.activityinfo.model.formula.diagnostic.AmbiguousSymbolException in project activityinfo by bedatadriven.

the class FormSymbolTable method tryResolveSymbol.

public Optional<FormField> tryResolveSymbol(String name) {
    FormField field = idMap.get(name);
    if (field != null) {
        return Optional.of(field);
    }
    Collection<FormField> matching = codeMap.get(name.toLowerCase());
    if (matching.isEmpty()) {
        // as last resort, try matching against label
        matching = labelMap.get(name.toLowerCase());
    }
    if (matching.size() > 1) {
        throw new AmbiguousSymbolException(name);
    } else if (matching.isEmpty()) {
        return Optional.absent();
    } else {
        return Optional.of(Iterables.getOnlyElement(matching));
    }
}
Also used : AmbiguousSymbolException(org.activityinfo.model.formula.diagnostic.AmbiguousSymbolException) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormField (org.activityinfo.model.form.FormField)1 AmbiguousSymbolException (org.activityinfo.model.formula.diagnostic.AmbiguousSymbolException)1