Always use path to target in AddImportHelper.addImport (PY-25484)

This commit is contained in:
Semyon Proshev
2017-10-23 19:48:31 +03:00
parent 551acb88d4
commit f98eca6612
6 changed files with 21 additions and 19 deletions
@@ -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);
}
}
}
@@ -0,0 +1,3 @@
from pkg import Foo
foo = Foo
@@ -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, "");