mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Always use path to target in AddImportHelper.addImport (PY-25484)
This commit is contained in:
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// 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.imports;
|
||||
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
@@ -561,18 +547,16 @@ public class AddImportHelper {
|
||||
addImportStatement(file, path, null, priority, element);
|
||||
}
|
||||
else {
|
||||
final QualifiedName toImportQName = QualifiedNameFinder.findCanonicalImportPath(toImport, element);
|
||||
if (toImportQName == null) return;
|
||||
if (useQualified) {
|
||||
addImportStatement(file, path, null, priority, element);
|
||||
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(file.getProject());
|
||||
final String targetName = PyUtil.getElementNameWithoutExtension(target);
|
||||
element.replace(elementGenerator.createExpressionFromText(LanguageLevel.forElement(target), toImportQName + "." + targetName));
|
||||
element.replace(elementGenerator.createExpressionFromText(LanguageLevel.forElement(target), qName + "." + targetName));
|
||||
}
|
||||
else {
|
||||
final String name = target.getName();
|
||||
if (name != null)
|
||||
addOrUpdateFromImportStatement(file, toImportQName.toString(), name, null, priority, element);
|
||||
addOrUpdateFromImportStatement(file, qName.toString(), name, null, priority, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
from pkg import Foo
|
||||
|
||||
foo = Foo
|
||||
+1
@@ -0,0 +1 @@
|
||||
foo = Foo<caret>
|
||||
@@ -0,0 +1,4 @@
|
||||
from bar import *
|
||||
|
||||
|
||||
__all__ = ["Foo"]
|
||||
@@ -0,0 +1,5 @@
|
||||
__all__ = ["Foo"]
|
||||
|
||||
|
||||
class Foo:
|
||||
pass
|
||||
@@ -79,6 +79,11 @@ public class PyClassNameCompletionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-25484
|
||||
public void testClassReexportedThroughDunderAll() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/className/" + getTestName(true);
|
||||
myFixture.copyDirectoryToProject(path, "");
|
||||
|
||||
Reference in New Issue
Block a user