Skip to content

Commit d60e268

Browse files
lukesandbergBrendan Linn
authored andcommitted
Add fully qualified deltemplate names to the parseinfos
This will make it possible to construct a deltemplate selector for soysauce without needing to run the compiler. The idea is that the user will hand us a set of SoyFileInfos and we can use that to find all the public basic templates and all the deltemplates. The combination of these two things will allow us to * construct a deltemplate selector (see [] * calculate transitive used ij params (see [] With these two things, we can construct a SoySauce object from classes found on the normal classpath. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=106339837
1 parent 85dc066 commit d60e268

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

java/src/com/google/template/soy/examples/FeaturesSoyInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ private FeaturesSoyInfo() {
872872
DEMO_BIDI_SUPPORT,
873873
BIDI_GLOBAL_DIR,
874874
EXAMPLE_HEADER),
875-
ImmutableMap.<String, CssTagsPrefixPresence>of());
875+
ImmutableMap.<String, CssTagsPrefixPresence>of(),
876+
ImmutableList.<String>of());
876877
}
877878

878879

java/src/com/google/template/soy/parseinfo/SoyFileInfo.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,16 @@ public static enum CssTagsPrefixPresence {
4545
/** The Soy file's namespace. */
4646
private final String namespace;
4747

48-
/** List of templates in this Soy file. */
48+
/** List of public basic templates in this Soy file. */
4949
private final ImmutableList<SoyTemplateInfo> templates;
5050

51+
/**
52+
* List of all deltemplate names in the Soy file.
53+
*
54+
* <p>These are the mangled names.
55+
*/
56+
private final ImmutableList<String> deltemplateNames;
57+
5158
/** Map from each CSS name appearing in this file to its CssTagsPrefixPresence state. */
5259
private final ImmutableMap<String, CssTagsPrefixPresence> cssNameMap;
5360

@@ -65,11 +72,13 @@ public static enum CssTagsPrefixPresence {
6572
public SoyFileInfo(
6673
String fileName, String namespace,
6774
ImmutableList<SoyTemplateInfo> templates,
68-
ImmutableMap<String, CssTagsPrefixPresence> cssNameMap) {
75+
ImmutableMap<String, CssTagsPrefixPresence> cssNameMap,
76+
ImmutableList<String> deltemplateNames) {
6977
this.fileName = fileName;
7078
this.namespace = namespace;
7179
this.templates = templates;
7280
this.cssNameMap = cssNameMap;
81+
this.deltemplateNames = deltemplateNames;
7382
}
7483

7584

@@ -100,4 +109,11 @@ public ImmutableMap<String, CssTagsPrefixPresence> getCssNames() {
100109
public ImmutableList<Object> getProtoTypes() {
101110
return ImmutableList.of();
102111
}
112+
113+
/**
114+
* Returns the fully qualified names of all deltemplates in the file.
115+
*/
116+
public ImmutableList<String> getAllTemplateNames() {
117+
return deltemplateNames;
118+
}
103119
}

java/src/com/google/template/soy/parseinfo/passes/GenerateParseInfoVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.google.template.soy.types.aggregate.UnionType;
6464
import com.google.template.soy.types.proto.SoyProtoType;
6565

66+
import java.util.ArrayList;
6667
import java.util.Collection;
6768
import java.util.LinkedHashMap;
6869
import java.util.List;
@@ -307,6 +308,7 @@ public GenerateParseInfoVisitor(
307308
// + for each param key, the list of templates that list it directly.
308309
// + for any params whose type is a proto, get the proto name and Java class name.
309310
LinkedHashMap<String, TemplateNode> publicBasicTemplateMap = Maps.newLinkedHashMap();
311+
List<String> deltemplates = new ArrayList<>();
310312
Set<String> allParamKeys = Sets.newHashSet();
311313
LinkedHashMultimap<String, TemplateNode> paramKeyToTemplatesMultimap =
312314
LinkedHashMultimap.create();
@@ -317,6 +319,9 @@ public GenerateParseInfoVisitor(
317319
publicBasicTemplateMap.put(
318320
convertToUpperUnderscore(template.getPartialTemplateName().substring(1)), template);
319321
}
322+
if (template instanceof TemplateDelegateNode) {
323+
deltemplates.add("\"" + template.getTemplateName() + "\"");
324+
}
320325
for (TemplateParam param : template.getAllParams()) {
321326
if (!param.isInjected()) {
322327
allParamKeys.add(param.name());
@@ -489,6 +494,8 @@ public GenerateParseInfoVisitor(
489494
"CssTagsPrefixPresence." + entry.getValue().name()));
490495
}
491496
appendImmutableMap(ilb, "<String, CssTagsPrefixPresence>", entrySnippetPairs);
497+
ilb.appendLineEnd(",");
498+
appendImmutableList(ilb, "<String>", deltemplates);
492499
ilb.appendLineEnd(");");
493500

494501
ilb.decreaseIndent(2);

java/tests/com/google/template/soy/test_data/ParseInfoExampleSoyInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ private ParseInfoExampleSoyInfo() {
193193
.put("_eee_fff", CssTagsPrefixPresence.ALWAYS)
194194
.put("aaa-bbb", CssTagsPrefixPresence.NEVER)
195195
.put("cccDdd", CssTagsPrefixPresence.SOMETIMES)
196-
.build());
196+
.build(),
197+
ImmutableList.<String>of());
197198
}
198199

199200

java/tests/com/google/template/soy/test_data/ParseInfoIjExampleSoyInfo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ private ParseInfoIjExampleSoyInfo() {
203203
HELLO,
204204
AAA,
205205
BBB_CCC),
206-
ImmutableMap.<String, CssTagsPrefixPresence>of());
206+
ImmutableMap.<String, CssTagsPrefixPresence>of(),
207+
ImmutableList.<String>of(
208+
"examples.abc.__deltemplate_s19_ce8ad760"));
207209
}
208210

209211

testdata/javascript/soy_usegoog_lib.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)