@@ -2216,84 +2216,55 @@ public static Map<VirtualFile, Collection<String>> getBlockNamesForFiles(@NotNul
22162216 * Visit all possible Twig include file pattern
22172217 */
22182218 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-
22382219 PsiTreeUtil .collectElements (twigFile , psiElement -> {
22392220 if (psiElement instanceof TwigTagWithFileReference ) {
22402221 // {% 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 ));
22472226 }
22482227 }
22492228 }
22502229
22512230 // {% 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 ));
22592236 }
22602237 }
22612238
22622239 // {% 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 ));
22702245 }
22712246 }
22722247 } else if (psiElement instanceof TwigCompositeElement ) {
22732248 // {{ include() }}
22742249 // {{ 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 ));
22822255 }
22832256 }
22842257
22852258 // {% 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 ));
22932264 }
22942265 }
22952266
2296- if (myTypes . contains ( TemplateInclude . TYPE . FORM_THEME ) && psiElement .getNode ().getElementType () == TwigElementTypes .TAG ) {
2267+ if (psiElement .getNode ().getElementType () == TwigElementTypes .TAG ) {
22972268 PsiElement tagElement = PsiElementUtils .getChildrenOfType (psiElement , PlatformPatterns .psiElement ().withElementType (TwigTokenTypes .TAG_NAME ));
22982269 if (tagElement != null ) {
22992270 String text = tagElement .getText ();
0 commit comments