remove wrong dependency of OpenAPI module "python.psi.api" on impl modules

GitOrigin-RevId: e660cbbf392d65e6ef67490c94d25808df2414bc
This commit is contained in:
Alexey Kudravtsev
2021-08-09 01:09:17 +02:00
committed by intellij-monorepo-bot
parent 732321c51a
commit c01b94ba55
6 changed files with 154 additions and 71 deletions

View File

@@ -10,7 +10,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="intellij.platform.core" />
<orderEntry type="module" module-name="intellij.platform.projectModel" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.util.ui" />
<orderEntry type="library" name="Guava" level="project" />
</component>

View File

@@ -1,7 +1,6 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.codeInsight;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
@@ -13,11 +12,8 @@ import com.intellij.util.Function;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.psi.PyPsiFacade;
import com.jetbrains.python.psi.PyTypedElement;
import com.jetbrains.python.psi.resolve.PyResolveContext;
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;
@@ -46,7 +42,7 @@ public class PyCustomMember extends UserDataHolderBase {
boolean myFunction = false;
/**
* Force resolving to {@link MyInstanceElement} even if element is function
* Force resolving to {@link com.jetbrains.python.codeInsight.PyCustomMemberProviderImpl.MyInstanceElement} even if element is function
*/
private boolean myAlwaysResolveToCustomElement;
private Icon myIcon = AllIcons.Nodes.Method;
@@ -128,7 +124,7 @@ public class PyCustomMember extends UserDataHolderBase {
}
/**
* Force resolving to {@link MyInstanceElement} even if element is function
* Force resolving to {@link com.jetbrains.python.codeInsight.PyCustomMemberProviderImpl.MyInstanceElement} even if element is function
*/
@NotNull
public final PyCustomMember alwaysResolveToCustomElement() {
@@ -220,7 +216,8 @@ public class PyCustomMember extends UserDataHolderBase {
if (targetClass == null && resolveTarget instanceof PyClass) {
targetClass = (PyClass)resolveTarget;
}
return new MyInstanceElement(targetClass, context, resolveTarget);
return PyCustomMemberProvider.getInstance().createPyCustomMemberTarget(this, targetClass, context, resolveTarget, myTypeCallback, myCustomTypeInfo, myResolveToInstance);
}
return null;
}
@@ -258,11 +255,7 @@ public class PyCustomMember extends UserDataHolderBase {
* @return true if reference points to it
*/
public final boolean isReferenceToMe(@NotNull final PsiReference reference) {
final PsiElement element = reference.resolve();
if (!(element instanceof MyInstanceElement)) {
return false;
}
return ((MyInstanceElement)element).getThis().equals(this);
return PyCustomMemberProvider.getInstance().isReferenceToMe(reference, this);
}
/**
@@ -285,60 +278,4 @@ public class PyCustomMember extends UserDataHolderBase {
return this;
}
private class MyInstanceElement extends ASTWrapperPsiElement implements PyTypedElement {
private final PyClass myClass;
private final PsiElement myContext;
MyInstanceElement(PyClass clazz, PsiElement context, PsiElement resolveTarget) {
super(resolveTarget != null ? resolveTarget.getNode() : clazz.getNode());
myClass = clazz;
myContext = context;
}
private PyCustomMember getThis() {
return PyCustomMember.this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyInstanceElement element = (MyInstanceElement)o;
return Objects.equals(getThis(), element.getThis()) &&
Objects.equals(myClass, element.myClass) &&
Objects.equals(myContext, element.myContext) &&
Objects.equals(getNode(), element.getNode());
}
@Override
public String toString() {
return "MyInstanceElement{" +
"myClass=" + myClass +
"member=" + getThis() +
"node=" + getNode() +
", myContext=" + myContext +
'}';
}
@Override
public int hashCode() {
return Objects.hash(myClass, myContext, getNode(), getThis());
}
@Override
@Nullable
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
if (myTypeCallback != null) {
return myTypeCallback.fun(myContext);
}
else if (myClass != null) {
final PyClassType type = PyPsiFacade.getInstance(getProject()).createClassType(myClass, !myResolveToInstance);
if (myCustomTypeInfo != null) {
myCustomTypeInfo.fill(type);
}
return type;
}
return null;
}
}
}

View File

@@ -0,0 +1,25 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.codeInsight;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.util.Function;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyTypedElement;
import com.jetbrains.python.psi.types.PyType;
public abstract class PyCustomMemberProvider {
public static PyCustomMemberProvider getInstance() {
return ApplicationManager.getApplication().getService(PyCustomMemberProvider.class);
}
public abstract boolean isReferenceToMe(PsiReference reference, PyCustomMember member);
public abstract PyTypedElement createPyCustomMemberTarget(PyCustomMember member,
PyClass clazz,
PsiElement context,
PsiElement resolveTarget,
Function<? super PsiElement, ? extends PyType> typeCallback,
PyCustomMemberTypeInfo<?> customTypeInfo, boolean resolveToInstance);
}

View File

@@ -7,7 +7,6 @@ import com.intellij.openapi.util.RecursionManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.jetbrains.python.psi.PyCallable;
import com.jetbrains.python.psi.PyTypedElement;
import org.jetbrains.annotations.NotNull;
@@ -246,6 +245,18 @@ public final class TypeEvalContext {
}
private boolean inOrigin(@NotNull PsiElement element) {
return myConstraints.myOrigin == element.getContainingFile() || myConstraints.myOrigin == FileContextUtil.getContextFile(element);
return myConstraints.myOrigin == element.getContainingFile() || myConstraints.myOrigin == getContextFile(element);
}
private static PsiFile getContextFile(@NotNull PsiElement element) {
PsiFile file = element.getContainingFile();
if (file == null) return null;
PsiElement context = file.getContext();
if (context == null) {
return file;
}
else {
return getContextFile(context);
}
}
}

View File

@@ -287,6 +287,8 @@
<applicationService serviceInterface="com.jetbrains.python.packaging.PyPackageManagers"
serviceImplementation="com.jetbrains.python.packaging.PyPackageManagersImpl"/>
<applicationService serviceImplementation="com.jetbrains.python.codeInsight.typing.PyStubPackagesAdvertiserCache"/>
<applicationService serviceInterface="com.jetbrains.python.codeInsight.PyCustomMemberProvider"
serviceImplementation="com.jetbrains.python.codeInsight.PyCustomMemberProviderImpl"/>
<projectService serviceImplementation="com.jetbrains.python.codeInsight.typing.PyStubPackagesInstallingStatus"/>
<qualifiedNameProvider implementation="com.jetbrains.python.actions.PyQualifiedNameProvider"/>

View File

@@ -0,0 +1,109 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.codeInsight;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.util.Function;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyPsiFacade;
import com.jetbrains.python.psi.PyTypedElement;
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;
import java.util.Objects;
class PyCustomMemberProviderImpl extends PyCustomMemberProvider {
@Override
public PyTypedElement createPyCustomMemberTarget(PyCustomMember member,
PyClass clazz,
PsiElement context,
PsiElement resolveTarget,
Function<? super PsiElement, ? extends PyType> typeCallback,
PyCustomMemberTypeInfo<?> customTypeInfo, boolean resolveToInstance) {
return new MyInstanceElement(member, clazz, context, resolveTarget, typeCallback, customTypeInfo, resolveToInstance);
}
@Override
public boolean isReferenceToMe(PsiReference reference, PyCustomMember member) {
final PsiElement element = reference.resolve();
if (!(element instanceof MyInstanceElement)) {
return false;
}
return ((MyInstanceElement)element).getThis().equals(member);
}
private static class MyInstanceElement extends ASTWrapperPsiElement implements PyTypedElement {
private final PyCustomMember myMember;
private final PyClass myClass;
private final PsiElement myContext;
private final Function<? super PsiElement, ? extends PyType> myTypeCallback;
private final PyCustomMemberTypeInfo<?> myCustomTypeInfo;
private final boolean myResolveToInstance;
MyInstanceElement(PyCustomMember member,
PyClass clazz,
PsiElement context,
PsiElement resolveTarget,
Function<? super PsiElement, ? extends PyType> typeCallback,
PyCustomMemberTypeInfo<?> customTypeInfo, boolean resolveToInstance) {
super(resolveTarget != null ? resolveTarget.getNode() : clazz.getNode());
myMember = member;
myClass = clazz;
myContext = context;
myTypeCallback = typeCallback;
myCustomTypeInfo = customTypeInfo;
myResolveToInstance = resolveToInstance;
}
private PyCustomMember getThis() {
return myMember;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyInstanceElement element = (MyInstanceElement)o;
return Objects.equals(getThis(), element.getThis()) &&
Objects.equals(myClass, element.myClass) &&
Objects.equals(myContext, element.myContext) &&
Objects.equals(getNode(), element.getNode());
}
@Override
public String toString() {
return "MyInstanceElement{" +
"myClass=" + myClass +
"member=" + getThis() +
"node=" + getNode() +
", myContext=" + myContext +
'}';
}
@Override
public int hashCode() {
return Objects.hash(myClass, myContext, getNode(), getThis());
}
@Override
@Nullable
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
if (myTypeCallback != null) {
return myTypeCallback.fun(myContext);
}
else if (myClass != null) {
final PyClassType type = PyPsiFacade.getInstance(getProject()).createClassType(myClass, !myResolveToInstance);
if (myCustomTypeInfo != null) {
myCustomTypeInfo.fill(type);
}
return type;
}
return null;
}
}
}