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;
/**
* @author Dennis.Ushakov
*/
-public class PyCustomMember extends UserDataHolderBase {
- private static final Key<ParameterizedCachedValue<PyClass, PsiElement>>
- RESOLVE = Key.create("resolve");
+public class PyCustomMember {
private final String myName;
private final boolean myResolveToInstance;
private final Function<PsiElement, PyType> myTypeCallback;
}
@Nullable
- public PsiElement resolve(@NotNull final PsiElement context) {
-
+ public PsiElement resolve(@NotNull PsiElement context) {
if (myTarget != null) {
return myTarget;
}
PyClass targetClass = null;
if (myTypeName != null) {
-
- 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);
+ targetClass = PyPsiFacade.getInstance(context.getProject()).createClassByQName(myTypeName, context);
}
final PsiElement resolveTarget = findResolveTarget(context);
if (resolveTarget instanceof PyFunction && !myAlwaysResolveToCustomElement) {
/**
* Checks if some reference points to this element
- *
* @param reference reference to check
* @return true if reference points to it
*/
}
/**
- * Checks if FQ element name is one of provided names
+ * Checks if FQ element name is one of provided names. May be <strong>heavy</strong>.
+ * It is always better to use less accurate but lighter {@link #isCalleeShortCut(PyCallExpression, FQNamesProvider, TypeEvalContext)}
*
* @param element element to check
* @param namesProviders some enum that has one or more names
*/
public static boolean isCalleeShortCut(@NotNull final PyCallExpression call,
@NotNull final FQNamesProvider function,
- @Nullable final TypeEvalContext context) {
- if (context == null) {
- return call.isCallee(function);
- }
+ @NotNull final TypeEvalContext context) {
final PyExpression callee = call.getCallee();
if (callee == null) {
return false;
import com.jetbrains.python.FunctionParameter;
import com.jetbrains.python.nameResolver.FQNamesProvider;
import com.jetbrains.python.psi.resolve.PyResolveContext;
+import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
* Returns the argument if one is present in the list.
*
* @param parameter parameter
- * @param argClass argument expected type
+ * @param argClass argument expected type
* @return the argument or null
*/
@Nullable
/**
* TODO: Copy/Paste with {@link PyArgumentList#addArgument(PyExpression)}
+ *
* @param expression
*/
void addArgument(PyExpression expression);
PyCallable resolveCalleeFunction(PyResolveContext resolveContext);
/**
- *
* @param resolveContext the reference resolve context
* @param implicitOffset known from the context implicit offset
*/
/**
* Checks if the qualified name of the callee matches any of the specified names provided by provider.
- * @see com.jetbrains.python.nameResolver
+ * May be <strong>heavy</strong>.
+ * Use {@link com.jetbrains.python.nameResolver.NameResolverTools#isCalleeShortCut(PyCallExpression, FQNamesProvider, TypeEvalContext)}
+ * if you can.
+ *
* @param name providers that provides one or more names to check
* @return true if matches, false otherwise
+ * @see com.jetbrains.python.nameResolver
*/
boolean isCallee(@NotNull FQNamesProvider... name);
/**
* @return number of implicitly passed positional parameters; 0 means no parameters are passed implicitly.
- * Note that a <tt>*args</tt> is never marked as passed implicitly.
- * E.g. for a function like <tt>foo(a, b, *args)</tt> always holds <tt>getImplicitOffset() < 2</tt>.
+ * Note that a <tt>*args</tt> is never marked as passed implicitly.
+ * E.g. for a function like <tt>foo(a, b, *args)</tt> always holds <tt>getImplicitOffset() < 2</tt>.
*/
public int getImplicitOffset() {
return myImplicitOffset;
@NotNull
@Override
public List<PyAssignmentStatement> findAttributes() {
+ /**
+ * TODO: This method if insanely heavy since it unstubs foreign files.
+ * Need to save stubs and use them somehow.
+ *
+ */
return CachedValuesManager.getManager(getProject()).getCachedValue(this, ATTRIBUTES_KEY, new CachedValueProvider<List<PyAssignmentStatement>>() {
@Nullable
@Override