PY-36374 Clean up in ImportFromExistingAction and ImportCandidateHolder

* Remove some obsolete comments
* Simplify a redundant PECS signature
* Fix visibility of the fields in ImportFromExistingAction
* Make a precondition violation an IllegalArgumentException instead of assertion

GitOrigin-RevId: e37ea9974ac56f385f1993d6b953c522f564efe5
This commit is contained in:
Mikhail Golubev
2021-01-07 17:25:37 +00:00
committed by intellij-monorepo-bot
parent 72ca3ddb8b
commit 5d3a9d440e
2 changed files with 9 additions and 8 deletions
@@ -28,9 +28,9 @@ import java.util.List;
*
* @author dcheryasov
*/
// visibility is intentionally package-level
public class ImportCandidateHolder implements Comparable<ImportCandidateHolder> {
private static final Logger LOG = Logger.getInstance(ImportCandidateHolder.class);
@NotNull private final SmartPsiElementPointer<PsiNamedElement> myImportable;
@Nullable private final SmartPsiElementPointer<PyImportElement> myImportElement;
@NotNull private final SmartPsiElementPointer<PsiFileSystemItem> myFile;
@@ -49,10 +49,12 @@ public class ImportCandidateHolder implements Comparable<ImportCandidateHolder>
* For top-level imported symbols it's <em>qualified name of containing module</em> (or package for __init__.py).
* For modules and packages it should be <em>qualified name of their parental package</em>
* (empty for modules and packages located at source roots).
*
*/
public ImportCandidateHolder(@NotNull PsiNamedElement importable, @NotNull PsiFileSystemItem file,
@Nullable PyImportElement importElement, @Nullable QualifiedName path, @Nullable String asName) {
if (importElement == null && path == null) {
throw new IllegalArgumentException("Either an import path or an existing import should be provided for " + importable);
}
SmartPointerManager pointerManager = SmartPointerManager.getInstance(importable.getProject());
myFile = pointerManager.createSmartPsiElementPointer(file);
myImportable = pointerManager.createSmartPsiElementPointer(importable);
@@ -63,7 +65,6 @@ public class ImportCandidateHolder implements Comparable<ImportCandidateHolder>
myAsName = asName;
myRelevance = PyCompletionUtilsKt.computeCompletionWeight(importable, myImportableName, myPath, null, false);
LOG.debug("Computed relevance for import item ", myImportableName, ": ", myRelevance);
assert importElement != null || path != null; // one of these must be present
}
public ImportCandidateHolder(@NotNull PsiNamedElement importable, @NotNull PsiFileSystemItem file,
@@ -27,10 +27,10 @@ import static com.jetbrains.python.psi.PyUtil.as;
* @author dcheryasov
*/
public class ImportFromExistingAction implements QuestionAction {
PsiElement myTarget;
List<? extends ImportCandidateHolder> mySources; // list of <import, imported_item>
String myName;
boolean myUseQualifiedImport;
private final PsiElement myTarget;
private final List<ImportCandidateHolder> mySources;
private final String myName;
private final boolean myUseQualifiedImport;
private Runnable myOnDoneCallback;
private final boolean myImportLocally;
@@ -40,7 +40,7 @@ public class ImportFromExistingAction implements QuestionAction {
* @param name relevant name ot the target element (e.g. of identifier in an expression).
* @param useQualified if True, use qualified "import modulename" instead of "from modulename import ...".
*/
public ImportFromExistingAction(@NotNull PsiElement target, @NotNull List<? extends ImportCandidateHolder> sources, @NotNull String name,
public ImportFromExistingAction(@NotNull PsiElement target, @NotNull List<ImportCandidateHolder> sources, @NotNull String name,
boolean useQualified, boolean importLocally) {
myTarget = target;
mySources = sources;