use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class AbstractTreeUi method getChildrenFor.
//todo [kirillk] temporary consistency check
private Object[] getChildrenFor(final Object element) {
final Ref<Object[]> passOne = new Ref<>();
try (LockToken ignored = acquireLock()) {
execute(new TreeRunnable("AbstractTreeUi.getChildrenFor") {
@Override
public void perform() {
passOne.set(getTreeStructure().getChildElements(element));
}
});
} catch (IndexNotReadyException e) {
warnOnIndexNotReady(e);
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
if (!Registry.is("ide.tree.checkStructure"))
return passOne.get();
final Object[] passTwo = getTreeStructure().getChildElements(element);
final HashSet<Object> two = new HashSet<>(Arrays.asList(passTwo));
if (passOne.get().length != passTwo.length) {
LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
} else {
for (Object eachInOne : passOne.get()) {
if (!two.contains(eachInOne)) {
LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
break;
}
}
}
return passOne.get();
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class AbstractTreeUi method update.
private boolean update(@NotNull final NodeDescriptor nodeDescriptor) {
try (LockToken ignored = acquireLock()) {
final AtomicBoolean update = new AtomicBoolean();
execute(new TreeRunnable("AbstractTreeUi.update") {
@Override
public void perform() {
nodeDescriptor.setUpdateCount(nodeDescriptor.getUpdateCount() + 1);
update.set(getBuilder().updateNodeDescriptor(nodeDescriptor));
}
});
return update.get();
} catch (IndexNotReadyException e) {
warnOnIndexNotReady(e);
return false;
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class FoldingPolicy method isCollapseByDefault.
public static boolean isCollapseByDefault(PsiElement element) {
final Language lang = element.getLanguage();
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
try {
return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode());
} catch (IndexNotReadyException e) {
LOG.error(e);
return false;
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class GotoTargetHandler method show.
private void show(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull final GotoData gotoData) {
final PsiElement[] targets = gotoData.targets;
final List<AdditionalAction> additionalActions = gotoData.additionalActions;
if (targets.length == 0 && additionalActions.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
return;
}
boolean finished = gotoData.listUpdaterTask == null || gotoData.listUpdaterTask.isFinished();
if (targets.length == 1 && additionalActions.isEmpty() && finished) {
navigateToElement(targets[0]);
return;
}
for (PsiElement eachTarget : targets) {
gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
}
final String name = ((PsiNamedElement) gotoData.source).getName();
final String title = getChooserTitle(gotoData.source, name, targets.length, finished);
if (shouldSortTargets()) {
Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
}
List<Object> allElements = new ArrayList<>(targets.length + additionalActions.size());
Collections.addAll(allElements, targets);
allElements.addAll(additionalActions);
final JBList list = new JBList(new CollectionListModel<>(allElements));
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setFont(EditorUtil.getEditorFont());
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value == null)
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof AdditionalAction) {
return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
final Runnable runnable = () -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
Object[] selectedElements = list.getSelectedValues();
for (Object element : selectedElements) {
if (element instanceof AdditionalAction) {
((AdditionalAction) element).execute();
} else {
Navigatable nav = element instanceof Navigatable ? (Navigatable) element : EditSourceUtil.getDescriptor((PsiElement) element);
try {
if (nav != null && nav.canNavigate()) {
navigateToElement(nav);
}
} catch (IndexNotReadyException e) {
DumbService.getInstance(project).showDumbModeNotification("Navigation is not available while indexing");
}
}
}
};
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setFilteringEnabled(o -> {
if (o instanceof AdditionalAction) {
return ((AdditionalAction) o).getText();
}
return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
});
final Ref<UsageView> usageView = new Ref<>();
final JBPopup popup = builder.setTitle(title).setItemChoosenCallback(runnable).setMovable(true).setCancelCallback(() -> {
HintUpdateSupply.hideHint(list);
final ListBackgroundUpdaterTask task = gotoData.listUpdaterTask;
if (task != null) {
task.cancelTask();
}
return true;
}).setCouldPin(popup1 -> {
usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), gotoData.source.getProject()));
popup1.cancel();
return false;
}).setAdText(getAdText(gotoData.source, targets.length)).createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
if (gotoData.listUpdaterTask != null) {
Alarm alarm = new Alarm(popup);
alarm.addRequest(() -> popup.showInBestPositionFor(editor), 300);
gotoData.listUpdaterTask.init((AbstractPopup) popup, list, usageView);
ProgressManager.getInstance().run(gotoData.listUpdaterTask);
} else {
popup.showInBestPositionFor(editor);
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class GotoDeclarationAction method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
DumbService.getInstance(project).setAlternativeResolveEnabled(true);
try {
int offset = editor.getCaretModel().getOffset();
PsiElement[] elements = underModalProgress(project, "Resolving Reference...", () -> findAllTargetElements(project, editor, offset));
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.declaration");
if (elements.length != 1) {
if (elements.length == 0 && suggestCandidates(TargetElementUtil.findReference(editor, offset)).isEmpty()) {
PsiElement element = findElementToShowUsagesOf(editor, editor.getCaretModel().getOffset());
if (startFindUsages(editor, element)) {
return;
}
//disable 'no declaration found' notification for keywords
final PsiElement elementAtCaret = file.findElementAt(offset);
if (elementAtCaret != null) {
final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(elementAtCaret.getLanguage());
if (namesValidator != null && namesValidator.isKeyword(elementAtCaret.getText(), project)) {
return;
}
}
}
chooseAmbiguousTarget(editor, offset, elements, file);
return;
}
PsiElement element = elements[0];
if (element == findElementToShowUsagesOf(editor, editor.getCaretModel().getOffset()) && startFindUsages(editor, element)) {
return;
}
PsiElement navElement = element.getNavigationElement();
navElement = TargetElementUtil.getInstance().getGotoDeclarationTarget(element, navElement);
if (navElement != null) {
gotoTargetElement(navElement, editor, file);
}
} catch (IndexNotReadyException e) {
DumbService.getInstance(project).showDumbModeNotification("Navigation is not available here during index update");
} finally {
DumbService.getInstance(project).setAlternativeResolveEnabled(false);
}
}
Aggregations