Search in sources :

Example 71 with SoyFileSetNode

use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.

the class SoyFileSet method doExtractMsgs.

/**
 * Performs the parsing and extraction logic.
 */
private SoyMsgBundle doExtractMsgs() {
    // extractMsgs disables a bunch of passes since it is typically not configured with things
    // like global definitions, type definitions, etc.
    SoyFileSetNode soyTree = parse(passManagerBuilder(SyntaxVersion.V1_0).allowUnknownGlobals().setTypeRegistry(SoyTypeRegistry.DEFAULT_UNKNOWN).disableAllTypeChecking(), // can't resolve strict types
    SoyTypeRegistry.DEFAULT_UNKNOWN, new PluginResolver(PluginResolver.Mode.ALLOW_UNDEFINED, printDirectives, soyFunctionMap, errorReporter)).fileSet();
    throwIfErrorsPresent();
    SoyMsgBundle bundle = new ExtractMsgsVisitor().exec(soyTree);
    throwIfErrorsPresent();
    return bundle;
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) PluginResolver(com.google.template.soy.soyparse.PluginResolver) SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle) ExtractMsgsVisitor(com.google.template.soy.msgs.internal.ExtractMsgsVisitor)

Example 72 with SoyFileSetNode

use of com.google.template.soy.soytree.SoyFileSetNode 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);
    }
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) IdGenerator(com.google.template.soy.base.internal.IdGenerator) IncrementingIdGenerator(com.google.template.soy.base.internal.IncrementingIdGenerator) SoyFileSupplier(com.google.template.soy.base.internal.SoyFileSupplier) IncrementingIdGenerator(com.google.template.soy.base.internal.IncrementingIdGenerator) SoyFileNode(com.google.template.soy.soytree.SoyFileNode) VersionedFile(com.google.template.soy.shared.SoyAstCache.VersionedFile)

Example 73 with SoyFileSetNode

use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.

the class ResolveExpressionTypesVisitorTest method testDataFlowTypeNarrowing_logicalExpressions.

@Test
public void testDataFlowTypeNarrowing_logicalExpressions() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param? record: [active : bool|null]}", "{@param? selected: map<string,bool>}", "{assertType('bool', $selected and $selected['a'])}", "{assertType('bool', $selected == null or $selected['a'])}", "{if isNonnull($record.active) and (not $record.active)}", "  {assertType('bool', $record.active)}", "{/if}", "")).addSoyFunction(ASSERT_TYPE_FUNCTION).declaredSyntaxVersion(SyntaxVersion.V2_4).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 74 with SoyFileSetNode

use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.

the class ResolveExpressionTypesVisitorTest method testNullCoalescingAndConditionalOps_complexCondition.

@Test
public void testNullCoalescingAndConditionalOps_complexCondition() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param? l: [a :int]}", "{assertType('int', $l?.a ?: 0)}")).declaredSyntaxVersion(SyntaxVersion.V2_0).typeRegistry(TYPE_REGISTRY).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 75 with SoyFileSetNode

use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.

the class ResolveExpressionTypesVisitorTest method testStringConcatenation.

@Test
public void testStringConcatenation() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param ps: string}", "{@param pi: int}", "{@param pf: float}", "{assertType('string', $ps + $ps)}", "{assertType('string', $ps + $pi)}", "{assertType('string', $ps + $pf)}", "{assertType('string', $pi + $ps)}", "{assertType('string', $pf + $ps)}")).declaredSyntaxVersion(SyntaxVersion.V2_0).typeRegistry(TYPE_REGISTRY).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
    assertTypes(soyTree);
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Aggregations

SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)106 Test (org.junit.Test)81 TemplateNode (com.google.template.soy.soytree.TemplateNode)35 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)29 ErrorReporter (com.google.template.soy.error.ErrorReporter)19 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)13 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)8 RawTextNode (com.google.template.soy.soytree.RawTextNode)8 MsgNode (com.google.template.soy.soytree.MsgNode)7 SoyNode (com.google.template.soy.soytree.SoyNode)6 CompiledTemplates (com.google.template.soy.jbcsrc.shared.CompiledTemplates)5 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)5 PrintNode (com.google.template.soy.soytree.PrintNode)5 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)4 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)4 CompiledTemplate (com.google.template.soy.jbcsrc.shared.CompiledTemplate)3 SoyMsg (com.google.template.soy.msgs.restricted.SoyMsg)3 SoyMsgBundleImpl (com.google.template.soy.msgs.restricted.SoyMsgBundleImpl)3 PluginResolver (com.google.template.soy.soyparse.PluginResolver)3 ImmutableList (com.google.common.collect.ImmutableList)2