3
3
import com .intellij .codeInspection .LocalInspectionTool ;
4
4
import com .intellij .codeInspection .ProblemHighlightType ;
5
5
import com .intellij .codeInspection .ProblemsHolder ;
6
- import com .intellij .lang .Language ;
7
- import com .intellij .lang .xml .XMLLanguage ;
6
+ import com .intellij .openapi .project .Project ;
8
7
import com .intellij .psi .PsiElement ;
9
8
import com .intellij .psi .PsiElementVisitor ;
10
9
import com .intellij .psi .xml .XmlText ;
10
+ import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
11
11
import fr .adrienbrault .idea .symfony2plugin .config .xml .XmlHelper ;
12
12
import fr .adrienbrault .idea .symfony2plugin .dic .container .util .ServiceContainerUtil ;
13
13
import org .apache .commons .lang3 .StringUtils ;
14
14
import org .jetbrains .annotations .NotNull ;
15
- import org .jetbrains .yaml .YAMLLanguage ;
16
15
import org .jetbrains .yaml .psi .YAMLScalar ;
17
16
18
17
/**
19
18
* @author Daniel Espendiller <daniel@espendiller.net>
20
19
*/
21
20
public class ContainerConstantInspection extends LocalInspectionTool {
22
-
23
21
public static final String MESSAGE = "Symfony: constant not found" ;
24
22
25
- @ NotNull
26
- public PsiElementVisitor buildVisitor (final @ NotNull ProblemsHolder holder , boolean isOnTheFly ) {
27
- return new PsiElementVisitor () {
28
- @ Override
29
- public void visitElement (@ NotNull PsiElement element ) {
30
- Language language = element .getLanguage ();
23
+ public static class MyYamlLocalInspectionTool extends LocalInspectionTool {
24
+ @ Override
25
+ public @ NotNull PsiElementVisitor buildVisitor (@ NotNull ProblemsHolder holder , boolean isOnTheFly ) {
26
+ Project project = holder .getProject ();
27
+ if (!Symfony2ProjectComponent .isEnabled (project )) {
28
+ return super .buildVisitor (holder , isOnTheFly );
29
+ }
31
30
32
- if (language == YAMLLanguage .INSTANCE ) {
31
+ return new PsiElementVisitor () {
32
+ @ Override
33
+ public void visitElement (@ NotNull PsiElement element ) {
33
34
if (element instanceof YAMLScalar yamlScalar ) {
34
35
visitYamlElement (yamlScalar , holder );
35
36
}
36
- } else if ( language == XMLLanguage . INSTANCE ) {
37
- visitXmlElement (element , holder );
37
+
38
+ super . visitElement (element );
38
39
}
40
+ };
41
+ }
42
+ }
39
43
40
- super .visitElement (element );
44
+ public static class MyXmlLocalInspectionTool extends LocalInspectionTool {
45
+ @ Override
46
+ public @ NotNull PsiElementVisitor buildVisitor (@ NotNull ProblemsHolder holder , boolean isOnTheFly ) {
47
+ Project project = holder .getProject ();
48
+ if (!Symfony2ProjectComponent .isEnabled (project )) {
49
+ return super .buildVisitor (holder , isOnTheFly );
41
50
}
42
- };
51
+
52
+ return new PsiElementVisitor () {
53
+ @ Override
54
+ public void visitElement (@ NotNull PsiElement element ) {
55
+ visitXmlElement (element , holder );
56
+ super .visitElement (element );
57
+ }
58
+ };
59
+ }
43
60
}
44
- private void visitYamlElement (@ NotNull YAMLScalar psiElement , @ NotNull ProblemsHolder holder ) {
61
+
62
+ private static void visitYamlElement (@ NotNull YAMLScalar psiElement , @ NotNull ProblemsHolder holder ) {
45
63
String textValue = psiElement .getTextValue ();
46
64
if (textValue .startsWith ("!php/const:" )) {
47
65
String constantName = textValue .substring (11 );
@@ -51,7 +69,7 @@ private void visitYamlElement(@NotNull YAMLScalar psiElement, @NotNull ProblemsH
51
69
}
52
70
}
53
71
54
- private void visitXmlElement (@ NotNull PsiElement psiElement , @ NotNull ProblemsHolder holder ) {
72
+ private static void visitXmlElement (@ NotNull PsiElement psiElement , @ NotNull ProblemsHolder holder ) {
55
73
if (!XmlHelper .getArgumentValueWithTypePattern ("constant" ).accepts (psiElement )) {
56
74
return ;
57
75
}
0 commit comments