55import com .intellij .lang .injection .MultiHostRegistrar ;
66import com .intellij .psi .PsiElement ;
77import com .intellij .psi .PsiLanguageInjectionHost ;
8+ import com .jetbrains .php .lang .documentation .phpdoc .psi .tags .PhpDocTag ;
89import com .jetbrains .php .lang .psi .elements .*;
910import com .jetbrains .php .lang .psi .elements .impl .ParameterListImpl ;
1011import com .jetbrains .php .lang .psi .elements .impl .StringLiteralExpressionImpl ;
12+ import de .espend .idea .php .annotation .util .AnnotationUtil ;
1113import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
1214import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
1315import org .jetbrains .annotations .NotNull ;
@@ -61,7 +63,13 @@ public class ParameterLanguageInjector implements MultiHostInjector {
6163 new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Entity" , "expr" , 1 ),
6264 new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ ParamConverter" , "expr" , 1 ),
6365 new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Route" , "condition" , 9 ),
64- new FunctionCallArgumentLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ DependencyInjection\\ Loader\\ Configurator\\ expr" , "expression" , 0 )
66+ new FunctionCallArgumentLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ DependencyInjection\\ Loader\\ Configurator\\ expr" , "expression" , 0 ),
67+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ Routing\\ Annotation\\ Route" , "condition" ),
68+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Security" , "expression" ),
69+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Cache" , "lastModified" ),
70+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Cache" , "Etag" ),
71+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Entity" , "expr" ),
72+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ ParamConverter" , "expr" ),
6573 };
6674
6775 public static final String LANGUAGE_ID_CSS = "CSS" ;
@@ -86,35 +94,24 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
8694 if (!(element instanceof StringLiteralExpression ) || !((PsiLanguageInjectionHost ) element ).isValidHost ()) {
8795 return ;
8896 }
97+
8998 if (!Symfony2ProjectComponent .isEnabled (element .getProject ())) {
9099 return ;
91100 }
92101
93102 final StringLiteralExpressionImpl expr = (StringLiteralExpressionImpl ) element ;
94103
95- PsiElement parent = expr .getParent ();
96-
97- final boolean isParameter = parent instanceof ParameterList /* && expr.getPrevPsiSibling() == null */ ; // 1st parameter
98- final boolean isAssignment = parent instanceof AssignmentExpression ;
99-
100- if (!isParameter && !isAssignment ) {
101- return ;
102- }
103-
104- if (isParameter ) {
105- parent = parent .getParent ();
106- }
107-
108104 for (LanguageInjection languageInjection : LANGUAGE_INJECTIONS ) {
109105 if (languageInjection .accepts (expr )) {
110106 injectLanguage (registrar , expr , languageInjection );
111107 return ;
112108 }
113109
114- if (parent instanceof AssignmentExpression ) {
115- Language language = languageInjection .getLanguage ();
110+ if (expr .getParent () instanceof AssignmentExpression ) {
111+ var parent = expr .getParent ();
112+ var language = languageInjection .getLanguage ();
116113 if (language != null && LANGUAGE_ID_DQL .equals (language .getID ())) {
117- PhpPsiElement variable = ((AssignmentExpression ) parent ).getVariable ();
114+ var variable = ((AssignmentExpression ) parent ).getVariable ();
118115 if (variable instanceof Variable ) {
119116 if (DQL_VARIABLE_NAME .equals (variable .getName ())) {
120117 injectLanguage (registrar , expr , languageInjection );
@@ -404,6 +401,39 @@ public boolean accepts(@NotNull StringLiteralExpression element) {
404401 }
405402 }
406403
404+ public static class AnnotationLanguageInjection extends LanguageInjection {
405+ @ NotNull
406+ private final String classFQN ;
407+ @ NotNull
408+ private final String propertyName ;
409+
410+ public AnnotationLanguageInjection (@ NotNull String languageId , @ NotNull String classFQN , @ NotNull String propertyName ) {
411+ this (languageId , null , null , classFQN , propertyName );
412+ }
413+
414+ public AnnotationLanguageInjection (@ NotNull String languageId , @ Nullable String prefix , @ Nullable String suffix , @ NotNull String classFQN , @ NotNull String propertyName ) {
415+ super (languageId , prefix , suffix );
416+ this .classFQN = classFQN ;
417+ this .propertyName = propertyName ;
418+ }
419+
420+ @ Override
421+ public boolean accepts (@ NotNull StringLiteralExpression element ) {
422+ if (element .getParent () == null || !(element .getParent ().getParent () instanceof PhpDocTag )) {
423+ return false ;
424+ }
425+
426+ var phpDocTag = (PhpDocTag ) element .getParent ().getParent ();
427+
428+ var annotationClass = AnnotationUtil .getAnnotationReference (phpDocTag );
429+ if (annotationClass != null && annotationClass .getFQN ().equals (classFQN )) {
430+ return element .equals (AnnotationUtil .getPropertyValueAsPsiElement (phpDocTag , propertyName ));
431+ }
432+
433+ return false ;
434+ }
435+ }
436+
407437 private static class NewExpressionLanguageInjection extends LanguageInjection {
408438 @ NotNull
409439 private final String classFQN ;
0 commit comments