use of com.google.template.soy.base.internal.IdGenerator in project closure-templates by google.
the class DesugarHtmlNodesPass method run.
@Override
public void run(SoyFileSetNode fileSet, TemplateRegistry registry) {
IdGenerator idGenerator = fileSet.getNodeIdGenerator();
run(fileSet, idGenerator);
}
use of com.google.template.soy.base.internal.IdGenerator in project closure-templates by google.
the class SoyTreeUtilsTest method testCloneWithNewIds.
@Test
public final void testCloneWithNewIds() throws Exception {
IdGenerator nodeIdGen = new IncrementingIdGenerator();
SoyFileSetNode soyTree = new SoyFileSetNode(nodeIdGen.genId(), nodeIdGen);
SoyFileNode soyFile = SoyFileSetParserBuilder.forFileContents(SOY_SOURCE_FOR_TESTING_CLONING).parse().fileSet().getChild(0);
soyTree.addChild(soyFile);
SoyFileSetNode clone = SoyTreeUtils.cloneWithNewIds(soyTree, nodeIdGen);
assertEquals(1, clone.numChildren());
assertFalse(clone.getId() == soyTree.getId());
assertEquals(clone.getChild(0).toSourceString(), soyFile.toSourceString());
}
use of com.google.template.soy.base.internal.IdGenerator in project closure-templates by google.
the class SoyFileSetParser method parseWithVersions.
/**
* Parses a set of Soy files, returning a structure containing the parse tree and template
* registry.
*/
private ParseResult parseWithVersions() throws IOException {
IdGenerator nodeIdGen = (cache() != null) ? cache().getNodeIdGenerator() : new IncrementingIdGenerator();
SoyFileSetNode soyTree = new SoyFileSetNode(nodeIdGen.genId(), nodeIdGen);
boolean filesWereSkipped = false;
// generator but fail to lock on it. Eliminate the id system to avoid this whole issue.
synchronized (nodeIdGen) {
// Avoid using the same ID generator in multiple threads.
for (SoyFileSupplier fileSupplier : soyFileSuppliers().values()) {
SoyFileSupplier.Version version = fileSupplier.getVersion();
VersionedFile cachedFile = cache() != null ? cache().get(fileSupplier.getFilePath(), version) : null;
SoyFileNode node;
if (cachedFile == null) {
node = parseSoyFileHelper(fileSupplier, nodeIdGen, typeRegistry());
// a malformed parse tree.
if (node == null) {
filesWereSkipped = true;
continue;
}
// Run passes that are considered part of initial parsing.
passManager().runSingleFilePasses(node, nodeIdGen);
// Run passes that check the tree.
if (cache() != null) {
cache().put(fileSupplier.getFilePath(), VersionedFile.of(node, version));
}
} else {
node = cachedFile.file();
}
soyTree.addChild(node);
}
TemplateRegistry registry;
// Run passes that check the tree iff we successfully parsed every file.
if (!filesWereSkipped) {
registry = passManager().runWholeFilesetPasses(soyTree);
} else {
registry = new TemplateRegistry(soyTree, errorReporter());
}
return ParseResult.create(soyTree, registry);
}
}
Aggregations