aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/TermEvaluator.java
blob: ab123c5067cffc91ed095c18e30d883d46fa1024 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package tools.refinery.store.query.viatra.internal.pquery;

import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
import tools.refinery.store.query.term.Term;
import tools.refinery.store.query.term.Variable;

import java.util.stream.Collectors;

class TermEvaluator<T> implements IExpressionEvaluator {
	private final Term<T> term;

	public TermEvaluator(Term<T> term) {
		this.term = term;
	}

	@Override
	public String getShortDescription() {
		return term.toString();
	}

	@Override
	public Iterable<String> getInputParameterNames() {
		return term.getInputVariables().stream().map(Variable::getUniqueName).collect(Collectors.toUnmodifiableSet());
	}

	@Override
	public Object evaluateExpression(IValueProvider provider) {
		var valuation = new ValueProviderBasedValuation(provider);
		return term.evaluate(valuation);
	}
}