Merge remote-tracking branch 'origin/PY-17356' into PY-17356 appcode/144.912 clion/144.906 dbe/144.904
authorIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Fri, 6 Nov 2015 22:42:42 +0000 (01:42 +0300)
committerIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Fri, 6 Nov 2015 22:42:42 +0000 (01:42 +0300)
# Conflicts:
# python/psi-api/src/com/jetbrains/python/nameResolver/NameResolverTools.java
# python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java

python/psi-api/src/com/jetbrains/python/codeInsight/PyCustomMember.java

index 77218c6457fceaadba013143e3e3737591ed1eee..543d635050d5073dc618af3930b136868f6df719 100644 (file)
@@ -17,8 +17,11 @@ package com.jetbrains.python.codeInsight;
 
 import com.intellij.extapi.psi.ASTWrapperPsiElement;
 import com.intellij.icons.AllIcons;
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.UserDataHolderBase;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiReference;
+import com.intellij.psi.util.*;
 import com.intellij.util.Function;
 import com.jetbrains.python.psi.PyClass;
 import com.jetbrains.python.psi.PyFunction;
@@ -34,7 +37,9 @@ import javax.swing.*;
 /**
  * @author Dennis.Ushakov
  */
-public class PyCustomMember {
+public class PyCustomMember extends UserDataHolderBase {
+  private static final Key<ParameterizedCachedValue<PyClass, PsiElement>>
+    RESOLVE = Key.create("resolve");
   private final String myName;
   private final boolean myResolveToInstance;
   private final Function<PsiElement, PyType> myTypeCallback;
@@ -165,14 +170,26 @@ public class PyCustomMember {
   }
 
   @Nullable
-  public PsiElement resolve(@NotNull PsiElement context) {
+  public PsiElement resolve(@NotNull final PsiElement context) {
+
     if (myTarget != null) {
       return myTarget;
     }
 
     PyClass targetClass = null;
     if (myTypeName != null) {
-      targetClass = PyPsiFacade.getInstance(context.getProject()).createClassByQName(myTypeName, context);
+
+      final ParameterizedCachedValueProvider<PyClass, PsiElement> provider = new ParameterizedCachedValueProvider<PyClass, PsiElement>() {
+        @Nullable
+        @Override
+        public CachedValueProvider.Result<PyClass> compute(
+          final PsiElement param) {
+          final PyClass result = PyPsiFacade.getInstance(param.getProject()).createClassByQName(myTypeName, param);
+          return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT);
+        }
+      };
+      targetClass = CachedValuesManager.getManager(context.getProject()).getParameterizedCachedValue(this, RESOLVE,
+                                                                                                     provider, false, context);
     }
     final PsiElement resolveTarget = findResolveTarget(context);
     if (resolveTarget instanceof PyFunction && !myAlwaysResolveToCustomElement) {
@@ -212,6 +229,7 @@ public class PyCustomMember {
 
   /**
    * Checks if some reference points to this element
+   *
    * @param reference reference to check
    * @return true if reference points to it
    */