Skip to content

Commit

Permalink
#18 prevent access to index while service is dumb - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfilatov committed Jun 5, 2016
1 parent 48bad00 commit 76b4a2d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
7 changes: 0 additions & 7 deletions src/com/phpuaca/completion/BaseTypeProvider.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.phpuaca.completion;

import com.intellij.openapi.project.DumbService;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider2;
import com.phpuaca.util.PhpClassAdapter;
Expand All @@ -12,10 +9,6 @@

abstract public class BaseTypeProvider implements PhpTypeProvider2 {

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

@Nullable
protected PhpClassAdapter getPhpClassAdapterForMethod(@NotNull Method method) {
PhpClass phpClass = method.getContainingClass();
Expand Down
12 changes: 11 additions & 1 deletion src/com/phpuaca/completion/PHPUnitTypeProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.phpuaca.completion;

import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.PhpIndex;
Expand Down Expand Up @@ -40,7 +41,12 @@ public char getKey() {
@Nullable
@Override
public String getType(PsiElement psiElement) {
if (!isAvailable(psiElement)) {
Project project = psiElement.getProject();
if (DumbService.isDumb(project)) {
return null;
}

if (!(psiElement instanceof MethodReference)) {
return null;
}

Expand Down Expand Up @@ -68,6 +74,10 @@ public String getType(PsiElement psiElement) {

@Override
public Collection<? extends PhpNamedElement> getBySignature(String s, Project project) {
if (DumbService.isDumb(project)) {
return null;
}

PhpIndex phpIndex = PhpIndex.getInstance(project);
Collection<PhpClass> collection = new ArrayList<PhpClass>();
collection.addAll(phpIndex.getInterfacesByFQN(CLASS_PHP_UNIT_MOCK_OBJECT));
Expand Down
15 changes: 6 additions & 9 deletions src/com/phpuaca/completion/ProphecyTypeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.FieldReference;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.elements.Parameter;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
import com.jetbrains.php.lang.psi.elements.Variable;
import com.jetbrains.php.lang.psi.elements.*;
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
import com.phpuaca.util.PhpClassAdapter;
import com.phpuaca.util.PhpClassResolver;
Expand Down Expand Up @@ -46,8 +40,7 @@ public char getKey() {
@Override
public String getType(PsiElement psiElement) {
Project project = psiElement.getProject();

if (DumbService.getInstance(project).isDumb()) {
if (DumbService.isDumb(project)) {
return null;
}

Expand Down Expand Up @@ -96,6 +89,10 @@ public String getType(PsiElement psiElement) {

@Override
public Collection<? extends PhpNamedElement> getBySignature(String s, Project project) {
if (DumbService.isDumb(project)) {
return null;
}

PhpIndex phpIndex = PhpIndex.getInstance(project);
Collection<PhpClass> collection = new ArrayList<PhpClass>();
for (String FQN : s.split(TYPE_SEPARATOR)) {
Expand Down
3 changes: 2 additions & 1 deletion src/com/phpuaca/completion/StringCompletionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.codeInsight.completion.CompletionProvider;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.project.DumbService;
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.completion.PhpLookupElement;
Expand All @@ -22,7 +23,7 @@ public class StringCompletionProvider extends CompletionProvider<CompletionParam
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
PsiElement originalPosition = completionParameters.getOriginalPosition();
if (originalPosition != null) {
if (originalPosition != null && !DumbService.isDumb(originalPosition.getProject())) {
Filter filter = FilterFactory.getInstance().getFilter(originalPosition.getParent());
if (filter != null) {
completionResultSet.addAllElements(getLookupElements(filter));
Expand Down
5 changes: 5 additions & 0 deletions src/com/phpuaca/helper/AvailabilityHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.phpuaca.helper;

import com.intellij.openapi.project.DumbService;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression;
Expand All @@ -21,6 +22,10 @@ public boolean checkScope(@Nullable PsiElement psiElement) {
return false;
}

if (DumbService.isDumb(psiElement.getProject())) {
return false;
}

// $this->method('cursor');
PsiElement stringLiteralExpressionContext = psiElement.getContext();
if (stringLiteralExpressionContext instanceof ParameterList) {
Expand Down
5 changes: 5 additions & 0 deletions src/com/phpuaca/reference/StringReference.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.phpuaca.reference;

import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
Expand Down Expand Up @@ -35,6 +36,10 @@ public TextRange getRangeInElement() {
@Nullable
@Override
public PsiElement resolve() {
if (DumbService.isDumb(getElement().getProject())) {
return null;
}

PsiElement resolvedElement = null;
Filter filter = FilterFactory.getInstance().getFilter(getElement());
if (filter != null) {
Expand Down
17 changes: 7 additions & 10 deletions src/com/phpuaca/util/PhpClassResolver.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.phpuaca.util;

import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
Expand Down Expand Up @@ -32,15 +31,13 @@ public PhpClass resolveByClassConstantReference(@NotNull ClassConstantReference

@Nullable
public PhpClass resolveByClassStringLiteralExpression(@NotNull StringLiteralExpression stringLiteralExpression) {
Project project = stringLiteralExpression.getProject();
if (!DumbService.getInstance(project).isDumb()) {
String className = stringLiteralExpression.getContents();
if (!className.isEmpty()) {
className = className.replace("\\\\", "\\");
Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getAnyByFQN(className);
if (!phpClasses.isEmpty()) {
return phpClasses.iterator().next();
}
String className = stringLiteralExpression.getContents();
if (!className.isEmpty()) {
className = className.replace("\\\\", "\\");
Project project = stringLiteralExpression.getProject();
Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getAnyByFQN(className);
if (!phpClasses.isEmpty()) {
return phpClasses.iterator().next();
}
}

Expand Down

0 comments on commit 76b4a2d

Please sign in to comment.