use of com.google.template.soy.pysrc.internal.GenPyExprsVisitor.GenPyExprsVisitorFactory in project closure-templates by google.
the class PySrcMain method createVisitor.
@VisibleForTesting
static GenPyCodeVisitor createVisitor(SoyPySrcOptions pySrcOptions, ImmutableMap<String, String> currentManifest) {
final IsComputableAsPyExprVisitor isComputableAsPyExprs = new IsComputableAsPyExprVisitor();
// here we resolve it with a mutable field in a custom provider
class PyCallExprVisitorSupplier implements Supplier<GenPyCallExprVisitor> {
GenPyExprsVisitorFactory factory;
@Override
public GenPyCallExprVisitor get() {
return new GenPyCallExprVisitor(isComputableAsPyExprs, checkNotNull(factory));
}
}
PyCallExprVisitorSupplier provider = new PyCallExprVisitorSupplier();
GenPyExprsVisitorFactory genPyExprsFactory = new GenPyExprsVisitorFactory(isComputableAsPyExprs, provider);
provider.factory = genPyExprsFactory;
return new GenPyCodeVisitor(pySrcOptions, currentManifest, isComputableAsPyExprs, genPyExprsFactory, provider.get());
}
use of com.google.template.soy.pysrc.internal.GenPyExprsVisitor.GenPyExprsVisitorFactory in project closure-templates by google.
the class SoyExprForPySubject method compilesTo.
/**
* Asserts the subject compiles to the correct list of PyExprs.
*
* <p>The given Soy expr is wrapped in a full body of a template. The actual result is replaced
* with ids for ### so that tests don't break when ids change.
*
* @param expectedPyExprs the expected result of compilation
*/
public void compilesTo(List<PyExpr> expectedPyExprs) {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(getSubject()).parse().fileSet();
SoyNode node = SharedTestUtils.getNode(soyTree, 0);
SharedTestUtils.simulateNewApiCall(injector, null, BidiGlobalDir.LTR);
final IsComputableAsPyExprVisitor isComputableAsPyExprs = new IsComputableAsPyExprVisitor();
// here we resolve it with a mutable field in a custom provider
class PyCallExprVisitorSupplier implements Supplier<GenPyCallExprVisitor> {
GenPyExprsVisitorFactory factory;
@Override
public GenPyCallExprVisitor get() {
return new GenPyCallExprVisitor(isComputableAsPyExprs, checkNotNull(factory));
}
}
PyCallExprVisitorSupplier provider = new PyCallExprVisitorSupplier();
GenPyExprsVisitorFactory genPyExprsFactory = new GenPyExprsVisitorFactory(isComputableAsPyExprs, provider);
provider.factory = genPyExprsFactory;
GenPyExprsVisitor genPyExprsVisitor = genPyExprsFactory.create(localVarExprs, ErrorReporter.exploding());
List<PyExpr> actualPyExprs = genPyExprsVisitor.exec(node);
assertThat(actualPyExprs).hasSize(expectedPyExprs.size());
for (int i = 0; i < expectedPyExprs.size(); i++) {
PyExpr expectedPyExpr = expectedPyExprs.get(i);
PyExpr actualPyExpr = actualPyExprs.get(i);
assertThat(actualPyExpr.getText().replaceAll("\\([0-9]+", "(###")).isEqualTo(expectedPyExpr.getText());
assertThat(actualPyExpr.getPrecedence()).isEqualTo(expectedPyExpr.getPrecedence());
}
}
Aggregations