use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class ShowByteCodeAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = e.getProject();
if (project == null)
return;
final Editor editor = e.getData(CommonDataKeys.EDITOR);
final PsiElement psiElement = getPsiElement(dataContext, project, editor);
if (psiElement == null)
return;
if (ByteCodeViewerManager.getContainingClass(psiElement) == null) {
Messages.showWarningDialog(project, "The selection should contain a class", "Unable to Find Class to Show Bytecode");
return;
}
final String psiElementTitle = ByteCodeViewerManager.getInstance(project).getTitle(psiElement);
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
if (virtualFile == null)
return;
final RelativePoint bestPopupLocation = JBPopupFactory.getInstance().guessBestPopupLocation(dataContext);
final SmartPsiElementPointer element = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Looking for Bytecode...") {
private String myByteCode;
private String myErrorMessage;
private String myErrorTitle;
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile) && isMarkedForCompilation(project, virtualFile)) {
myErrorMessage = "Unable to show bytecode for '" + psiElementTitle + "'. Class file does not exist or is out-of-date.";
myErrorTitle = "Class File Out-Of-Date";
} else {
myByteCode = ReadAction.compute(() -> ByteCodeViewerManager.getByteCode(psiElement));
}
}
@Override
public void onSuccess() {
if (project.isDisposed())
return;
if (myErrorMessage != null && myTitle != null) {
Messages.showWarningDialog(project, myErrorMessage, myErrorTitle);
return;
}
final PsiElement targetElement = element.getElement();
if (targetElement == null)
return;
final ByteCodeViewerManager codeViewerManager = ByteCodeViewerManager.getInstance(project);
if (codeViewerManager.hasActiveDockedDocWindow()) {
codeViewerManager.doUpdateComponent(targetElement, myByteCode);
} else {
if (myByteCode == null) {
Messages.showErrorDialog(project, "Unable to parse class file for '" + psiElementTitle + "'.", "Bytecode not Found");
return;
}
final ByteCodeViewerComponent component = new ByteCodeViewerComponent(project, null);
component.setText(myByteCode, targetElement);
Processor<JBPopup> pinCallback = popup -> {
codeViewerManager.recreateToolWindow(targetElement, targetElement);
popup.cancel();
return false;
};
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, null).setProject(project).setDimensionServiceKey(project, ShowByteCodeAction.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(LookupManager.getActiveLookup(editor) == null).setTitle(psiElementTitle + " Bytecode").setCouldPin(pinCallback).createPopup();
Disposer.register(popup, component);
if (editor != null) {
popup.showInBestPositionFor(editor);
} else {
popup.show(bestPopupLocation);
}
}
}
});
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class XsltIncludeIndex method _process.
private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>) file -> psiManager.findFile(file));
for (final PsiFile psiFile : psiFiles) {
if (XsltSupport.isXsltFile(psiFile)) {
if (!processor.process((XmlFile) psiFile)) {
return false;
}
}
}
return true;
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class ConvertParameterToMapEntryIntention method collectOwnerOccurrences.
private static boolean collectOwnerOccurrences(final Project project, final GrParametersOwner owner, final Collection<PsiElement> occurrences) {
final PsiElement namedElem = getReferencedElement(owner);
if (namedElem == null)
return true;
final Ref<Boolean> result = new Ref<>(true);
final Task task = new Task.Modal(project, GroovyIntentionsBundle.message("find.method.ro.closure.usages.0", owner instanceof GrClosableBlock ? CLOSURE_CAPTION : METHOD_CAPTION), true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
final Collection<PsiReference> references = Collections.synchronizedSet(new HashSet<PsiReference>());
final Processor<PsiReference> consumer = psiReference -> {
references.add(psiReference);
return true;
};
ReferencesSearch.search(namedElem).forEach(consumer);
boolean isProperty = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return namedElem instanceof GrField && ((GrField) namedElem).isProperty();
}
});
if (isProperty) {
final GrAccessorMethod[] getters = ApplicationManager.getApplication().runReadAction(new Computable<GrAccessorMethod[]>() {
@Override
public GrAccessorMethod[] compute() {
return ((GrField) namedElem).getGetters();
}
});
for (GrAccessorMethod getter : getters) {
MethodReferencesSearch.search(getter).forEach(consumer);
}
}
for (final PsiReference reference : references) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = reference.getElement();
if (element != null) {
occurrences.add(element);
}
});
}
}
@Override
public void onCancel() {
result.set(false);
}
@Override
public void onThrowable(@NotNull Throwable error) {
super.onThrowable(error);
result.set(false);
}
@Override
public void onSuccess() {
result.set(true);
}
};
ProgressManager.getInstance().run(task);
return result.get().booleanValue();
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class JavaFxMethodSearcher method searchMethod.
private static void searchMethod(@NotNull PsiMethod psiMethod, @NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final Project project = PsiUtilCore.getProjectInReadAction(psiMethod);
final SearchScope scope = ReadAction.compute(queryParameters::getEffectiveSearchScope);
if (scope instanceof LocalSearchScope) {
final VirtualFile[] vFiles = ((LocalSearchScope) scope).getVirtualFiles();
for (VirtualFile vFile : vFiles) {
if (JavaFxFileTypeFactory.isFxml(vFile)) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
if (psiFile != null) {
final Boolean goOn = ReadAction.compute(() -> searchMethodInFile(psiMethod, psiFile, consumer));
if (!goOn)
break;
}
}
}
} else if (scope instanceof GlobalSearchScope) {
final String propertyName = ReadAction.compute(() -> PropertyUtil.getPropertyName(psiMethod.getName()));
if (propertyName == null)
return;
final String className = ReadAction.compute(() -> {
final PsiClass psiClass = psiMethod.getContainingClass();
return psiClass != null ? psiClass.getName() : null;
});
if (className == null)
return;
final GlobalSearchScope fxmlScope = new JavaFxScopeEnlarger.GlobalFxmlSearchScope((GlobalSearchScope) scope);
final VirtualFile[] filteredFiles = ReadAction.compute(() -> CacheManager.SERVICE.getInstance(project).getVirtualFilesWithWord(className, UsageSearchContext.IN_PLAIN_TEXT, fxmlScope, true));
if (ArrayUtil.isEmpty(filteredFiles))
return;
final GlobalSearchScope filteredScope = GlobalSearchScope.filesScope(project, ContainerUtil.newHashSet(filteredFiles));
ApplicationManager.getApplication().runReadAction((Runnable) () -> CacheManager.SERVICE.getInstance(project).processFilesWithWord(file -> searchMethodInFile(psiMethod, file, consumer), propertyName, UsageSearchContext.IN_PLAIN_TEXT, filteredScope, true));
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class MavenDomProjectProcessorUtils method searchDependencyUsages.
@NotNull
public static Set<MavenDomDependency> searchDependencyUsages(@NotNull final MavenDomProjectModel model, @NotNull final DependencyConflictId dependencyId, @NotNull final Set<MavenDomDependency> excludes) {
Project project = model.getManager().getProject();
final Set<MavenDomDependency> usages = new HashSet<>();
Processor<MavenDomProjectModel> collectProcessor = mavenDomProjectModel -> {
for (MavenDomDependency domDependency : mavenDomProjectModel.getDependencies().getDependencies()) {
if (excludes.contains(domDependency))
continue;
if (dependencyId.equals(DependencyConflictId.create(domDependency))) {
usages.add(domDependency);
}
}
return false;
};
processChildrenRecursively(model, collectProcessor, project, new HashSet<>(), true);
return usages;
}
Aggregations