mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -19,13 +19,13 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -160,17 +160,20 @@ public class ImportCandidateHolder implements Comparable<ImportCandidateHolder>
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int compareTo(@NotNull ImportCandidateHolder rhs) {
|
||||
public int compareTo(@NotNull ImportCandidateHolder other) {
|
||||
final int lRelevance = getRelevance();
|
||||
final int rRelevance = rhs.getRelevance();
|
||||
final int rRelevance = other.getRelevance();
|
||||
if (rRelevance != lRelevance) {
|
||||
return rRelevance - lRelevance;
|
||||
}
|
||||
// prefer shorter paths
|
||||
if (myPath != null && rhs.myPath != null) {
|
||||
return myPath.getComponentCount() - rhs.myPath.getComponentCount();
|
||||
if (myPath != null && other.myPath != null) {
|
||||
// prefer shorter paths
|
||||
final int lengthDiff = myPath.getComponentCount() - other.myPath.getComponentCount();
|
||||
if (lengthDiff != 0) {
|
||||
return lengthDiff;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return Comparing.compare(myPath, other.myPath);
|
||||
}
|
||||
|
||||
int getRelevance() {
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
from foo import MyClass
|
||||
from bar import MyClass
|
||||
|
||||
MyClass()
|
||||
@@ -15,16 +15,10 @@
|
||||
*/
|
||||
package com.jetbrains.python.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.debugger.PySignature;
|
||||
import com.jetbrains.python.debugger.PySignatureCacheManager;
|
||||
import com.jetbrains.python.debugger.PySignatureCacheManagerImpl;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
@@ -51,30 +45,6 @@ public class PyAnnotateTypesIntentionTest extends PyIntentionTestCase {
|
||||
public void testTypeComment() {
|
||||
doTest(PyBundle.message("INTN.annotate.types"), LanguageLevel.PYTHON27);
|
||||
}
|
||||
|
||||
public void testImportDict() throws IOException {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON30);
|
||||
try {
|
||||
final String testFileName = getTestName(true);
|
||||
myFixture.configureByFile(testFileName + ".py");
|
||||
|
||||
String signature = PySignatureCacheManager.signatureToString(
|
||||
new PySignature(myFixture.getFile().getVirtualFile().getCanonicalPath(), "get_dict").addReturnType("Dict[int, str]"));
|
||||
PySignatureCacheManagerImpl.CALL_SIGNATURES_ATTRIBUTE.writeAttributeBytes(myFixture.getFile().getVirtualFile(),
|
||||
signature.getBytes());
|
||||
|
||||
final IntentionAction intentionAction = myFixture.findSingleIntention(PyBundle.message("INTN.annotate.types"));
|
||||
assertNotNull(intentionAction);
|
||||
myFixture.launchAction(intentionAction);
|
||||
myFixture.checkResultByFile(testFileName + "_after.py", true);
|
||||
}
|
||||
finally {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null);
|
||||
}
|
||||
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
private void doTest() {
|
||||
doTest(PyBundle.message("INTN.annotate.types"), LanguageLevel.PYTHON30);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class AddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
doMultiFileAutoImportTest("Import", fix -> {
|
||||
final List<ImportCandidateHolder> candidates = fix.getCandidates();
|
||||
final List<String> names = ContainerUtil.map(candidates, c -> c.getPresentableText("MyClass"));
|
||||
assertSameElements(names, "foo.MyClass", "bar.MyClass");
|
||||
assertOrderedEquals(names, "bar.MyClass", "foo.MyClass");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user