use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class JUnitConfigurationModel method applyTo.
private void applyTo(final JUnitConfiguration.Data data, final Module module) {
final String testObject = getTestObject();
final String className = getJUnitTextValue(CLASS);
data.TEST_OBJECT = testObject;
if (testObject != JUnitConfiguration.TEST_PACKAGE && testObject != JUnitConfiguration.TEST_PATTERN && testObject != JUnitConfiguration.TEST_DIRECTORY && testObject != JUnitConfiguration.TEST_CATEGORY && testObject != JUnitConfiguration.BY_SOURCE_CHANGES) {
try {
data.METHOD_NAME = getJUnitTextValue(METHOD);
final PsiClass testClass = !myProject.isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, myProject) : null;
if (testClass != null && testClass.isValid()) {
data.setMainClass(testClass);
} else {
data.MAIN_CLASS_NAME = className;
}
} catch (ProcessCanceledException | IndexNotReadyException e) {
data.MAIN_CLASS_NAME = className;
}
} else if (testObject != JUnitConfiguration.BY_SOURCE_CHANGES) {
if (testObject == JUnitConfiguration.TEST_PACKAGE) {
data.PACKAGE_NAME = getJUnitTextValue(ALL_IN_PACKAGE);
} else if (testObject == JUnitConfiguration.TEST_DIRECTORY) {
data.setDirName(getJUnitTextValue(DIR));
} else if (testObject == JUnitConfiguration.TEST_CATEGORY) {
data.setCategoryName(getJUnitTextValue(CATEGORY));
} else {
final LinkedHashSet<String> set = new LinkedHashSet<>();
final String[] patterns = getJUnitTextValue(PATTERN).split("\\|\\|");
for (String pattern : patterns) {
if (pattern.length() > 0) {
set.add(pattern);
}
}
data.setPatterns(set);
}
data.MAIN_CLASS_NAME = "";
data.METHOD_NAME = "";
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class JavaFxControllerClassIndex method findFxmls.
static <T> List<T> findFxmls(ID<String, ?> id, Project project, @NotNull String className, Function<VirtualFile, T> f, GlobalSearchScope scope) {
return ReadAction.compute(() -> {
final Collection<VirtualFile> files;
try {
files = FileBasedIndex.getInstance().getContainingFiles(id, className, GlobalSearchScope.projectScope(project).intersectWith(scope));
} catch (IndexNotReadyException e) {
return Collections.emptyList();
}
if (files.isEmpty())
return Collections.emptyList();
List<T> result = new ArrayList<>();
for (VirtualFile file : files) {
if (!file.isValid())
continue;
final T fFile = f.fun(file);
if (fFile != null) {
result.add(fFile);
}
}
return result;
});
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class JavaDebuggerEvaluator method getExpressionRangeAtOffset.
@Nullable
@Override
public TextRange getExpressionRangeAtOffset(final Project project, final Document document, final int offset, final boolean sideEffectsAllowed) {
final Ref<TextRange> currentRange = Ref.create(null);
PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
try {
PsiElement elementAtCursor = DebuggerUtilsEx.findElementAt(PsiDocumentManager.getInstance(project).getPsiFile(document), offset);
if (elementAtCursor == null || !elementAtCursor.isValid()) {
return;
}
Pair<PsiElement, TextRange> pair = findExpression(elementAtCursor, sideEffectsAllowed);
if (pair != null) {
currentRange.set(pair.getSecond());
}
} catch (IndexNotReadyException ignored) {
}
});
return currentRange.get();
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class IndexCacheManagerImpl method collectVirtualFilesWithWord.
// IMPORTANT!!!
// Since implementation of virtualFileProcessor.process() may call indices directly or indirectly,
// we cannot call it inside FileBasedIndex.processValues() method except in collecting form
// If we do, deadlocks are possible (IDEADEV-42137). Process the files without not holding indices' read lock.
private boolean collectVirtualFilesWithWord(@NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively, @NotNull final Processor<VirtualFile> fileProcessor) {
if (myProject.isDefault()) {
return true;
}
try {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
final FileIndexFacade index = FileIndexFacade.getInstance(myProject);
@Override
public boolean process(final VirtualFile file, final Integer value) {
ProgressIndicatorProvider.checkCanceled();
final int mask = value.intValue();
if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
if (!fileProcessor.process(file))
return false;
}
return true;
}
}, scope);
}
});
} catch (IndexNotReadyException e) {
throw new ProcessCanceledException();
}
}
use of com.intellij.openapi.project.IndexNotReadyException in project intellij-community by JetBrains.
the class IdentifierHighlighterPass method doCollectInformation.
@Override
public void doCollectInformation(@NotNull final ProgressIndicator progress) {
if (myHighlightUsagesHandler != null) {
List<PsiElement> targets = myHighlightUsagesHandler.getTargets();
myHighlightUsagesHandler.computeUsages(targets);
final List<TextRange> readUsages = myHighlightUsagesHandler.getReadUsages();
for (TextRange readUsage : readUsages) {
LOG.assertTrue(readUsage != null, "null text range from " + myHighlightUsagesHandler);
}
myReadAccessRanges.addAll(readUsages);
final List<TextRange> writeUsages = myHighlightUsagesHandler.getWriteUsages();
for (TextRange writeUsage : writeUsages) {
LOG.assertTrue(writeUsage != null, "null text range from " + myHighlightUsagesHandler);
}
myWriteAccessRanges.addAll(writeUsages);
if (!myHighlightUsagesHandler.highlightReferences())
return;
}
int flags = TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED;
PsiElement myTarget;
try {
myTarget = TargetElementUtil.getInstance().findTargetElement(myEditor, flags, myCaretOffset);
} catch (IndexNotReadyException e) {
return;
}
if (myTarget == null) {
if (!PsiDocumentManager.getInstance(myProject).isUncommited(myEditor.getDocument())) {
// when document is committed, try to check injected stuff - it's fast
Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myEditor, myFile, myCaretOffset);
myTarget = TargetElementUtil.getInstance().findTargetElement(injectedEditor, flags, injectedEditor.getCaretModel().getOffset());
}
}
if (myTarget != null) {
highlightTargetUsages(myTarget);
} else {
PsiReference ref = TargetElementUtil.findReference(myEditor);
if (ref instanceof PsiPolyVariantReference) {
if (!ref.getElement().isValid()) {
throw new PsiInvalidElementAccessException(ref.getElement(), "Invalid element in " + ref + " of " + ref.getClass() + "; editor=" + myEditor);
}
ResolveResult[] results = ((PsiPolyVariantReference) ref).multiResolve(false);
if (results.length > 0) {
for (ResolveResult result : results) {
PsiElement target = result.getElement();
if (target != null) {
if (!target.isValid()) {
throw new PsiInvalidElementAccessException(target, "Invalid element returned from " + ref + " of " + ref.getClass() + "; editor=" + myEditor);
}
highlightTargetUsages(target);
}
}
}
}
}
}
Aggregations