Add default implementation for PyCallableType.isCallable and PyCallableType.getParameters

This commit is contained in:
Semyon Proshev
2017-06-09 21:29:07 +03:00
committed by Semyon Proshev
parent c9ddd3985d
commit f79376a519
7 changed files with 26 additions and 68 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -24,7 +24,6 @@ import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.psi.resolve.CompletionVariantsProcessor;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.resolve.RatedResolveResult;
import com.jetbrains.python.psi.types.PyCallableParameter;
import com.jetbrains.python.psi.types.PyClassLikeType;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
@@ -45,6 +44,7 @@ public class PyJavaClassType implements PyClassLikeType {
myDefinition = definition;
}
@Override
@Nullable
public List<? extends RatedResolveResult> resolveMember(@NotNull final String name,
@Nullable PyExpression location,
@@ -73,12 +73,15 @@ public class PyJavaClassType implements PyClassLikeType {
return null;
}
@Override
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
final CompletionVariantsProcessor processor = new CompletionVariantsProcessor(location);
myClass.processDeclarations(processor, ResolveState.initial(), null, location);
return processor.getResult();
}
@Override
@Nullable
public String getName() {
if (myClass != null) {
return myClass.getName();
@@ -117,12 +120,6 @@ public class PyJavaClassType implements PyClassLikeType {
return getReturnType(context);
}
@Nullable
@Override
public List<PyCallableParameter> getParameters(@NotNull TypeEvalContext context) {
return null;
}
@Override
public boolean isDefinition() {
return myDefinition;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -25,7 +25,6 @@ import com.jetbrains.python.psi.PyCallSiteExpression;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.resolve.RatedResolveResult;
import com.jetbrains.python.psi.types.PyCallableParameter;
import com.jetbrains.python.psi.types.PyCallableType;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
@@ -45,11 +44,6 @@ public class PyJavaMethodType implements PyCallableType {
myMethod = method;
}
@Override
public boolean isCallable() {
return true;
}
@Nullable
@Override
public PyType getReturnType(@NotNull TypeEvalContext context) {
@@ -62,12 +56,6 @@ public class PyJavaMethodType implements PyCallableType {
return getReturnType(context);
}
@Nullable
@Override
public List<PyCallableParameter> getParameters(@NotNull TypeEvalContext context) {
return null;
}
@Nullable
@Override
public List<? extends RatedResolveResult> resolveMember(@NotNull String name,
@@ -86,7 +74,7 @@ public class PyJavaMethodType implements PyCallableType {
@Override
public String getName() {
final PsiClass cls = myMethod.getContainingClass();
return "Java method(" + (cls != null ? cls.getQualifiedName() : cls) + "." + myMethod.getName() + ")";
return "Java method(" + (cls != null ? cls.getQualifiedName() : null) + "." + myMethod.getName() + ")";
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -31,7 +31,9 @@ public interface PyCallableType extends PyType {
/**
* Returns true if the type is callable.
*/
boolean isCallable();
default boolean isCallable() {
return true;
}
/**
* Returns the return type of a function independent of a call site.
@@ -54,5 +56,7 @@ public interface PyCallableType extends PyType {
* @return list of parameter info null if not applicable.
*/
@Nullable
List<PyCallableParameter> getParameters(@NotNull TypeEvalContext context);
default List<PyCallableParameter> getParameters(@NotNull TypeEvalContext context) {
return null;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -21,13 +21,17 @@ import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.QualifiedName;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ProcessingContext;
import com.intellij.util.Processor;
import com.jetbrains.NotNullPredicate;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.resolve.RatedResolveResult;
import com.jetbrains.python.psi.types.*;
import com.jetbrains.python.psi.types.PyClassLikeType;
import com.jetbrains.python.psi.types.PyClassType;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -178,12 +182,6 @@ public class PyCustomType implements PyClassLikeType {
return getReturnType(context);
}
@Nullable
@Override
public final List<PyCallableParameter> getParameters(@NotNull final TypeEvalContext context) {
return null;
}
@Nullable
@Override
public final List<? extends RatedResolveResult> resolveMember(@NotNull final String name,
@@ -212,7 +210,7 @@ public class PyCustomType implements PyClassLikeType {
lookupElements.addAll(Collections2.filter(Arrays.asList(parentType.getCompletionVariants(completionPrefix, location, context)),
new CompletionFilter()));
}
return lookupElements.toArray(new Object[lookupElements.size()]);
return ArrayUtil.toObjectArray(lookupElements);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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,7 +17,7 @@ package com.jetbrains.python.psi.types;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.util.Function;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ProcessingContext;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.psi.AccessDirection;
@@ -42,11 +42,6 @@ public class PyCallableTypeImpl implements PyCallableType {
myReturnType = returnType;
}
@Override
public boolean isCallable() {
return true;
}
@Nullable
@Override
public PyType getReturnType(@NotNull TypeEvalContext context) {
@@ -76,7 +71,7 @@ public class PyCallableTypeImpl implements PyCallableType {
@Override
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
return new Object[0];
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
@Nullable
@@ -494,12 +494,6 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
}
}
@Nullable
@Override
public List<PyCallableParameter> getParameters(@NotNull TypeEvalContext context) {
return null;
}
@NotNull
@Override
public final List<PyClassLikeType> getAncestorTypes(@NotNull final TypeEvalContext context) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -24,7 +24,6 @@ import com.jetbrains.python.PyNames;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.resolve.PyResolveImportUtil;
import com.jetbrains.python.psi.resolve.QualifiedResolveResult;
import com.jetbrains.python.psi.resolve.RatedResolveResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -37,7 +36,7 @@ import static com.jetbrains.python.psi.PyFunction.Modifier.STATICMETHOD;
import static com.jetbrains.python.psi.PyUtil.as;
/**
* Type of a particular function that is represented as a {@link com.jetbrains.python.psi.PyCallable} in the PSI tree.
* Type of a particular function that is represented as a {@link PyCallable} in the PSI tree.
*
* @author vlan
*/
@@ -48,11 +47,6 @@ public class PyFunctionTypeImpl implements PyFunctionType {
myCallable = callable;
}
@Override
public boolean isCallable() {
return true;
}
@Nullable
@Override
public PyType getReturnType(@NotNull TypeEvalContext context) {
@@ -176,16 +170,4 @@ public class PyFunctionTypeImpl implements PyFunctionType {
public PyCallable getCallable() {
return myCallable;
}
@Nullable
public static String getParameterName(@NotNull PyNamedParameter namedParameter) {
String name = namedParameter.getName();
if (namedParameter.isPositionalContainer()) {
name = "*" + name;
}
else if (namedParameter.isKeywordContainer()) {
name = "**" + name;
}
return name;
}
}