Skip to content

Commit ea7162b

Browse files
committed
#8: type providers - support for interfaces and traits
1 parent eef6044 commit ea7162b

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

src/com/phpuaca/completion/BaseTypeProvider.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.phpuaca.completion;
22

33
import com.intellij.openapi.project.DumbService;
4-
import com.intellij.openapi.project.Project;
54
import com.intellij.psi.PsiElement;
6-
import com.jetbrains.php.PhpIndex;
75
import com.jetbrains.php.lang.psi.elements.Method;
86
import com.jetbrains.php.lang.psi.elements.MethodReference;
97
import com.jetbrains.php.lang.psi.elements.PhpClass;
@@ -12,23 +10,12 @@
1210
import org.jetbrains.annotations.NotNull;
1311
import org.jetbrains.annotations.Nullable;
1412

15-
import java.util.Collection;
16-
1713
abstract public class BaseTypeProvider implements PhpTypeProvider2 {
1814

1915
protected boolean isAvailable(@NotNull PsiElement psiElement) {
2016
return (psiElement instanceof MethodReference) && !DumbService.getInstance(psiElement.getProject()).isDumb();
2117
}
2218

23-
protected Collection<PhpClass> getPhpInterfaceCollection(@NotNull Project project, String FQN) {
24-
return PhpIndex.getInstance(project).getInterfacesByFQN(FQN);
25-
}
26-
27-
@NotNull
28-
protected Collection<PhpClass> getPhpClassCollection(@NotNull Project project, String FQN) {
29-
return PhpIndex.getInstance(project).getClassesByFQN(FQN);
30-
}
31-
3219
@Nullable
3320
protected PhpClassAdapter getPhpClassAdapterForMethod(@NotNull Method method) {
3421
PhpClass phpClass = method.getContainingClass();

src/com/phpuaca/completion/PHPUnitTypeProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.openapi.project.Project;
44
import com.intellij.psi.PsiElement;
5+
import com.jetbrains.php.PhpIndex;
56
import com.jetbrains.php.lang.psi.elements.Method;
67
import com.jetbrains.php.lang.psi.elements.MethodReference;
78
import com.jetbrains.php.lang.psi.elements.PhpClass;
@@ -67,9 +68,10 @@ public String getType(PsiElement psiElement) {
6768

6869
@Override
6970
public Collection<? extends PhpNamedElement> getBySignature(String s, Project project) {
71+
PhpIndex phpIndex = PhpIndex.getInstance(project);
7072
Collection<PhpClass> collection = new ArrayList<PhpClass>();
71-
collection.addAll(getPhpInterfaceCollection(project, CLASS_PHP_UNIT_MOCK_OBJECT));
72-
collection.addAll(getPhpClassCollection(project, s));
73+
collection.addAll(phpIndex.getInterfacesByFQN(CLASS_PHP_UNIT_MOCK_OBJECT));
74+
collection.addAll(phpIndex.getAnyByFQN(s));
7375
return collection;
7476
}
7577

src/com/phpuaca/completion/ProphecyTypeProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.openapi.project.Project;
44
import com.intellij.psi.PsiElement;
5+
import com.jetbrains.php.PhpIndex;
56
import com.jetbrains.php.lang.psi.elements.*;
67
import com.phpuaca.util.PhpClassAdapter;
78
import com.phpuaca.util.PhpClassResolver;
@@ -66,9 +67,10 @@ public String getType(PsiElement psiElement) {
6667

6768
@Override
6869
public Collection<? extends PhpNamedElement> getBySignature(String s, Project project) {
70+
PhpIndex phpIndex = PhpIndex.getInstance(project);
6971
Collection<PhpClass> collection = new ArrayList<PhpClass>();
7072
for (String FQN : s.split(TYPE_SEPARATOR)) {
71-
collection.addAll(getPhpClassCollection(project, FQN));
73+
collection.addAll(phpIndex.getAnyByFQN(FQN));
7274
}
7375
return collection;
7476
}

src/com/phpuaca/util/PhpClassResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public PhpClass resolveByClassStringLiteralExpression(@NotNull StringLiteralExpr
3333
if (!className.isEmpty()) {
3434
className = className.replace("\\\\", "\\");
3535
Project project = stringLiteralExpression.getProject();
36-
Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getClassesByFQN(className);
36+
Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getAnyByFQN(className);
3737
if (!phpClasses.isEmpty()) {
3838
return phpClasses.iterator().next();
3939
}

0 commit comments

Comments
 (0)