use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class HighlightVisitorImpl method highlightReferencedMethodOrClassName.
private void highlightReferencedMethodOrClassName(@NotNull PsiJavaCodeReferenceElement element, PsiElement resolved) {
PsiElement parent = element.getParent();
final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
if (parent instanceof PsiMethodCallExpression) {
PsiMethod method = ((PsiMethodCallExpression) parent).resolveMethod();
PsiElement methodNameElement = element.getReferenceNameElement();
if (method != null && methodNameElement != null && !(methodNameElement instanceof PsiKeyword)) {
myHolder.add(HighlightNamesUtil.highlightMethodName(method, methodNameElement, false, colorsScheme));
myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(element, colorsScheme));
}
} else if (parent instanceof PsiConstructorCall) {
try {
PsiMethod method = ((PsiConstructorCall) parent).resolveConstructor();
PsiMember methodOrClass = method != null ? method : resolved instanceof PsiClass ? (PsiClass) resolved : null;
if (methodOrClass != null) {
final PsiElement referenceNameElement = element.getReferenceNameElement();
if (referenceNameElement != null) {
// exclude type parameters from the highlighted text range
TextRange range = referenceNameElement.getTextRange();
myHolder.add(HighlightNamesUtil.highlightMethodName(methodOrClass, referenceNameElement, range, colorsScheme, false));
}
}
} catch (IndexNotReadyException ignored) {
}
} else if (resolved instanceof PsiPackage) {
// highlight package (and following dot) as a class
myHolder.add(HighlightNamesUtil.highlightPackage(resolved, element, colorsScheme));
} else if (resolved instanceof PsiClass) {
myHolder.add(HighlightNamesUtil.highlightClassName((PsiClass) resolved, element, colorsScheme));
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class AutoPopupController method autoPopupParameterInfo.
public void autoPopupParameterInfo(@NotNull final Editor editor, @Nullable final PsiElement highlightedMethod) {
if (ApplicationManager.getApplication().isUnitTestMode())
return;
if (DumbService.isDumb(myProject))
return;
if (PowerSaveMode.isEnabled())
return;
ApplicationManager.getApplication().assertIsDispatchThread();
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
if (settings.AUTO_POPUP_PARAMETER_INFO) {
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
PsiFile file = documentManager.getPsiFile(editor.getDocument());
if (file == null)
return;
if (!documentManager.isUncommited(editor.getDocument())) {
file = documentManager.getPsiFile(InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file).getDocument());
if (file == null)
return;
}
final PsiFile file1 = file;
Runnable request = () -> {
if (!myProject.isDisposed() && !DumbService.isDumb(myProject) && !editor.isDisposed() && editor.getComponent().isShowing()) {
int lbraceOffset = editor.getCaretModel().getOffset() - 1;
try {
ShowParameterInfoHandler.invoke(myProject, editor, file1, lbraceOffset, highlightedMethod, false);
} catch (IndexNotReadyException ignored) {
//anything can happen on alarm
}
}
};
addRequest(() -> documentManager.performLaterWhenAllCommitted(request), settings.PARAMETER_INFO_DELAY);
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class AbstractLayoutCodeProcessor method runProcessFile.
private void runProcessFile(@NotNull final PsiFile file) {
Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);
if (document == null) {
return;
}
if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) {
Messages.showMessageDialog(myProject, PsiBundle.message("cannot.modify.a.read.only.file", file.getName()), CodeInsightBundle.message("error.dialog.readonly.file.title"), Messages.getErrorIcon());
return;
}
final Ref<FutureTask<Boolean>> writeActionRunnable = new Ref<>();
Runnable readAction = () -> {
if (!checkFileWritable(file))
return;
try {
FutureTask<Boolean> writeTask = preprocessFile(file, myProcessChangedTextOnly);
writeActionRunnable.set(writeTask);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
};
Runnable writeAction = () -> {
if (writeActionRunnable.isNull())
return;
FutureTask<Boolean> task = writeActionRunnable.get();
task.run();
try {
task.get();
} catch (CancellationException ignored) {
} catch (ExecutionException e) {
if (e.getCause() instanceof IndexNotReadyException) {
throw (IndexNotReadyException) e.getCause();
}
LOG.error(e);
} catch (Exception e) {
LOG.error(e);
}
};
runLayoutCodeProcess(readAction, writeAction);
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method runGlobalTools.
private void runGlobalTools(@NotNull final AnalysisScope scope, @NotNull final InspectionManager inspectionManager, @NotNull List<Tools> globalTools, boolean isOfflineInspections) {
LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed() || isOfflineInspections, "Must not run under read action, too unresponsive");
final List<InspectionToolWrapper> needRepeatSearchRequest = new ArrayList<>();
final boolean canBeExternalUsages = !(scope.getScopeType() == AnalysisScope.PROJECT && scope.isIncludeTestSource());
for (Tools tools : globalTools) {
for (ScopeToolState state : tools.getTools()) {
final InspectionToolWrapper toolWrapper = state.getTool();
final GlobalInspectionTool tool = (GlobalInspectionTool) toolWrapper.getTool();
final InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
try {
if (tool.isGraphNeeded()) {
try {
((RefManagerImpl) getRefManager()).findAllDeclarations();
} catch (Throwable e) {
getStdJobDescriptors().BUILD_GRAPH.setDoneAmount(0);
throw e;
}
}
ApplicationManager.getApplication().runReadAction(() -> {
tool.runInspection(scope, inspectionManager, this, toolPresentation);
//skip phase when we are sure that scope already contains everything, unused declaration though needs to proceed with its suspicious code
if ((canBeExternalUsages || tool.getAdditionalJobs(this) != null) && tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) {
needRepeatSearchRequest.add(toolWrapper);
}
});
} catch (ProcessCanceledException | IndexNotReadyException e) {
throw e;
} catch (Throwable e) {
LOG.error(e);
}
}
}
for (GlobalInspectionContextExtension extension : myExtensions.values()) {
try {
extension.performPostRunActivities(needRepeatSearchRequest, this);
} catch (ProcessCanceledException | IndexNotReadyException e) {
throw e;
} catch (Throwable e) {
LOG.error(e);
}
}
addProblemsToView(globalTools);
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class DebuggerUtils method findClass.
@Nullable
public static PsiClass findClass(@NotNull final String className, @NotNull Project project, final GlobalSearchScope scope) {
ApplicationManager.getApplication().assertReadAccessAllowed();
try {
if (getArrayClass(className) != null) {
return JavaPsiFacade.getInstance(project).getElementFactory().getArrayClass(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel());
}
if (project.isDefault()) {
return null;
}
PsiManager psiManager = PsiManager.getInstance(project);
PsiClass psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, scope);
if (psiClass == null) {
GlobalSearchScope globalScope = GlobalSearchScope.allScope(project);
if (!globalScope.equals(scope)) {
psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, globalScope);
}
}
return psiClass;
} catch (IndexNotReadyException ignored) {
return null;
}
}
Aggregations