@@ -2216,84 +2216,55 @@ public static Map<VirtualFile, Collection<String>> getBlockNamesForFiles(@NotNul
2216
2216
* Visit all possible Twig include file pattern
2217
2217
*/
2218
2218
public static void visitTemplateIncludes (@ NotNull TwigFile twigFile , @ NotNull Consumer <TemplateInclude > consumer ) {
2219
- visitTemplateIncludes (
2220
- twigFile ,
2221
- consumer ,
2222
- TemplateInclude .TYPE .EMBED ,
2223
- TemplateInclude .TYPE .INCLUDE ,
2224
- TemplateInclude .TYPE .INCLUDE_FUNCTION ,
2225
- TemplateInclude .TYPE .FROM ,
2226
- TemplateInclude .TYPE .IMPORT ,
2227
- TemplateInclude .TYPE .FORM_THEME
2228
- );
2229
- }
2230
-
2231
- private static void visitTemplateIncludes (@ NotNull TwigFile twigFile , @ NotNull Consumer <TemplateInclude > consumer , @ NotNull TemplateInclude .TYPE ... types ) {
2232
- if (types .length == 0 ) {
2233
- return ;
2234
- }
2235
-
2236
- List <TemplateInclude .TYPE > myTypes = Arrays .asList (types );
2237
-
2238
2219
PsiTreeUtil .collectElements (twigFile , psiElement -> {
2239
2220
if (psiElement instanceof TwigTagWithFileReference ) {
2240
2221
// {% include %}
2241
- if (myTypes .contains (TemplateInclude .TYPE .INCLUDE )) {
2242
- if (psiElement .getNode ().getElementType () == TwigElementTypes .INCLUDE_TAG ) {
2243
- for (String templateName : getIncludeTagStrings ((TwigTagWithFileReference ) psiElement )) {
2244
- if (StringUtils .isNotBlank (templateName )) {
2245
- consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .INCLUDE ));
2246
- }
2222
+ if (psiElement .getNode ().getElementType () == TwigElementTypes .INCLUDE_TAG ) {
2223
+ for (String templateName : getIncludeTagStrings ((TwigTagWithFileReference ) psiElement )) {
2224
+ if (StringUtils .isNotBlank (templateName )) {
2225
+ consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .INCLUDE ));
2247
2226
}
2248
2227
}
2249
2228
}
2250
2229
2251
2230
// {% import "foo.html.twig"
2252
- if (myTypes .contains (TemplateInclude .TYPE .IMPORT )) {
2253
- PsiElement embedTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getTagNameParameterPattern (TwigElementTypes .IMPORT_TAG , "import" ));
2254
- if (embedTag != null ) {
2255
- String templateName = embedTag .getText ();
2256
- if (StringUtils .isNotBlank (templateName )) {
2257
- consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .IMPORT ));
2258
- }
2231
+ PsiElement importTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getTagNameParameterPattern (TwigElementTypes .IMPORT_TAG , "import" ));
2232
+ if (importTag != null ) {
2233
+ String templateName = importTag .getText ();
2234
+ if (StringUtils .isNotBlank (templateName )) {
2235
+ consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .IMPORT ));
2259
2236
}
2260
2237
}
2261
2238
2262
2239
// {% from 'forms.html' import ... %}
2263
- if (myTypes .contains (TemplateInclude .TYPE .FROM )) {
2264
- PsiElement embedTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getTagNameParameterPattern (TwigElementTypes .IMPORT_TAG , "from" ));
2265
- if (embedTag != null ) {
2266
- String templateName = embedTag .getText ();
2267
- if (StringUtils .isNotBlank (templateName )) {
2268
- consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .IMPORT ));
2269
- }
2240
+ PsiElement fromTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getTagNameParameterPattern (TwigElementTypes .IMPORT_TAG , "from" ));
2241
+ if (fromTag != null ) {
2242
+ String templateName = fromTag .getText ();
2243
+ if (StringUtils .isNotBlank (templateName )) {
2244
+ consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .IMPORT ));
<
D7AE
/tr>2270
2245
}
2271
2246
}
2272
2247
} else if (psiElement instanceof TwigCompositeElement ) {
2273
2248
// {{ include() }}
2274
2249
// {{ source() }}
2275
- if (myTypes .contains (TemplateInclude .TYPE .INCLUDE_FUNCTION )) {
2276
- PsiElement includeTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getPrintBlockOrTagFunctionPattern ("include" , "source" ));
2277
- if (includeTag != null ) {
2278
- String templateName = includeTag .getText ();
2279
- if (StringUtils .isNotBlank (templateName )) {
2280
- consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .INCLUDE_FUNCTION ));
2281
- }
2250
+ PsiElement includeTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getPrintBlockOrTagFunctionPattern ("include" , "source" ));
2251
+ if (includeTag != null ) {
2252
+ String templateName = includeTag .getText ();
2253
+ if (StringUtils .isNotBlank (templateName )) {
2254
+ consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .INCLUDE_FUNCTION ));
2282
2255
}
2283
2256
}
2284
2257
2285
2258
// {% embed "foo.html.twig"
2286
- if (myTypes .contains (TemplateInclude .TYPE .EMBED )) {
2287
- PsiElement embedTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getEmbedPattern ());
2288
- if (embedTag != null ) {
2289
- String templateName = embedTag .getText ();
2290
- if (StringUtils .isNotBlank (templateName )) {
2291
- consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .EMBED ));
2292
- }
2259
+ PsiElement embedTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getEmbedPattern ());
2260
+ if (embedTag != null ) {
2261
+ String templateName = embedTag .getText ();
2262
+ if (StringUtils .isNotBlank (templateName )) {
2263
+ consumer .consume (new TemplateInclude (psiElement , templateName , TemplateInclude .TYPE .EMBED ));
2293
2264
}
2294
2265
}
2295
2266
2296
- if (myTypes . contains ( TemplateInclude . TYPE . FORM_THEME ) && psiElement .getNode ().getElementType () == TwigElementTypes .TAG ) {
2267
+ if (psiElement .getNode ().getElementType () == TwigElementTypes .TAG ) {
2297
2268
PsiElement tagElement = PsiElementUtils .getChildrenOfType (psiElement , PlatformPatterns .psiElement ().withElementType (TwigTokenTypes .TAG_NAME ));
2298
2269
if (tagElement != null ) {
2299
2270
String text = tagElement .getText ();
0 commit comments