3
3
import com .intellij .lang .Language ;
4
4
import com .intellij .lang .injection .MultiHostInjector ;
5
5
import com .intellij .lang .injection .MultiHostRegistrar ;
6
+ import com .intellij .patterns .PlatformPatterns ;
6
7
import com .intellij .psi .PsiElement ;
7
8
import com .intellij .psi .PsiLanguageInjectionHost ;
9
+ import com .intellij .psi .PsiWhiteSpace ;
10
+ import com .jetbrains .php .lang .documentation .phpdoc .lexer .PhpDocTokenTypes ;
11
+ import com .jetbrains .php .lang .documentation .phpdoc .parser .PhpDocElementTypes ;
8
12
import com .jetbrains .php .lang .documentation .phpdoc .psi .tags .PhpDocTag ;
9
13
import com .jetbrains .php .lang .psi .elements .*;
10
14
import com .jetbrains .php .lang .psi .elements .impl .ParameterListImpl ;
@@ -53,7 +57,7 @@ public class ParameterLanguageInjector implements MultiHostInjector {
53
57
new MethodCallArgumentLanguageInjection (LANGUAGE_ID_XPATH , XPATH_SIGNATURES ),
54
58
new MethodCallArgumentLanguageInjection (LANGUAGE_ID_JSON , JSON_SIGNATURES ),
55
59
new MethodCallArgumentLanguageInjection (LANGUAGE_ID_DQL , DQL_SIGNATURES ),
56
- new MethodCallArgumentLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , EXPRESSION_LANGUAGE_SIGNATURES ),
60
+ new MethodCallArgumentLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , EXPRESSION_LANGUAGE_SIGNATURES ),
57
61
new NewExpressionLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ ExpressionLanguage\\ Expression" , "expression" , 0 ),
58
62
new FunctionCallArgumentLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ DependencyInjection\\ Loader\\ Configurator\\ expr" , "expression" , 0 ),
59
63
new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ Validator\\ Constraints\\ Expression" , "expression" , 0 ),
@@ -64,12 +68,13 @@ public class ParameterLanguageInjector implements MultiHostInjector {
64
68
new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Entity" , "expr" , 1 ),
65
69
new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ ParamConverter" , "expr" , 1 ),
66
70
new AttributeLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Route" , "condition" , 9 ),
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" ),
71
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ Validator\\ Constraints\\ Expression" , "expression" , true ),
72
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Symfony\\ Component\\ Routing\\ Annotation\\ Route" , "condition" , false ),
73
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Security" , "expression" , true ),
74
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Cache" , "lastModified" , false ),
75
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Cache" , "Etag" , false ),
76
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ Entity" , "expr" , false ),
77
+ new AnnotationLanguageInjection (LANGUAGE_ID_EXPRESSION_LANGUAGE , "\\ Sensio\\ Bundle\\ FrameworkExtraBundle\\ Configuration\\ ParamConverter" , "expr" , false ),
73
78
};
74
79
75
80
public static final String LANGUAGE_ID_CSS = "CSS" ;
@@ -406,15 +411,17 @@ public static class AnnotationLanguageInjection extends LanguageInjection {
406
411
private final String classFQN ;
407
412
@ NotNull
408
413
private final String propertyName ;
414
+ private final boolean isDefaultProperty ;
409
415
410
- public AnnotationLanguageInjection (@ NotNull String languageId , @ NotNull String classFQN , @ NotNull String propertyName ) {
411
- this (languageId , null , null , classFQN , propertyName );
416
+ public AnnotationLanguageInjection (@ NotNull String languageId , @ NotNull String classFQN , @ NotNull String propertyName , boolean defaultProperty ) {
417
+ this (languageId , null , null , classFQN , propertyName , defaultProperty );
412
418
}
413
419
414
- public AnnotationLanguageInjection (@ NotNull String languageId , @ Nullable String prefix , @ Nullable String suffix , @ NotNull String classFQN , @ NotNull String propertyName ) {
420
+ public AnnotationLanguageInjection (@ NotNull String languageId , @ Nullable String prefix , @ Nullable String suffix , @ NotNull String classFQN , @ NotNull String propertyName , boolean defaultProperty ) {
415
421
super (languageId , prefix , suffix );
416
422
this .classFQN = classFQN ;
417
423
this .propertyName = propertyName ;
424
+ this .isDefaultProperty = defaultProperty ;
418
425
}
419
426
420
427
@ Override
@@ -427,11 +434,40 @@ public boolean accepts(@NotNull StringLiteralExpression element) {
427
434
428
435
var annotationClass = AnnotationUtil .getAnnotationReference (phpDocTag );
429
436
if (annotationClass != null && annotationClass .getFQN ().equals (classFQN )) {
430
- return element .equals (AnnotationUtil . getPropertyValueAsPsiElement (phpDocTag , propertyName ));
437
+ return element .equals (getPropertyValuePsiElement (phpDocTag ));
431
438
}
432
439
433
440
return false ;
434
441
}
442
+
443
+ @ Nullable
444
+ private PsiElement getPropertyValuePsiElement (@ NotNull PhpDocTag phpDocTag ) {
445
+ PsiElement property = AnnotationUtil .getPropertyValueAsPsiElement (phpDocTag , propertyName );
446
+
447
+ if (property == null && isDefaultProperty ) {
448
+ var phpDocAttrList = phpDocTag .getFirstPsiChild ();
449
+ if (phpDocAttrList != null && phpDocAttrList .getNode ().getElementType () == PhpDocElementTypes .phpDocAttributeList ) {
450
+ PhpPsiElement firstPhpPsiElement = phpDocAttrList .getFirstPsiChild ();
451
+ if (firstPhpPsiElement instanceof StringLiteralExpression && !hasIdentifier (firstPhpPsiElement )) {
452
+ property = firstPhpPsiElement ;
453
+ }
454
+ }
455
+ }
456
+
457
+ return property ;
458
+ }
459
+
460
+ private boolean hasIdentifier (@ NotNull PsiElement property ) {
461
+ return PlatformPatterns .psiElement ()
462
+ .afterLeafSkipping (
463
+ PlatformPatterns .or (
464
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
465
+ PlatformPatterns .psiElement (PhpDocTokenTypes .DOC_TEXT ).withText ("=" )
466
+ ),
467
+ PlatformPatterns .psiElement (PhpDocTokenTypes .DOC_IDENTIFIER )
468
+ )
469
+ .accepts (property );
470
+ }
435
471
}
436
472
437
473
private static class NewExpressionLanguageInjection extends LanguageInjection {
0 commit comments