@Override public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { PsiReference reference = getReference(startElement); return file instanceof GoFile && file.getManager().isInProject(file) && reference != null && reference.resolve() == null && !getImportPathVariantsToImport(startElement).isEmpty() && notQualified(startElement); }
@Override public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { // We only perform this action on Ballerina modules since this might cause issues in other modules. Module module = ModuleUtil.findModuleForFile(file.getVirtualFile(), file.getProject()); boolean isBallerinaModule = BallerinaSdkService.getInstance(project).isBallerinaModule(module); if (!isBallerinaModule) { return false; } // If the file contain error elements, do not perform auto import. Since this might affect badly to the user // experience. Collection<PsiErrorElement> errorElements = PsiTreeUtil.findChildrenOfType(file, PsiErrorElement.class); if (!errorElements.isEmpty()) { return false; } PsiReference reference = startElement.getReference(); return file instanceof BallerinaFile && file.getManager().isInProject(file) && (reference == null || reference.resolve() == null); }
@NotNull @Override public Collection<PsiFileSystemItem> computeDefaultContexts() { PsiFile file = getContainingFile(); if (file == null || !file.isValid() || isAbsolutePathReference()) { return Collections.emptyList(); } PsiManager psiManager = file.getManager(); Module module = ModuleUtilCore.findModuleForPsiElement(file); Project project = file.getProject(); LinkedHashSet<VirtualFile> sourceRoots = GoVendoringUtil.isVendoringEnabled(module) ? GoSdkUtil.getVendoringAwareSourcesPathsToLookup(project, module, file.getVirtualFile()) : GoSdkUtil.getSourcesPathsToLookup(project, module); return ContainerUtil.mapNotNull(sourceRoots, psiManager::findDirectory); }
PsiManager psiManager = file.getManager(); Module module = ModuleUtilCore.findModuleForPsiElement(file); Project project = file.getProject();
((PsiModificationTrackerImpl) file.getManager().getModificationTracker()).incCounter();