use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PythonImportUtils method proposeImportFix.
@Nullable
public static AutoImportQuickFix proposeImportFix(final PyElement node, PsiReference reference) {
final String text = reference.getElement().getText();
// text of the part we're working with
final String refText = reference.getRangeInElement().substring(text);
// don't propose meaningless auto imports if no interpreter is configured
final Module module = ModuleUtilCore.findModuleForPsiElement(node);
if (module != null && PythonSdkType.findPythonSdk(module) == null) {
return null;
}
// don't show auto-import fix if we're trying to reference a variable which is defined below in the same scope
ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(node, ScopeOwner.class);
if (scopeOwner != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(refText)) {
return null;
}
AutoImportQuickFix fix = addCandidates(node, reference, refText, null);
if (fix != null)
return fix;
final String packageName = PyPackageAliasesProvider.commonImportAliases.get(refText);
if (packageName != null) {
fix = addCandidates(node, reference, packageName, refText);
if (fix != null)
return fix;
}
return null;
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class AddImportHelper method getImportPriority.
@NotNull
public static ImportPriority getImportPriority(@NotNull PsiElement importLocation, @NotNull PsiFileSystemItem toImport) {
final VirtualFile vFile = toImport.getVirtualFile();
if (vFile == null) {
return UNRESOLVED_SYMBOL_PRIORITY;
}
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(toImport.getProject());
final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
if (fileIndex.isInContent(vFile) && !fileIndex.isInLibraryClasses(vFile)) {
return ImportPriority.PROJECT;
}
final Module module = ModuleUtilCore.findModuleForPsiElement(importLocation);
final Sdk pythonSdk = module != null ? PythonSdkType.findPythonSdk(module) : projectRootManager.getProjectSdk();
return PythonSdkType.isStdLib(vFile, pythonSdk) ? ImportPriority.BUILTIN : ImportPriority.THIRD_PARTY;
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class ImportCandidateHolder method getRelevance.
int getRelevance() {
final Project project = myImportable.getProject();
final PsiFile psiFile = myImportable.getContainingFile();
final VirtualFile vFile = psiFile == null ? null : psiFile.getVirtualFile();
if (vFile == null)
return 0;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
// files under project source are most relevant
final Module module = fileIndex.getModuleForFile(vFile);
if (module != null)
return 3;
// then come files directly under Lib
if (vFile.getParent().getName().equals("Lib"))
return 2;
// tests we don't want
if (vFile.getParent().getName().equals("test"))
return 0;
return 1;
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PythonTestLegacyConfigurationProducer method isTestFolder.
protected boolean isTestFolder(@NotNull final VirtualFile virtualFile, @NotNull final Project project) {
@NonNls final String name = virtualFile.getName();
final HashSet<VirtualFile> roots = Sets.newHashSet();
final Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
roots.addAll(PyUtil.getSourceRoots(module));
}
Collections.addAll(roots, ProjectRootManager.getInstance(project).getContentRoots());
return name.toLowerCase().contains("test") || roots.contains(virtualFile);
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PyInterpreterUsagesCollector method getProjectUsages.
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) throws CollectUsagesException {
Set<UsageDescriptor> result = new HashSet<>();
for (Module m : ModuleManager.getInstance(project).getModules()) {
Sdk pythonSdk = PythonSdkType.findPythonSdk(m);
if (pythonSdk != null) {
String versionString = pythonSdk.getVersionString();
if (StringUtil.isEmpty(versionString)) {
versionString = "unknown version";
}
if (PythonSdkType.isRemote(pythonSdk)) {
versionString = versionString + " (" + getRemoteSuffix(pythonSdk) + ")";
}
if (PythonSdkType.isVirtualEnv(pythonSdk)) {
versionString += " [virtualenv]";
}
if (PythonSdkType.isCondaVirtualEnv(pythonSdk)) {
versionString += " [condavenv]";
}
result.add(new UsageDescriptor(versionString, 1));
}
}
return result;
}
Aggregations