PY-18328 Fixed: CTRL+ALT+B on method leads to excpetion
authorSemyon Proshev <Semyon.Proshev@jetbrains.com>
Mon, 29 Feb 2016 12:32:32 +0000 (15:32 +0300)
committerSemyon Proshev <Semyon.Proshev@jetbrains.com>
Mon, 14 Mar 2016 11:09:50 +0000 (14:09 +0300)
Run search of function and target definitions in Application.runReadAction

python/src/com/jetbrains/python/psi/search/PyDefinitionsSearch.java
python/src/com/jetbrains/python/psi/search/PyOverridingMethodsSearchExecutor.java

index 662e669326aecbf85f1e19d2ad28c80eba66be38..78999419ff807b4eaceaca08b7bade351033443d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
  */
 package com.jetbrains.python.psi.search;
 
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
 import com.intellij.psi.PsiElement;
 import com.intellij.util.Processor;
 import com.intellij.util.Query;
@@ -39,17 +41,35 @@ public class PyDefinitionsSearch implements QueryExecutor<PsiElement, PsiElement
       });
     }
     else if (queryParameters instanceof PyFunction) {
-      final Query<PyFunction> query = PyOverridingMethodsSearch.search((PyFunction) queryParameters, true);
-      return query.forEach(new Processor<PyFunction>() {
-        public boolean process(final PyFunction pyFunction) {
-          return consumer.process(pyFunction);
+      final Query<PyFunction> query = ApplicationManager.getApplication().runReadAction(
+        new Computable<Query<PyFunction>>() {
+          @Override
+          public Query<PyFunction> compute() {
+            return PyOverridingMethodsSearch.search((PyFunction)queryParameters, true);
+          }
         }
-      });
+      );
+
+      return query.forEach(
+        new Processor<PyFunction>() {
+          public boolean process(final PyFunction pyFunction) {
+            return consumer.process(pyFunction);
+          }
+        }
+      );
     }
     else if (queryParameters instanceof PyTargetExpression) {  // PY-237
-      final PsiElement parent = queryParameters.getParent();
+      final PsiElement parent = ApplicationManager.getApplication().runReadAction(
+        new Computable<PsiElement>() {
+          @Override
+          public PsiElement compute() {
+            return queryParameters.getParent();
+          }
+        }
+      );
+
       if (parent instanceof PyAssignmentStatement) {
-        return consumer.process(parent);        
+        return consumer.process(parent);
       }
     }
     return true;
index 84887c3efa6d43dbeced7e08aff91678b35c4263..99a54daf975cda26e7b0157eca14e745a6bf92b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package com.jetbrains.python.psi.search;
 
 import com.intellij.openapi.application.AccessToken;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
 import com.intellij.util.Processor;
 import com.intellij.util.QueryExecutor;
 import com.jetbrains.python.psi.*;
@@ -26,9 +27,19 @@ import org.jetbrains.annotations.NotNull;
  * @author yole
  */
 public class PyOverridingMethodsSearchExecutor implements QueryExecutor<PyFunction, PyOverridingMethodsSearch.SearchParameters> {
-  public boolean execute(@NotNull final PyOverridingMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<PyFunction> consumer) {
+  public boolean execute(@NotNull final PyOverridingMethodsSearch.SearchParameters queryParameters,
+                         @NotNull final Processor<PyFunction> consumer) {
     final PyFunction baseMethod = queryParameters.getFunction();
-    PyClass containingClass = baseMethod.getContainingClass();
+
+    final PyClass containingClass = ApplicationManager.getApplication().runReadAction(
+      new Computable<PyClass>() {
+        @Override
+        public PyClass compute() {
+          return baseMethod.getContainingClass();
+        }
+      }
+    );
+
     return PyClassInheritorsSearch.search(containingClass, queryParameters.isCheckDeep()).forEach(new Processor<PyClass>() {
       public boolean process(final PyClass pyClass) {
         final AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();