use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class MethodDuplicatesHandler method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
final int offset = editor.getCaretModel().getOffset();
final PsiElement element = file.findElementAt(offset);
final PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class);
final String cannotRefactorMessage = getCannotRefactorMessage(member);
if (cannotRefactorMessage != null) {
String message = RefactoringBundle.getCannotRefactorMessage(cannotRefactorMessage);
showErrorMessage(message, project, editor);
return;
}
final AnalysisScope scope = new AnalysisScope(file);
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(RefactoringBundle.message("replace.method.duplicates.scope.chooser.title", REFACTORING_NAME), RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"), project, scope, module != null ? module.getName() : null, false, AnalysisUIOptions.getInstance(project), element);
if (dlg.showAndGet()) {
AnalysisScope selectedScope = dlg.getScope(AnalysisUIOptions.getInstance(project), scope, project, module);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Locate duplicates", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
invokeOnScope(project, member, selectedScope);
}
});
}
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class ForwardDependenciesBuilder method visit.
private void visit(final PsiFile file, final ProjectFileIndex fileIndex, final PsiManager psiManager, int depth) {
final FileViewProvider viewProvider = file.getViewProvider();
if (viewProvider.getBaseLanguage() != file.getLanguage())
return;
if (getScopeOfInterest() != null && !getScopeOfInterest().contains(file))
return;
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
final VirtualFile virtualFile = file.getVirtualFile();
if (indicator != null) {
if (indicator.isCanceled()) {
throw new ProcessCanceledException();
}
indicator.setText(AnalysisScopeBundle.message("package.dependencies.progress.text"));
if (virtualFile != null) {
indicator.setText2(getRelativeToProjectPath(virtualFile));
}
if (myTotalFileCount > 0) {
indicator.setFraction(((double) ++myFileCount) / myTotalFileCount);
}
}
final boolean isInLibrary = virtualFile == null || fileIndex.isInLibrarySource(virtualFile) || fileIndex.isInLibraryClasses(virtualFile);
final Set<PsiFile> collectedDeps = new HashSet<>();
final HashSet<PsiFile> processed = new HashSet<>();
collectedDeps.add(file);
do {
if (depth++ > getTransitiveBorder())
return;
for (PsiFile psiFile : new HashSet<>(collectedDeps)) {
final VirtualFile vFile = psiFile.getVirtualFile();
if (vFile != null) {
if (indicator != null) {
indicator.setText2(getRelativeToProjectPath(vFile));
}
if (!isInLibrary && (fileIndex.isInLibraryClasses(vFile) || fileIndex.isInLibrarySource(vFile))) {
processed.add(psiFile);
}
}
final Set<PsiFile> found = new HashSet<>();
if (!processed.contains(psiFile)) {
processed.add(psiFile);
analyzeFileDependencies(psiFile, new DependencyProcessor() {
@Override
public void process(PsiElement place, PsiElement dependency) {
PsiFile dependencyFile = dependency.getContainingFile();
if (dependencyFile != null) {
if (viewProvider == dependencyFile.getViewProvider())
return;
if (dependencyFile.isPhysical()) {
final VirtualFile virtualFile = dependencyFile.getVirtualFile();
if (virtualFile != null && (fileIndex.isInContent(virtualFile) || fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile))) {
final PsiElement navigationElement = dependencyFile.getNavigationElement();
found.add(navigationElement instanceof PsiFile ? (PsiFile) navigationElement : dependencyFile);
}
}
}
}
});
Set<PsiFile> deps = getDependencies().get(file);
if (deps == null) {
deps = new HashSet<>();
getDependencies().put(file, deps);
}
deps.addAll(found);
getDirectDependencies().put(psiFile, new HashSet<>(found));
collectedDeps.addAll(found);
psiManager.dropResolveCaches();
InjectedLanguageManager.getInstance(file.getProject()).dropFileCaches(file);
}
}
collectedDeps.removeAll(processed);
} while (isTransitive() && !collectedDeps.isEmpty());
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class InspectionEngine method inspectElements.
// returns map tool.shortName -> list of descriptors found
@NotNull
static Map<String, List<ProblemDescriptor>> inspectElements(@NotNull List<LocalInspectionToolWrapper> toolWrappers, @NotNull final PsiFile file, @NotNull final InspectionManager iManager, final boolean isOnTheFly, boolean failFastOnAcquireReadAction, @NotNull ProgressIndicator indicator, @NotNull final List<PsiElement> elements, @NotNull final Set<String> elementDialectIds) {
TextRange range = file.getTextRange();
final LocalInspectionToolSession session = new LocalInspectionToolSession(file, range.getStartOffset(), range.getEndOffset());
Map<LocalInspectionToolWrapper, Set<String>> toolToSpecifiedDialectIds = getToolsToSpecifiedLanguages(toolWrappers);
List<Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedDialectIds.entrySet());
final Map<String, List<ProblemDescriptor>> resultDescriptors = new ConcurrentHashMap<>();
Processor<Entry<LocalInspectionToolWrapper, Set<String>>> processor = entry -> {
ProblemsHolder holder = new ProblemsHolder(iManager, file, isOnTheFly);
final LocalInspectionTool tool = entry.getKey().getTool();
Set<String> dialectIdsSpecifiedForTool = entry.getValue();
createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, elementDialectIds, dialectIdsSpecifiedForTool);
tool.inspectionFinished(session, holder);
if (holder.hasResults()) {
resultDescriptors.put(tool.getShortName(), ContainerUtil.filter(holder.getResults(), descriptor -> {
PsiElement element = descriptor.getPsiElement();
return element == null || !SuppressionUtil.inspectionResultSuppressed(element, tool);
}));
}
return true;
};
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, failFastOnAcquireReadAction, processor);
return resultDescriptors;
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class TreeModelBuilder method buildFileNode.
@Nullable
private PackageDependenciesNode buildFileNode(final VirtualFile file, @Nullable PackageDependenciesNode parent) {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
((PanelProgressIndicator) indicator).update(SCANNING_PACKAGES_MESSAGE, false, ((double) myScannedFileCount++) / myTotalFileCount);
}
boolean isMarked = myMarker != null && myMarker.isMarked(file);
if (isMarked)
myMarkedFileCount++;
if (isMarked || myAddUnmarkedFiles) {
PackageDependenciesNode dirNode = parent != null ? parent : getFileParentNode(file);
if (dirNode == null)
return null;
if (myShowFiles) {
FileNode fileNode = new FileNode(file, myProject, isMarked);
dirNode.add(fileNode);
} else {
dirNode.addFile(file, isMarked);
}
return dirNode;
}
return null;
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class FindJarFix method findJarsForFqn.
private void findJarsForFqn(final String fqn, final Editor editor) {
final Map<String, String> libs = new HashMap<>();
final Runnable runnable = () -> {
try {
final DOMParser parser = new DOMParser();
parser.parse(CLASS_ROOT_URL + fqn.replace('.', '/') + CLASS_PAGE_EXT);
final Document doc = parser.getDocument();
if (doc != null) {
final NodeList links = doc.getElementsByTagName(LINK_TAG_NAME);
for (int i = 0; i < links.getLength(); i++) {
final Node link = links.item(i);
final String libName = link.getTextContent();
final NamedNodeMap attributes = link.getAttributes();
if (attributes != null) {
final Node href = attributes.getNamedItem(LINK_ATTR_NAME);
if (href != null) {
final String pathToJar = href.getTextContent();
if (pathToJar != null && (pathToJar.startsWith("/jar/") || pathToJar.startsWith("/class/../"))) {
libs.put(libName, SERVICE_URL + pathToJar);
}
}
}
}
}
} catch (IOException ignore) {
//
} catch (Exception e) {
//
LOG.warn(e);
}
};
final Task.Modal task = new Task.Modal(editor.getProject(), "Looking for libraries", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
runUncanceledRunnableWithProgress(runnable, indicator);
}
@Override
public void onSuccess() {
super.onSuccess();
if (libs.isEmpty()) {
HintManager.getInstance().showInformationHint(editor, "No libraries found for '" + fqn + "'");
} else {
final ArrayList<String> variants = new ArrayList<>(libs.keySet());
Collections.sort(variants, (o1, o2) -> o1.compareTo(o2));
final JBList libNames = new JBList(variants);
libNames.installCellRenderer(o -> new JLabel(o.toString(), PlatformIcons.JAR_ICON, SwingConstants.LEFT));
if (libs.size() == 1) {
final String jarName = libs.keySet().iterator().next();
final String url = libs.get(jarName);
initiateDownload(url, jarName);
} else {
JBPopupFactory.getInstance().createListPopupBuilder(libNames).setTitle("Select a JAR file").setItemChoosenCallback(() -> {
final Object value = libNames.getSelectedValue();
if (value instanceof String) {
final String jarName = (String) value;
final String url = libs.get(jarName);
if (url != null) {
initiateDownload(url, jarName);
}
}
}).createPopup().showInBestPositionFor(editor);
}
}
}
};
ProgressManager.getInstance().run(task);
}
Aggregations