From c86688b5e64cabd25800ad630257e8cbd1c0ca91 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 18 Jan 2018 15:27:31 +0300 Subject: [PATCH] Revert "Remove deprecated methods and classes from PyCallExpression" This reverts commit 80701b3 until https://github.com/pantsbuild/intellij-pants-plugin/issues/327 is closed --- .../python/psi/PyCallExpression.java | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) diff --git a/python/psi-api/src/com/jetbrains/python/psi/PyCallExpression.java b/python/psi-api/src/com/jetbrains/python/psi/PyCallExpression.java index a66986b812e3..59421d4a2782 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/PyCallExpression.java +++ b/python/psi-api/src/com/jetbrains/python/psi/PyCallExpression.java @@ -149,6 +149,67 @@ public interface PyCallExpression extends PyCallSiteExpression { return null; } + /** + * Adds an argument to the end of argument list. + * + * @param expression what to add + * @deprecated Use {@link PyCallExpression#getArgumentList()} and {@link PyArgumentList#addArgument(PyExpression)} instead. + * This method will be removed in 2018.1. + */ + @Deprecated + default void addArgument(@NotNull PyExpression expression) { + final PyArgumentList argumentList = getArgumentList(); + if (argumentList != null) { + argumentList.addArgument(expression); + } + } + + /** + * Resolves the callee down to particular function (standalone, method, or constructor). + * + * @param resolveContext resolve context + * @return the resolved callee or null if it cannot be resolved + * @deprecated Use {@link PyCallExpression#multiResolveCalleeFunction(PyResolveContext)} instead. + * This method will be removed in 2018.1. + */ + @Nullable + @Deprecated + default PyCallable resolveCalleeFunction(@NotNull PyResolveContext resolveContext) { + final PyMarkedCallee first = ContainerUtil.getFirstItem(multiResolveCallee(resolveContext, 0)); + return first == null ? null : first.getElement(); + } + + /** + * Resolves the callee down to particular function (standalone, method, or constructor). + * + * @param resolveContext resolve context + * @return an object which contains callable, modifier, implicit offset and "implicitly resolved" flag. + * Returns null if the callee cannot be resolved. + * @deprecated Use {@link PyCallExpression#multiResolveCallee(PyResolveContext)} instead. + * This method will be removed in 2018.1. + */ + @Nullable + @Deprecated + default PyMarkedCallee resolveCallee(@NotNull PyResolveContext resolveContext) { + return ContainerUtil.getFirstItem(multiResolveCallee(resolveContext, 0)); + } + + /** + * Resolves the callee down to particular function (standalone, method, or constructor). + * + * @param resolveContext resolve context + * @param implicitOffset implicit offset which is known from the context + * @return an object which contains callable, modifier, implicit offset and "implicitly resolved" flag. + * Returns null if the callee cannot be resolved. + * @deprecated Use {@link PyCallExpression#multiResolveCallee(PyResolveContext, int)} instead. + * This method will be removed in 2018.1. + */ + @Nullable + @Deprecated + default PyMarkedCallee resolveCallee(@NotNull PyResolveContext resolveContext, int implicitOffset) { + return ContainerUtil.getFirstItem(multiResolveCallee(resolveContext, implicitOffset)); + } + /** * Resolves the callee to possible functions. * Try to use {@link PyCallExpression#multiResolveCallee(PyResolveContext)} @@ -186,6 +247,93 @@ public interface PyCallExpression extends PyCallSiteExpression { @NotNull List multiResolveCallee(@NotNull PyResolveContext resolveContext, int implicitOffset); + /** + * Resolves the callee to possible functions. + * + * @param resolveContext resolve context + * @return the rated resolved callees or an empty list. + * Note: the returned list does not contain null values. + * @deprecated Use {@link PyCallExpression#multiResolveCallee(PyResolveContext)} instead. + * This method will be removed in 2018.1. + */ + @NotNull + @Deprecated + default List multiResolveRatedCalleeFunction(@NotNull PyResolveContext resolveContext) { + return ContainerUtil.map(multiResolveCallee(resolveContext, 0), + markedCallee -> new PyRatedCallee(markedCallee.getCallableType(), + markedCallee.getElement(), + markedCallee.getRate())); + } + + /** + * Resolves the callee to possible functions. + * + * @param resolveContext resolve context + * @return rated objects which contains callable, modifier, implicit offset and "implicitly resolved" flag. + * Note: the returned list does not contain null values. + * @deprecated Use {@link PyCallExpression#multiResolveCallee(PyResolveContext)} instead. + * This method will be removed in 2018.1. + */ + @NotNull + @Deprecated + default List multiResolveRatedCallee(@NotNull PyResolveContext resolveContext) { + return multiResolveRatedCallee(resolveContext, 0); + } + + /** + * Resolves the callee to possible functions. + * + * @param resolveContext resolve context + * @param implicitOffset implicit offset which is known from the context + * @return rated objects which contains callable, modifier, implicit offset and "implicitly resolved" flag. + * Note: the returned list does not contain null values. + * @deprecated Use {@link PyCallExpression#multiResolveCallee(PyResolveContext, int)} instead. + * This method will be removed in 2018.1. + */ + @NotNull + @Deprecated + default List multiResolveRatedCallee(@NotNull PyResolveContext resolveContext, int implicitOffset) { + return ContainerUtil.map(multiResolveCallee(resolveContext, implicitOffset), + markedCallee -> new PyRatedMarkedCallee(markedCallee, markedCallee.getRate())); + } + + /** + * Resolves the callee down to particular function (standalone, method, or constructor) and maps arguments to parameters. + * + * @param resolveContext resolve context + * @return an object which contains callable and mappings. + * Returns mapping created by {@link PyArgumentsMapping#empty(PyCallSiteExpression)} if the callee cannot be resolved. + * @deprecated Use {@link PyCallExpression#multiMapArguments(PyResolveContext)} instead. + * This method will be removed in 2018.1. + */ + @NotNull + @Deprecated + default PyArgumentsMapping mapArguments(@NotNull PyResolveContext resolveContext) { + return Optional + .of(multiMapArguments(resolveContext, 0)) + .map(ContainerUtil::getFirstItem) + .orElseGet(() -> PyArgumentsMapping.empty(this)); + } + + /** + * Resolves the callee down to particular function (standalone, method, or constructor) and maps arguments to parameters. + * + * @param resolveContext resolve context + * @param implicitOffset implicit offset which is known from the context + * @return an object which contains callable and mappings. + * Returns mapping created by {@link PyArgumentsMapping#empty(PyCallSiteExpression)} if the callee cannot be resolved. + * @deprecated Use {@link PyCallExpression#multiMapArguments(PyResolveContext, int)} instead. + * This method will be removed in 2018.1. + */ + @NotNull + @Deprecated + default PyArgumentsMapping mapArguments(@NotNull PyResolveContext resolveContext, int implicitOffset) { + return Optional + .of(multiMapArguments(resolveContext, implicitOffset)) + .map(ContainerUtil::getFirstItem) + .orElseGet(() -> PyArgumentsMapping.empty(this)); + } + /** * Resolves the callee to possible functions and maps arguments to parameters for all of them. * @@ -384,6 +532,17 @@ public interface PyCallExpression extends PyCallSiteExpression { return myCallableType; } + /** + * @return resolved callable + * @deprecated Use {@link PyMarkedCallee#getElement()} instead. + * This method will be removed in 2018.1. + */ + @Nullable + @Deprecated + public PyCallable getCallable() { + return getElement(); + } + @Override @Nullable public PyCallable getElement() { @@ -411,4 +570,60 @@ public interface PyCallExpression extends PyCallSiteExpression { return myImplicitlyResolved; } } + + /** + * @deprecated Use {@link PyMarkedCallee} instead. + * This class will be removed in 2018.1. + */ + @Deprecated + class PyRatedCallee extends RatedResolveResult { + + @NotNull + private final PyCallableType myCallableType; + + public PyRatedCallee(@NotNull PyCallableType callableType, @Nullable PyCallable callable, int rate) { + super(rate, callable); + myCallableType = callableType; + } + + @NotNull + public PyCallableType getCallableType() { + return myCallableType; + } + + @Override + @Nullable + public PyCallable getElement() { + //noinspection ConstantConditions + return (PyCallable)super.getElement(); + } + } + + /** + * @deprecated Use {@link PyMarkedCallee} instead. + * This class will be removed in 2018.1. + */ + @Deprecated + class PyRatedMarkedCallee extends RatedResolveResult { + + @NotNull + private final PyMarkedCallee myMarkedCallee; + + public PyRatedMarkedCallee(@NotNull PyMarkedCallee markedCallee, int rate) { + super(rate, markedCallee.getElement()); + myMarkedCallee = markedCallee; + } + + @NotNull + public PyMarkedCallee getMarkedCallee() { + return myMarkedCallee; + } + + @Override + @Nullable + public PyCallable getElement() { + //noinspection ConstantConditions + return (PyCallable)super.getElement(); + } + } }