5
5
import com .intellij .lang .injection .MultiHostRegistrar ;
6
6
import com .intellij .psi .PsiElement ;
7
7
import com .intellij .psi .PsiLanguageInjectionHost ;
8
+ import com .jetbrains .php .lang .documentation .phpdoc .psi .tags .PhpDocTag ;
8
9
import com .jetbrains .php .lang .psi .elements .*;
9
10
import com .jetbrains .php .lang .psi .elements .impl .ParameterListImpl ;
10
11
import com .jetbrains .php .lang .psi .elements .impl .StringLiteralExpressionImpl ;
12
+ import de .espend .idea .php .annotation .util .AnnotationUtil ;
11
13
import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
12
14
import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
13
15
import org .jetbrains .annotations .NotNull ;
@@ -61,7 +63,13 @@ public class ParameterLanguageInjector implements MultiHostInjector {
61
63
new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Entity" , "expr" , 1 ),
62
64
new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ ParamConverter" , "expr" , 1 ),
63
65
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" ),
65
73
};
66
74
67
75
public static final String LANGUAGE_ID_CSS = "CSS" ;
@@ -86,35 +94,24 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
86
94
if (!(element instanceof StringLiteralExpression ) || !((PsiLanguageInjectionHost ) element ).isValidHost ()) {
87
95
return ;
88
96
}
97
+
89
98
if (!Symfony2ProjectComponent .isEnabled (element .getProject ())) {
90
99
return ;
91
100
}
92
101
93
102
final StringLiteralExpressionImpl expr = (StringLiteralExpressionImpl ) element ;
94
103
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
-
108
104
for (LanguageInjection languageInjection : LANGUAGE_INJECTIONS ) {
109
105
if (languageInjection .accepts (expr )) {
110
106
injectLanguage (registrar , expr , languageInjection );
111
107
return ;
112
108
}
113
109
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 ();
116
113
if (language != null && LANGUAGE_ID_DQL .equals (language .getID ())) {
117
- PhpPsiElement variable = ((AssignmentExpression ) parent ).getVariable ();
114
+ var variable = ((AssignmentExpression ) parent ).getVariable ();
118
115
if (variable instanceof Variable ) {
119
116
if (DQL_VARIABLE_NAME .equals (variable .getName ())) {
120
117
injectLanguage (registrar , expr , languageInjection );
@@ -404,6 +401,39 @@ public boolean accepts(@NotNull StringLiteralExpression element) {
404
401
}
405
402
}
406
403
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
+
407
437
private static class NewExpressionLanguageInjection extends LanguageInjection {
408
438
@ NotNull
409
439
private final String classFQN ;
0 commit comments