9
9
import com .intellij .psi .xml .XmlAttributeValue ;
10
10
import com .intellij .psi .xml .XmlTag ;
11
11
import com .intellij .psi .xml .XmlToken ;
12
+ import com .intellij .util .containers .ContainerUtil ;
13
+ import com .jetbrains .php .completion .PhpLookupElement ;
14
+ import com .jetbrains .php .lang .psi .elements .PhpClass ;
12
15
import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
13
16
import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionProvider ;
14
17
import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionRegistrar ;
15
18
import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionRegistrarParameter ;
16
19
import fr .adrienbrault .idea .symfony2plugin .codeInsight .utils .GotoCompletionUtil ;
17
20
import fr .adrienbrault .idea .symfony2plugin .config .xml .XmlHelper ;
21
+ import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
18
22
import fr .adrienbrault .idea .symfony2plugin .util .dict .ServiceUtil ;
19
23
import fr .adrienbrault .idea .symfony2plugin .util .resource .FileResourceUtil ;
20
24
import org .apache .commons .lang .StringUtils ;
23
27
import java .util .ArrayList ;
24
28
import java .util .Collection ;
25
29
import java .util .Collections ;
30
+ import java .util .stream .Collectors ;
26
31
27
32
public class XmlGotoCompletionRegistrar implements GotoCompletionRegistrar {
28
33
@@ -39,11 +44,20 @@ public void register(GotoCompletionRegistrarParameter registrar) {
39
44
XmlPatterns .psiElement ().withParent (XmlHelper .getServiceIdNamePattern ()),
40
45
ServiceIdCompletionProvider ::new
41
46
);
47
+
48
+ // <factory class="AppBundle\Trivago\ConfigFactory" method="create"/>
49
+ // <factory service="foo" method="create"/>
50
+ registrar .register (
51
+ XmlPatterns .psiElement ().withParent (XmlHelper .getTagAttributePattern ("factory" , "method" )
52
+ .inside (XmlHelper .getInsideTagPattern ("services" ))
53
+ .inFile (XmlHelper .getXmlFilePattern ())),
54
+ ServiceFactoryMethodCompletionProvider ::new
55
+ );
42
56
}
43
57
44
58
private static class ImportResourceGotoCompletionProvider extends GotoCompletionProvider {
45
59
46
- public ImportResourceGotoCompletionProvider (PsiElement element ) {
60
+ ImportResourceGotoCompletionProvider (PsiElement element ) {
47
61
super (element );
48
62
}
49
63
@@ -114,4 +128,41 @@ public Collection<PsiElement> getPsiTargets(PsiElement element) {
114
128
return Collections .emptyList ();
115
129
}
116
130
}
131
+
132
+ private static class ServiceFactoryMethodCompletionProvider extends GotoCompletionProvider {
133
+ ServiceFactoryMethodCompletionProvider (PsiElement element ) {
134
+ super (element );
135
+ }
136
+
137
+ @ NotNull
138
+ @ Override
139
+ public Collection <LookupElement > getLookupElements () {
140
+ PsiElement parent = getElement ().getParent ();
141
+ if (!(parent instanceof XmlAttributeValue )) {
142
+ return Collections .emptyList ();
143
+ }
144
+
145
+ Collection <PhpClass > phpClasses = new ArrayList <>();
146
+
147
+ ContainerUtil .addIfNotNull (phpClasses , XmlHelper .getPhpClassForClassFactory ((XmlAttributeValue ) parent ));
148
+ ContainerUtil .addIfNotNull (phpClasses , XmlHelper .getPhpClassForServiceFactory ((XmlAttributeValue ) parent ));
149
+
150
+ Collection <LookupElement > lookupElements = new ArrayList <>();
151
+
152
+ for (PhpClass phpClass : phpClasses ) {
153
+ lookupElements .addAll (PhpElementsUtil .getClassPublicMethod (phpClass ).stream ()
154
+ .map (PhpLookupElement ::new )
155
+ .collect (Collectors .toList ())
156
+ );
157
+ }
158
+
159
+ return lookupElements ;
160
+ }
161
+
162
+ @ NotNull
163
+ @ Override
164
+ public Collection <PsiElement > getPsiTargets (PsiElement element ) {
165
+ return Collections .emptyList ();
166
+ }
167
+ }
117
168
}
0 commit comments