Skip to content

Review the wording around Query vs Predicate or Clause #126

@cmoulliard

Description

@cmoulliard

TODO

Review the wording around Query vs words like: Predicate or Clause as a Query represents the user's string including different substring separated or not with AND, OR operators. As within the code we use a Query class to transport the information of

public class QueryVisitor extends QueryBaseVisitor<Set<Query>> {
    Set<Query> simpleQueries = new LinkedHashSet<>();
    Set<Query> andQueries = new LinkedHashSet<>();
    Set<Query> orQueries = new LinkedHashSet<>();

we should certainly review the definition to use a more appropriate wording

public class QueryVisitor extends QueryBaseVisitor<Set<Predicate>> {
    Set<Predicate> simpleQueries = new LinkedHashSet<>();
    Set<Predicate> andQueries = new LinkedHashSet<>();
    Set<Predicate> orQueries = new LinkedHashSet<>();

Such a change should also include the antlr query wording

// From
searchQuery: operation;
operation
    : operation AND operation #AndOperation
    | operation OR operation #OrOperation
    | clause #SimpleClause
    ;

clause: fileType ('.' symbol)? ('is' | '=') (value | '(' keyValuePair (',' keyValuePair)* ')');

// To
query: predicates;
predicates
    : predicate AND predicate   #AndPredicate
    | predicate OR predicate      #OrPredicate
    | predicate                                  #Predicate
    ;

the new wording will help the developer to better understand how the code internally is working
as the query object returned by the visitor will include (depending which word we use now to name the substring) a list of by example Predicates or OrPredicates, etc

QueryVisitor query = QueryUtils.parseAndVisit(rule.when().condition());

if (query.getPredicates().size() == 1) {
            query.getPredicates().stream().findFirst().ifPresent(p -> {
                List<SymbolInformation> results = executeCommand(config, p);
                ruleResults.putAll(Map.of(rule.ruleID(), results));
            });
        } else if (query.getOrPredicates().size() > 1) {
            query.getOrPredicates().stream().forEach(q -> {
                List<SymbolInformation> results = executeCommand(config, p);
                ruleResults.putAll(Map.of(rule.ruleID(), results));
            });
        } else if (query.getAndPredicates().size() > 1) {
            query.getAndQueries().stream().forEach(q -> {
                List<SymbolInformation> results = executeCommand(config, p);
                ruleResults.putAll(Map.of(rule.ruleID(), results));
            });
        } else {
            logger.warnf("Rule %s has no valid condition(s)", rule.ruleID());
            ruleResults.put(rule.ruleID(), new ArrayList<>());
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions