6
6
import com .intellij .patterns .PlatformPatterns ;
7
7
import com .intellij .psi .PsiElement ;
8
8
import com .jetbrains .php .lang .PhpLanguage ;
9
- import com .jetbrains .php .lang .lexer .PhpTokenTypes ;
9
+ import com .jetbrains .php .lang .psi .PhpFile ;
10
+ import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
10
11
import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
11
12
import fr .adrienbrault .idea .symfony2plugin .TwigHelper ;
12
13
import fr .adrienbrault .idea .symfony2plugin .util .PsiElementUtils ;
14
+ import org .apache .commons .lang .StringUtils ;
13
15
import org .jetbrains .annotations .Nullable ;
14
16
15
17
/**
@@ -21,27 +23,35 @@ public class PhpTemplateGlobalStringGoToDeclarationHandler implements GotoDeclar
21
23
@ Override
22
24
public PsiElement [] getGotoDeclarationTargets (PsiElement psiElement , int i , Editor editor ) {
23
25
26
+ if (!(psiElement .getContainingFile () instanceof PhpFile ) || !(psiElement .getContext () instanceof StringLiteralExpression )) {
27
+ return new PsiElement [0 ];
28
+ }
29
+
24
30
if (!Symfony2ProjectComponent .isEnabled (psiElement ) || !PlatformPatterns .or (
25
31
PlatformPatterns
26
- .psiElement (PhpTokenTypes . STRING_LITERAL )
32
+ .psiElement (StringLiteralExpression . class )
27
33
.withText (PlatformPatterns .or (
28
34
PlatformPatterns .string ().endsWith ("twig'" ),
29
35
PlatformPatterns .string ().endsWith ("twig\" " )
30
36
))
31
37
.withLanguage (PhpLanguage .INSTANCE ),
32
38
PlatformPatterns
33
- .psiElement (PhpTokenTypes . STRING_LITERAL_SINGLE_QUOTE )
39
+ .psiElement (StringLiteralExpression . class )
34
40
.withText (PlatformPatterns .or (
35
41
PlatformPatterns .string ().endsWith ("twig'" ),
36
42
PlatformPatterns .string ().endsWith ("twig\" " )
37
43
))
38
44
.withLanguage (PhpLanguage .INSTANCE )
39
- ).accepts (psiElement )) {
45
+ ).accepts (psiElement . getContext () )) {
40
46
41
47
return new PsiElement [0 ];
42
48
}
43
49
44
50
String templateName = PsiElementUtils .getText (psiElement );
51
+ if (StringUtils .isBlank (templateName )) {
52
+ return new PsiElement [0 ];
53
+ }
54
+
45
55
return TwigHelper .getTemplatePsiElements (psiElement .getProject (), templateName );
46
56
}
47
57
0 commit comments