mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
Return null if found similar element is the same as the original one
This commit is contained in:
@@ -184,11 +184,13 @@ public class PyiUtil {
|
|||||||
final PyClassLikeType instanceType = classType.toInstance();
|
final PyClassLikeType instanceType = classType.toInstance();
|
||||||
final List<? extends RatedResolveResult> resolveResults = instanceType.resolveMember(name, null, AccessDirection.READ,
|
final List<? extends RatedResolveResult> resolveResults = instanceType.resolveMember(name, null, AccessDirection.READ,
|
||||||
PyResolveContext.noImplicits(), false);
|
PyResolveContext.noImplicits(), false);
|
||||||
return takeTopPriorityElement(resolveResults);
|
final PsiElement result = takeTopPriorityElement(resolveResults);
|
||||||
|
return result == element ? null : result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (originalOwner instanceof PyFile) {
|
else if (originalOwner instanceof PyFile) {
|
||||||
return takeTopPriorityElement(((PyFile)originalOwner).multiResolveName(name));
|
final PsiElement result = takeTopPriorityElement(((PyFile)originalOwner).multiResolveName(name));
|
||||||
|
return result == element ? null : result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
foo = None
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def foo():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class B:
|
||||||
|
bar = None
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class B:
|
||||||
|
def bar(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def function():
|
||||||
|
pass
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
function = None
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A:
|
||||||
|
def method(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class A:
|
||||||
|
method = None
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class B:
|
||||||
|
def bar(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A:
|
||||||
|
def method(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def foo():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class B:
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class B:
|
||||||
|
def bar(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def function():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A:
|
||||||
|
def method(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class A:
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def foo():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def function():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from typing import overload
|
||||||
|
|
||||||
|
|
||||||
|
class B:
|
||||||
|
@overload
|
||||||
|
def baz(self, v: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def baz(self, v: int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def baz(self, v):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def foo():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def foo():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class B:
|
||||||
|
def bar(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class B:
|
||||||
|
def bar(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def function():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def function():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A:
|
||||||
|
def method(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A:
|
||||||
|
def method(self):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
// Copyright 2000-2018 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.pyi
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
||||||
|
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiNameIdentifierOwner
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
|
import com.jetbrains.python.fixtures.PyTestCase
|
||||||
|
import com.jetbrains.python.psi.PyFunction
|
||||||
|
|
||||||
|
class PyiRelatedItemLineMarkerTest : PyTestCase() {
|
||||||
|
|
||||||
|
fun testOverloadsAndImplementationInPyFile() {
|
||||||
|
assertNoMarker("baz", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// runtime -> stub
|
||||||
|
|
||||||
|
fun testNoSimilarClassForRuntimeMethod() {
|
||||||
|
assertNoMarker("method", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNoSimilarForRuntimeMethod() {
|
||||||
|
assertNoMarker("method", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimilarForRuntimeMethod() {
|
||||||
|
assertMarker("method", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testAnotherTypeSimilarForRuntimeMethod() {
|
||||||
|
assertMarker("method", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNoSimilarModuleForRuntimeFunction() {
|
||||||
|
assertNoMarker("function", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNoSimilarForRuntimeFunction() {
|
||||||
|
assertNoMarker("function", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimilarForRuntimeFunction() {
|
||||||
|
assertMarker("function", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testAnotherTypeSimilarForRuntimeFunction() {
|
||||||
|
assertMarker("function", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stub -> runtime
|
||||||
|
|
||||||
|
fun testNoSimilarClassForMethodStub() {
|
||||||
|
assertNoMarker("bar", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNoSimilarForMethodStub() {
|
||||||
|
assertNoMarker("bar", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimilarForMethodStub() {
|
||||||
|
assertMarker("bar", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testAnotherTypeSimilarForMethodStub() {
|
||||||
|
assertMarker("bar", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNoSimilarModuleForFunctionStub() {
|
||||||
|
assertNoMarker("foo", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNoSimilarForFunctionStub() {
|
||||||
|
assertNoMarker("foo", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimilarForFunctionStub() {
|
||||||
|
assertMarker("foo", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testAnotherTypeSimilarForFunctionStub() {
|
||||||
|
assertMarker("foo", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getTestDataPath(): String {
|
||||||
|
return super.getTestDataPath() + "/pyi/lineMarkers"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertMarker(elementName: String, pyi: Boolean) {
|
||||||
|
val expectedTooltip = if (pyi) "Stub for item in b.py" else "Has stub item in a.pyi"
|
||||||
|
assertEquals(expectedTooltip, getMarkers(elementName, pyi).singleOrNull()?.lineMarkerTooltip)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertNoMarker(elementName: String, pyi: Boolean) {
|
||||||
|
assertEmpty(getMarkers(elementName, pyi))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getMarkers(elementName: String, pyi: Boolean): List<LineMarkerInfo<PsiElement>> {
|
||||||
|
myFixture.copyDirectoryToProject(getTestName(false), "")
|
||||||
|
myFixture.configureByFile(if (pyi) "b.pyi" else "a.py")
|
||||||
|
|
||||||
|
val functions = PsiTreeUtil.findChildrenOfType(myFixture.file, PyFunction::class.java)
|
||||||
|
functions.forEach { assertEquals(elementName, it.name) }
|
||||||
|
assertNotEmpty(functions)
|
||||||
|
|
||||||
|
myFixture.doHighlighting()
|
||||||
|
|
||||||
|
return DaemonCodeAnalyzerImpl
|
||||||
|
.getLineMarkers(myFixture.editor.document, myFixture.project)
|
||||||
|
.filter { PsiTreeUtil.getParentOfType(it.element, PsiNameIdentifierOwner::class.java)?.name == elementName }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user