mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
EA-220955 - F: NullityInferrer.collect
GitOrigin-RevId: 6171c7deed0e65c038fb40c2d398ab3b6f52e1c1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ffa1aa21cb
commit
a4f30d2e8b
@@ -178,26 +178,30 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
|
||||
final int fileCount) {
|
||||
final NullityInferrer inferrer = new NullityInferrer(isAnnotateLocalVariables(), project);
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final Runnable searchForUsages = () -> scope.accept(new PsiElementVisitor() {
|
||||
int myFileCount;
|
||||
final List<UsageInfo> usages = new ArrayList<>();
|
||||
final Runnable searchForUsages = () -> {
|
||||
scope.accept(new PsiElementVisitor() {
|
||||
int myFileCount;
|
||||
|
||||
@Override
|
||||
public void visitFile(@NotNull final PsiFile file) {
|
||||
myFileCount++;
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
final FileViewProvider viewProvider = psiManager.findViewProvider(virtualFile);
|
||||
final Document document = viewProvider == null ? null : viewProvider.getDocument();
|
||||
if (document == null || virtualFile.getFileType().isBinary()) return; //do not inspect binary files
|
||||
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project));
|
||||
progressIndicator.setFraction(((double)myFileCount) / fileCount);
|
||||
@Override
|
||||
public void visitFile(@NotNull final PsiFile file) {
|
||||
myFileCount++;
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
final FileViewProvider viewProvider = psiManager.findViewProvider(virtualFile);
|
||||
final Document document = viewProvider == null ? null : viewProvider.getDocument();
|
||||
if (document == null || virtualFile.getFileType().isBinary()) return; //do not inspect binary files
|
||||
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project));
|
||||
progressIndicator.setFraction(((double)myFileCount) / fileCount);
|
||||
}
|
||||
if (file instanceof PsiJavaFile) {
|
||||
inferrer.collect(file);
|
||||
}
|
||||
}
|
||||
if (file instanceof PsiJavaFile) {
|
||||
inferrer.collect(file);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
inferrer.collect(usages);
|
||||
};
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(searchForUsages, INFER_NULLITY_ANNOTATIONS, true, project)) {
|
||||
return null;
|
||||
@@ -206,8 +210,6 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
|
||||
searchForUsages.run();
|
||||
}
|
||||
|
||||
final List<UsageInfo> usages = new ArrayList<>();
|
||||
inferrer.collect(usages);
|
||||
return usages.toArray(UsageInfo.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.Nullability;
|
||||
import com.intellij.codeInsight.NullabilityAnnotationInfo;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationFix;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.*;
|
||||
@@ -238,7 +239,7 @@ public class NullityInferrer {
|
||||
}
|
||||
}
|
||||
|
||||
public void collect(List<? super UsageInfo> usages) {
|
||||
void collect(List<? super UsageInfo> usages) {
|
||||
collect(usages, true);
|
||||
collect(usages, false);
|
||||
}
|
||||
@@ -246,10 +247,12 @@ public class NullityInferrer {
|
||||
private void collect(List<? super UsageInfo> usages, boolean nullable) {
|
||||
final List<SmartPsiElementPointer<? extends PsiModifierListOwner>> set = nullable ? myNullableSet : myNotNullSet;
|
||||
for (SmartPsiElementPointer<? extends PsiModifierListOwner> elementPointer : set) {
|
||||
final PsiModifierListOwner element = elementPointer.getElement();
|
||||
if (element != null && !shouldIgnore(element)) {
|
||||
usages.add(nullable ? new NullableUsageInfo(element) : new NotNullUsageInfo(element));
|
||||
}
|
||||
ReadAction.run(() -> {
|
||||
PsiModifierListOwner element = elementPointer.getElement();
|
||||
if (element != null && !shouldIgnore(element)) {
|
||||
usages.add(nullable ? new NullableUsageInfo(element) : new NotNullUsageInfo(element));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user