3
3
import com .intellij .codeInsight .lookup .LookupElement ;
4
4
import com .intellij .codeInsight .lookup .LookupElementBuilder ;
5
5
import com .intellij .openapi .project .Project ;
6
+ import com .intellij .psi .PsiElement ;
6
7
import com .jetbrains .php .PhpIndex ;
7
8
import com .jetbrains .php .lang .psi .elements .PhpClass ;
8
9
import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
9
10
import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
10
11
import fr .adrienbrault .idea .symfony2plugin .util .completion .annotations .AnnotationMethodInsertHandler ;
11
12
import fr .adrienbrault .idea .symfony2plugin .util .completion .annotations .AnnotationTagInsertHandler ;
12
13
import org .jetbrains .annotations .NotNull ;
14
+ import org .jetbrains .annotations .Nullable ;
13
15
14
16
import java .util .*;
15
17
@@ -22,22 +24,62 @@ public class DoctrineStaticTypeLookupBuilder {
22
24
23
25
public static Collection <LookupElement > getTypes (@ NotNull Project project ) {
24
26
25
- Map <String , LookupElement > lookupElements = new HashMap <String , LookupElement >();
27
+ final Collection <LookupElement > lookupElements = new ArrayList <LookupElement >();
28
+
29
+ visitCustomTypes (project , new ColumnTypeVisitor () {
30
+ @ Override
31
+ public void visit (@ NotNull String name , @ Nullable PhpClass phpClass , @ Nullable PsiElement psiElement ) {
32
+ LookupElementBuilder lookupElementBuilder = LookupElementBuilder .create (name ).withIcon (Symfony2Icons .DOCTRINE );
33
+
34
+ if (phpClass != null ) {
35
+ lookupElementBuilder = lookupElementBuilder .withTypeText (phpClass .getName (), true );
36
+ }
37
+
38
+ lookupElements .add (lookupElementBuilder );
39
+ }
40
+ });
41
+
42
+ return lookupElements ;
43
+ }
44
+
45
+ public static void visitCustomTypes (@ NotNull Project project , @ NotNull ColumnTypeVisitor visitor ) {
46
+
47
+ Set <String > found = new HashSet <String >();
26
48
27
49
for (PhpClass phpClass : PhpIndex .getInstance (project ).getAllSubclasses ("\\ Doctrine\\ DBAL\\ Types\\ Type" )) {
28
- String getName = PhpElementsUtil .getMethodReturnAsString (phpClass , "getName" );
29
- if (getName != null ) {
30
- lookupElements .put (getName , LookupElementBuilder .create (getName ).withIcon (Symfony2Icons .DOCTRINE ).withTypeText (phpClass .getName (), true ));
50
+ String name = PhpElementsUtil .getMethodReturnAsString (phpClass , "getName" );
51
+ if (name != null ) {
52
+ found .add (name );
53
+ visitor .visit (name , phpClass , phpClass .findMethodByName ("getName" ));
31
54
}
32
55
}
33
56
34
57
for (String s : Arrays .asList ("id" , "string" , "integer" , "smallint" , "bigint" , "boolean" , "decimal" , "date" , "time" , "datetime" , "text" , "array" , "float" )) {
35
- if (!lookupElements . containsKey (s )) {
36
- lookupElements . put (s , LookupElementBuilder . create ( s ). withIcon ( Symfony2Icons . DOCTRINE ) );
58
+ if (!found . contains (s )) {
59
+ visitor . visit (s , null , null );
37
60
}
38
61
}
39
62
40
- return lookupElements .values ();
63
+ }
64
+
65
+ private interface ColumnTypeVisitor {
66
+ void visit (@ NotNull String name , @ Nullable PhpClass phpClass , @ Nullable PsiElement psiElement );
67
+ }
68
+
69
+ public static Collection <PsiElement > getColumnTypesTargets (@ NotNull Project project , final @ NotNull String contents ) {
70
+
71
+ final Collection <PsiElement > targets = new ArrayList <PsiElement >();
72
+
73
+ visitCustomTypes (project , new ColumnTypeVisitor () {
74
+ @ Override
75
+ public void visit (@ NotNull String name , @ Nullable PhpClass phpClass , @ Nullable PsiElement psiElement ) {
76
+ if (name .equals (contents ) && phpClass != null ) {
77
+ targets .add (phpClass );
78
+ }
79
+ }
80
+ });
81
+
82
+ return targets ;
41
83
}
42
84
43
85
public ArrayList <LookupElement > getNullAble () {
0 commit comments