use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class OccurenceNavigatorActionBase method update.
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null) {
presentation.setEnabled(false);
// make it invisible only in main menu to avoid initial invisibility in toolbars
presentation.setVisible(!ActionPlaces.isMainMenuOrActionSearch(event.getPlace()));
return;
}
OccurenceNavigator navigator = getNavigator(event.getDataContext());
if (navigator == null) {
presentation.setEnabled(false);
// make it invisible only in main menu to avoid initial invisibility in toolbars
presentation.setVisible(!ActionPlaces.isMainMenuOrActionSearch(event.getPlace()));
return;
}
presentation.setVisible(true);
try {
presentation.setEnabled(hasOccurenceToGo(navigator));
presentation.setText(getDescription(navigator));
} catch (IndexNotReadyException e) {
presentation.setEnabled(false);
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class DependenciesHandlerBase method perform.
private void perform(List<DependenciesBuilder> builders) {
try {
PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
for (AnalysisScope scope : myScopes) {
builders.add(createDependenciesBuilder(scope));
}
for (DependenciesBuilder builder : builders) {
builder.analyze();
}
snapshot.logResponsivenessSinceCreation("Dependency analysis");
} catch (IndexNotReadyException e) {
DumbService.getInstance(myProject).showDumbModeNotification("Analyze dependencies is not available until indices are ready");
throw new ProcessCanceledException();
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class ContributorsBasedGotoByModel method processNames.
@Override
public void processNames(final Processor<String> nameProcessor, final boolean checkBoxState) {
long start = System.currentTimeMillis();
List<ChooseByNameContributor> liveContribs = filterDumb(myContributors);
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
Processor<ChooseByNameContributor> processor = new ReadActionProcessor<ChooseByNameContributor>() {
@Override
public boolean processInReadAction(@NotNull ChooseByNameContributor contributor) {
try {
if (!myProject.isDisposed()) {
long contributorStarted = System.currentTimeMillis();
final TIntHashSet filter = new TIntHashSet(1000);
myContributorToItsSymbolsMap.put(contributor, filter);
if (contributor instanceof ChooseByNameContributorEx) {
((ChooseByNameContributorEx) contributor).processNames(s -> {
if (nameProcessor.process(s)) {
filter.add(s.hashCode());
}
return true;
}, FindSymbolParameters.searchScopeFor(myProject, checkBoxState), getIdFilter(checkBoxState));
} else {
String[] names = contributor.getNames(myProject, checkBoxState);
for (String element : names) {
if (nameProcessor.process(element)) {
filter.add(element.hashCode());
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(contributor + " for " + (System.currentTimeMillis() - contributorStarted));
}
}
} catch (ProcessCanceledException | IndexNotReadyException ex) {
// index corruption detected, ignore
} catch (Exception ex) {
LOG.error(ex);
}
return true;
}
};
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(liveContribs, indicator, true, processor)) {
throw new ProcessCanceledException();
}
if (indicator != null) {
indicator.checkCanceled();
}
long finish = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug("processNames(): " + (finish - start) + "ms;");
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class PsiViewerDialog method init.
@Override
protected void init() {
initMnemonics();
initTree(myPsiTree);
final TreeCellRenderer renderer = myPsiTree.getCellRenderer();
myPsiTree.setCellRenderer(new TreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
final Component c = renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof ViewerNodeDescriptor) {
final Object element = ((ViewerNodeDescriptor) userObject).getElement();
if (c instanceof NodeRenderer) {
((NodeRenderer) c).setToolTipText(element == null ? null : element.getClass().getName());
}
if (element instanceof PsiElement && FileContextUtil.getFileContext(((PsiElement) element).getContainingFile()) != null || element instanceof ViewerTreeStructure.Inject) {
final TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
c.setBackground(attr.getBackgroundColor());
}
}
}
return c;
}
});
myPsiTreeBuilder = new ViewerTreeBuilder(myProject, myPsiTree);
Disposer.register(getDisposable(), myPsiTreeBuilder);
myPsiTree.addTreeSelectionListener(new MyPsiTreeSelectionListener());
final GoToListener listener = new GoToListener();
myRefs.addKeyListener(listener);
myRefs.addMouseListener(listener);
myRefs.getSelectionModel().addListSelectionListener(listener);
myRefs.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
try {
if (resolve(index) == null) {
comp.setForeground(JBColor.RED);
}
} catch (IndexNotReadyException ignore) {
}
return comp;
}
});
initTree(myBlockTree);
myEditor.getSettings().setFoldingOutlineShown(false);
myEditor.getDocument().addDocumentListener(myEditorListener);
myEditor.getSelectionModel().addSelectionListener(myEditorListener);
myEditor.getCaretModel().addCaretListener(myEditorListener);
getPeer().getWindow().setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
@Override
public Component getInitialComponent(@NotNull Window window) {
return myEditor.getComponent();
}
});
PsiViewerSettings settings = PsiViewerSettings.getSettings();
VirtualFile file = myExternalDocument ? FileDocumentManager.getInstance().getFile(myEditor.getDocument()) : null;
Language curLanguage = LanguageUtil.getLanguageForPsi(myProject, file);
String type = curLanguage != null ? curLanguage.getDisplayName() : settings.type;
SourceWrapper lastUsed = null;
for (PsiViewerExtension extension : Extensions.getExtensions(PsiViewerExtension.EP_NAME)) {
SourceWrapper wrapper = new SourceWrapper(extension);
mySourceWrappers.add(wrapper);
}
Set<FileType> allFileTypes = ContainerUtil.newHashSet();
Collections.addAll(allFileTypes, FileTypeManager.getInstance().getRegisteredFileTypes());
for (Language language : Language.getRegisteredLanguages()) {
FileType fileType = language.getAssociatedFileType();
if (fileType != null) {
allFileTypes.add(fileType);
}
}
for (FileType fileType : allFileTypes) {
if (fileType != StdFileTypes.GUI_DESIGNER_FORM && fileType != StdFileTypes.IDEA_MODULE && fileType != StdFileTypes.IDEA_PROJECT && fileType != StdFileTypes.IDEA_WORKSPACE && fileType != FileTypes.ARCHIVE && fileType != FileTypes.UNKNOWN && fileType != FileTypes.PLAIN_TEXT && !(fileType instanceof AbstractFileType) && !fileType.isBinary() && !fileType.isReadOnly()) {
final SourceWrapper wrapper = new SourceWrapper(fileType);
mySourceWrappers.add(wrapper);
if (lastUsed == null && wrapper.getText().equals(type))
lastUsed = wrapper;
if (curLanguage != null && wrapper.myFileType == curLanguage.getAssociatedFileType()) {
lastUsed = wrapper;
}
}
}
myFileTypeComboBox.setModel(new CollectionComboBoxModel<>(ContainerUtil.newArrayList(mySourceWrappers), lastUsed));
myFileTypeComboBox.setRenderer(new ListCellRendererWrapper<SourceWrapper>() {
@Override
public void customize(JList list, SourceWrapper value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.getText());
setIcon(value.getIcon());
}
}
});
new ComboboxSpeedSearch(myFileTypeComboBox) {
@Override
protected String getElementText(Object element) {
return element instanceof SourceWrapper ? ((SourceWrapper) element).getText() : null;
}
};
myFileTypeComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
updateDialectsCombo(null);
updateExtensionsCombo();
updateEditor();
}
});
myDialectComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
updateEditor();
}
});
new ComboboxSpeedSearch(myDialectComboBox) {
@Override
protected String getElementText(Object element) {
return element instanceof Language ? ((Language) element).getDisplayName() : "<default>";
}
};
myFileTypeComboBox.addFocusListener(new AutoExpandFocusListener(myFileTypeComboBox));
if (!myExternalDocument && lastUsed == null && mySourceWrappers.size() > 0) {
myFileTypeComboBox.setSelectedIndex(0);
}
myDialectComboBox.setRenderer(new ListCellRendererWrapper<Language>() {
@Override
public void customize(final JList list, final Language value, final int index, final boolean selected, final boolean hasFocus) {
setText(value != null ? value.getDisplayName() : "<default>");
}
});
myDialectComboBox.addFocusListener(new AutoExpandFocusListener(myDialectComboBox));
myExtensionComboBox.setRenderer(new ListCellRendererWrapper<String>() {
@Override
public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
if (value != null)
setText("." + value);
}
});
myExtensionComboBox.addFocusListener(new AutoExpandFocusListener(myExtensionComboBox));
final ViewerTreeStructure psiTreeStructure = getTreeStructure();
myShowWhiteSpacesBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
psiTreeStructure.setShowWhiteSpaces(myShowWhiteSpacesBox.isSelected());
myPsiTreeBuilder.queueUpdate();
}
});
myShowTreeNodesCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
psiTreeStructure.setShowTreeNodes(myShowTreeNodesCheckBox.isSelected());
myPsiTreeBuilder.queueUpdate();
}
});
myShowWhiteSpacesBox.setSelected(settings.showWhiteSpaces);
psiTreeStructure.setShowWhiteSpaces(settings.showWhiteSpaces);
myShowTreeNodesCheckBox.setSelected(settings.showTreeNodes);
psiTreeStructure.setShowTreeNodes(settings.showTreeNodes);
myShowBlocksCheckBox.setSelected(settings.showBlocks);
myBlockStructurePanel.setVisible(settings.showBlocks);
myShowBlocksCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
if (!myShowBlocksCheckBox.isSelected()) {
settings.blockRefDividerLocation = myBlockRefSplitPane.getDividerLocation();
} else {
myBlockRefSplitPane.setDividerLocation(settings.blockRefDividerLocation);
}
myBlockStructurePanel.setVisible(myShowBlocksCheckBox.isSelected());
myBlockStructurePanel.repaint();
}
});
myTextPanel.setLayout(new BorderLayout());
myTextPanel.add(myEditor.getComponent(), BorderLayout.CENTER);
updateDialectsCombo(settings.dialect);
updateExtensionsCombo();
registerCustomKeyboardActions();
final Dimension size = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject);
if (size == null) {
DimensionService.getInstance().setSize(getDimensionServiceKey(), JBUI.size(800, 600));
}
myTextSplit.setDividerLocation(settings.textDividerLocation);
myTreeSplit.setDividerLocation(settings.treeDividerLocation);
myBlockRefSplitPane.setDividerLocation(settings.blockRefDividerLocation);
updateEditor();
super.init();
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class AntRenameHandler method getPsiElementsIn.
@Nullable
private static PsiElement[] getPsiElementsIn(final Editor editor, final PsiFile psiFile) {
try {
final PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference == null) {
return null;
}
final Collection<PsiElement> candidates = TargetElementUtil.getInstance().getTargetCandidates(reference);
return ContainerUtil.toArray(candidates, new PsiElement[candidates.size()]);
} catch (IndexNotReadyException e) {
return null;
}
}
Aggregations