33import com .intellij .lang .Language ;
44import com .intellij .lang .injection .MultiHostInjector ;
55import com .intellij .lang .injection .MultiHostRegistrar ;
6- import com .intellij .openapi .util .TextRange ;
76import com .intellij .psi .PsiElement ;
87import com .intellij .psi .PsiLanguageInjectionHost ;
98import com .jetbrains .php .lang .psi .elements .*;
1211import fr .adrienbrault .idea .symfony2plugin .util .MethodMatcher ;
1312import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
1413import org .jetbrains .annotations .NotNull ;
14+ import org .jetbrains .annotations .Nullable ;
1515
1616import java .util .Collections ;
1717import java .util .List ;
@@ -41,10 +41,10 @@ public class ParameterLanguageInjector implements MultiHostInjector {
4141 };
4242
4343 private final MethodLanguageInjection [] LANGUAGE_INJECTIONS = {
44- new MethodLanguageInjection (LANGUAGE_ID_CSS , "@media all { " , " }" , CSS_SELECTOR_SIGNATURES ),
45- new MethodLanguageInjection (LANGUAGE_ID_XPATH , null , null , XPATH_SIGNATURES ),
46- new MethodLanguageInjection (LANGUAGE_ID_JSON , null , null , JSON_SIGNATURES ),
47- new MethodLanguageInjection (LANGUAGE_ID_DQL , null , null , DQL_SIGNATURES ),
44+ new MethodLanguageInjection (LANGUAGE_ID_CSS , "@media all { " , " }" , CSS_SELECTOR_SIGNATURES ),
45+ new MethodLanguageInjection (LANGUAGE_ID_XPATH , null , null , XPATH_SIGNATURES ),
46+ new MethodLanguageInjection (LANGUAGE_ID_JSON , null , null , JSON_SIGNATURES ),
47+ new MethodLanguageInjection (LANGUAGE_ID_DQL , null , null , DQL_SIGNATURES ),
4848 };
4949
5050 public static final String LANGUAGE_ID_CSS = "CSS" ;
@@ -88,26 +88,23 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
8888 }
8989
9090 for (MethodLanguageInjection languageInjection : LANGUAGE_INJECTIONS ) {
91- Language language = languageInjection .getLanguage ();
92- if (language == null ) {
93- continue ;
94- }
9591 // $crawler->filter('...')
9692 // $em->createQuery('...')
9793 // JsonResponse::fromJsonString('...')
9894 if (parent instanceof MethodReference ) {
9995 if (PhpElementsUtil .isMethodReferenceInstanceOf ((MethodReference ) parent , languageInjection .getSignatures ())) {
100- injectLanguage (registrar , expr , language , languageInjection );
96+ injectLanguage (registrar , expr , languageInjection );
10197 return ;
10298 }
10399 }
104100 // $dql = "...";
105101 else if (parent instanceof AssignmentExpression ) {
106- if (LANGUAGE_ID_DQL .equals (language .getID ())) {
102+ Language language = languageInjection .getLanguage ();
103+ if (language != null && LANGUAGE_ID_DQL .equals (language .getID ())) {
107104 PhpPsiElement variable = ((AssignmentExpression ) parent ).getVariable ();
108105 if (variable instanceof Variable ) {
109106 if (DQL_VARIABLE_NAME .equals (variable .getName ())) {
110- injectLanguage (registrar , expr , language , languageInjection );
107+ injectLanguage (registrar , expr , languageInjection );
111108 return ;
112109 }
113110 }
@@ -117,28 +114,33 @@ else if (parent instanceof AssignmentExpression) {
117114
118115 }
119116
120- private void injectLanguage (@ NotNull MultiHostRegistrar registrar , @ NotNull StringLiteralExpressionImpl element , Language language , MethodLanguageInjection languageInjection ) {
117+ private void injectLanguage (@ NotNull MultiHostRegistrar registrar , @ NotNull StringLiteralExpressionImpl element , MethodLanguageInjection languageInjection ) {
118+ Language language = languageInjection .getLanguage ();
119+ if (language == null ) {
120+ return ;
121+ }
122+
121123 registrar .startInjecting (language )
122- .addPlace (languageInjection .getPrefix (), languageInjection .getSuffix (), element , element .getValueRange ())
123- .doneInjecting ();
124+ .addPlace (languageInjection .getPrefix (), languageInjection .getSuffix (), element , element .getValueRange ())
125+ .doneInjecting ();
124126 }
125127
126- private class MethodLanguageInjection {
127- private final Language language ;
128+ private static class MethodLanguageInjection {
129+ private final String language ;
128130 private final String prefix ;
129131 private final String suffix ;
130132 private final MethodMatcher .CallToSignature [] signatures ;
131133
132- MethodLanguageInjection (@ NotNull String languageId , String prefix , String suffix , MethodMatcher .CallToSignature [] signatures ) {
133-
134- this .language = Language .findLanguageByID (languageId );
134+ MethodLanguageInjection (String languageId , String prefix , String suffix , MethodMatcher .CallToSignature [] signatures ) {
135+ this .language = languageId ;
135136 this .prefix = prefix ;
136137 this .suffix = suffix ;
137138 this .signatures = signatures ;
138139 }
139140
141+ @ Nullable
140142 public Language getLanguage () {
141- return language ;
143+ return Language . findLanguageByID ( this . language ) ;
142144 }
143145
144146 public String getPrefix () {
0 commit comments