4
4
import com .intellij .openapi .project .Project ;
5
5
import com .intellij .psi .PsiElement ;
6
6
import com .intellij .psi .PsiElementVisitor ;
7
- import com .intellij .psi .PsiFile ;
8
7
import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
9
8
import fr .adrienbrault .idea .symfony2plugin .action .ServiceActionUtil ;
10
9
import fr .adrienbrault .idea .symfony2plugin .stubs .ContainerCollectionResolver ;
11
10
import fr .adrienbrault .idea .symfony2plugin .util .yaml .YamlHelper ;
12
11
import org .jetbrains .annotations .NotNull ;
13
- import org .jetbrains .yaml .psi .YAMLFile ;
14
12
import org .jetbrains .yaml .psi .YAMLKeyValue ;
15
13
import org .jetbrains .yaml .psi .YAMLMapping ;
16
14
@@ -49,30 +47,30 @@ private static class MyPsiElementVisitor extends PsiElementVisitor {
49
47
}
50
48
51
49
@ Override
52
- public void visitFile (PsiFile file ) {
53
- if (!(file instanceof YAMLFile )) {
54
- return ;
55
- }
56
-
57
- for (ServiceActionUtil .ServiceYamlContainer serviceYamlContainer : ServiceActionUtil .getYamlContainerServiceArguments ((YAMLFile ) file )) {
58
-
59
- // we dont support parent services for now
60
- if ("_defaults" .equalsIgnoreCase (serviceYamlContainer .getServiceKey ().getKeyText ()) || !isValidService (serviceYamlContainer )) {
61
- continue ;
62
- }
63
-
64
- List <String > yamlMissingArgumentTypes = ServiceActionUtil .getYamlMissingArgumentTypes (problemsHolder .getProject (), serviceYamlContainer , false , getLazyServiceCollector (problemsHolder .getProject ()));
65
- if (yamlMissingArgumentTypes .size () > 0 ) {
66
- problemsHolder .registerProblem (serviceYamlContainer .getServiceKey ().getFirstChild (), "Missing argument" , ProblemHighlightType .GENERIC_ERROR_OR_WARNING , new YamlArgumentQuickfix ());
50
+ public void visitElement (@ NotNull PsiElement element ) {
51
+ if (element instanceof YAMLKeyValue yamlKeyValue && yamlKeyValue .getParent () instanceof YAMLMapping yamlMapping && yamlMapping .getParent () instanceof YAMLKeyValue yamlKeyValue1 && "services" .equals (yamlKeyValue1 .getKeyText ())) {
52
+ // we don't support parent services for now
53
+ if (!"_defaults" .equalsIgnoreCase (yamlKeyValue .getKeyText ()) && isValidService (yamlKeyValue )) {
54
+ ServiceActionUtil .ServiceYamlContainer container = ServiceActionUtil .ServiceYamlContainer .create (yamlKeyValue );
55
+ if (container != null ) {
56
+ List <String > yamlMissingArgumentTypes = ServiceActionUtil .getYamlMissingArgumentTypes (
57
+ problemsHolder .getProject (),
58
+ container ,
59
+ false ,
60
+ getLazyServiceCollector (problemsHolder .getProject ())
61
+ );
62
+
63
+ if (yamlMissingArgumentTypes .size () > 0 ) {
64
+ problemsHolder .registerProblem (yamlKeyValue .getFirstChild (), "Missing argument" , ProblemHighlightType .GENERIC_ERROR_OR_WARNING , new YamlArgumentQuickfix ());
65
+ }
66
+ }
67
67
}
68
68
}
69
69
70
- this . lazyServiceCollector = null ;
70
+ super . visitElement ( element ) ;
71
71
}
72
72
73
- private boolean isValidService (ServiceActionUtil .ServiceYamlContainer serviceYamlContainer ) {
74
- YAMLKeyValue serviceKey = serviceYamlContainer .getServiceKey ();
75
-
73
+ private boolean isValidService (@ NotNull YAMLKeyValue serviceKey ) {
76
74
Set <String > keySet = YamlHelper .getKeySet (serviceKey );
77
75
if (keySet == null ) {
78
76
return true ;
@@ -88,9 +86,7 @@ private boolean isValidService(ServiceActionUtil.ServiceYamlContainer serviceYam
88
86
Boolean serviceAutowire = YamlHelper .getYamlKeyValueAsBoolean (serviceKey , "autowire" );
89
87
if (serviceAutowire != null ) {
90
88
// use service scope for autowire
91
- if (serviceAutowire ) {
92
- return false ;
93
- }
89
+ return !serviceAutowire ;
94
90
} else {
95
91
// find file scope defaults
96
92
// defaults: [autowire: true]
@@ -99,9 +95,7 @@ private boolean isValidService(ServiceActionUtil.ServiceYamlContainer serviceYam
99
95
YAMLKeyValue defaults = YamlHelper .getYamlKeyValue (key , "_defaults" );
100
96
if (defaults != null ) {
101
97
Boolean autowire = YamlHelper .getYamlKeyValueAsBoolean (defaults , "autowire" );
102
- if (autowire != null && autowire ) {
103
- return false ;
104
- }
98
+ return autowire == null || !autowire ;
105
99
}
106
100
}
107
101
}
0 commit comments