mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ExceptionFilter/ExceptionWorker: use SyntaxTraverser instead of PsiElementFilter
GitOrigin-RevId: 75cb96222cc6fdb24a60c28de31cedde359552c0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5e8e1a687f
commit
6254cd93bf
@@ -18,7 +18,6 @@ package com.intellij.execution.filters;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiElementFilter;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
@@ -26,11 +25,13 @@ import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ExceptionFilter implements Filter, DumbAware {
|
||||
private static final String EXCEPTION_IN_THREAD = "Exception in thread \"";
|
||||
private static final String CAUSED_BY = "Caused by: ";
|
||||
private final ExceptionInfoCache myCache;
|
||||
private PsiElementFilter myNextLineRefiner;
|
||||
private Predicate<PsiElement> myNextLineRefiner;
|
||||
|
||||
public ExceptionFilter(@NotNull final GlobalSearchScope scope) {
|
||||
myCache = new ExceptionInfoCache(scope);
|
||||
@@ -44,10 +45,10 @@ public class ExceptionFilter implements Filter, DumbAware {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static PsiElementFilter getRefinerFromException(@NotNull String line) {
|
||||
private static Predicate<PsiElement> getRefinerFromException(@NotNull String line) {
|
||||
String exceptionName = getExceptionFromMessage(line);
|
||||
if (exceptionName == null) return null;
|
||||
PsiElementFilter exceptionCreationFilter = e -> {
|
||||
Predicate<PsiElement> exceptionCreationFilter = e -> {
|
||||
// We look for new Exception() expression rather than throw statement, because stack-trace is filled in exception constructor
|
||||
if (!(e instanceof PsiKeyword) || !(e.textMatches(PsiKeyword.NEW))) return false;
|
||||
PsiNewExpression newExpression = ObjectUtils.tryCast(e.getParent(), PsiNewExpression.class);
|
||||
@@ -55,13 +56,13 @@ public class ExceptionFilter implements Filter, DumbAware {
|
||||
PsiType type = newExpression.getType();
|
||||
return type != null && type.equalsToText(exceptionName);
|
||||
};
|
||||
PsiElementFilter specificFilter = getExceptionSpecificFilter(exceptionName);
|
||||
Predicate<PsiElement> specificFilter = getExceptionSpecificFilter(exceptionName);
|
||||
if (specificFilter == null) return exceptionCreationFilter;
|
||||
return element -> exceptionCreationFilter.isAccepted(element) || specificFilter.isAccepted(element);
|
||||
return exceptionCreationFilter.or(specificFilter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiElementFilter getExceptionSpecificFilter(String exceptionName) {
|
||||
private static Predicate<PsiElement> getExceptionSpecificFilter(String exceptionName) {
|
||||
switch (exceptionName) {
|
||||
case "java.lang.ArrayIndexOutOfBoundsException":
|
||||
return e -> e instanceof PsiJavaToken &&
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.psi.util.ClassUtil;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiElementFilter;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
@@ -44,6 +43,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public class ExceptionWorker {
|
||||
@@ -58,7 +58,7 @@ public class ExceptionWorker {
|
||||
private String myMethod;
|
||||
private ParsedLine myInfo;
|
||||
private final ExceptionInfoCache myCache;
|
||||
private PsiElementFilter myLocationRefiner;
|
||||
private Predicate<PsiElement> myLocationRefiner;
|
||||
|
||||
public ExceptionWorker(@NotNull ExceptionInfoCache cache) {
|
||||
myProject = cache.getProject();
|
||||
@@ -69,7 +69,7 @@ public class ExceptionWorker {
|
||||
return execute(line, textEndOffset, null);
|
||||
}
|
||||
|
||||
public Filter.Result execute(@NotNull String line, final int textEndOffset, @Nullable PsiElementFilter elementMatcher) {
|
||||
public Filter.Result execute(@NotNull String line, final int textEndOffset, @Nullable Predicate<PsiElement> elementMatcher) {
|
||||
myResult = null;
|
||||
myInfo = parseExceptionLine(line);
|
||||
if (myInfo == null || myProject.isDisposed()) {
|
||||
@@ -145,7 +145,7 @@ public class ExceptionWorker {
|
||||
return result;
|
||||
}
|
||||
|
||||
public PsiElementFilter getLocationRefiner() {
|
||||
public Predicate<PsiElement> getLocationRefiner() {
|
||||
return myLocationRefiner;
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ public class ExceptionWorker {
|
||||
}
|
||||
}
|
||||
|
||||
private static class StackFrameMatcher implements PsiElementFilter {
|
||||
private static class StackFrameMatcher implements Predicate<PsiElement> {
|
||||
private final String myMethodName;
|
||||
private final String myClassName;
|
||||
private final boolean myHasDollarInName;
|
||||
@@ -353,7 +353,7 @@ public class ExceptionWorker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccepted(@NotNull PsiElement element) {
|
||||
public boolean test(@NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiIdentifier)) return false;
|
||||
if (myMethodName.equals("<init>")) {
|
||||
if (myHasDollarInName || element.textMatches(StringUtil.getShortName(myClassName))) {
|
||||
@@ -394,10 +394,10 @@ public class ExceptionWorker {
|
||||
}
|
||||
|
||||
private static class ExceptionColumnFinder implements ToIntFunction<PsiFile> {
|
||||
private final PsiElementFilter myElementMatcher;
|
||||
private final Predicate<PsiElement> myElementMatcher;
|
||||
private final int myLineNumber;
|
||||
|
||||
private ExceptionColumnFinder(@NotNull PsiElementFilter elementMatcher, int lineNumber) {
|
||||
private ExceptionColumnFinder(@NotNull Predicate<PsiElement> elementMatcher, int lineNumber) {
|
||||
myElementMatcher = elementMatcher;
|
||||
myLineNumber = lineNumber;
|
||||
}
|
||||
@@ -413,7 +413,7 @@ public class ExceptionWorker {
|
||||
PsiElement element = file.findElementAt(startOffset);
|
||||
List<PsiElement> candidates = new ArrayList<>();
|
||||
while (element != null && element.getTextRange().getStartOffset() < endOffset) {
|
||||
if (myElementMatcher.isAccepted(element)) {
|
||||
if (myElementMatcher.test(element)) {
|
||||
candidates.add(element);
|
||||
if (candidates.size() > 1) return 0;
|
||||
}
|
||||
@@ -426,9 +426,9 @@ public class ExceptionWorker {
|
||||
}
|
||||
}
|
||||
|
||||
private static class FunctionCallMatcher implements PsiElementFilter {
|
||||
private static class FunctionCallMatcher implements Predicate<PsiElement> {
|
||||
@Override
|
||||
public boolean isAccepted(@NotNull PsiElement element) {
|
||||
public boolean test(@NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiIdentifier)) return false;
|
||||
PsiElement parent = element.getParent();
|
||||
if (!(parent instanceof PsiReferenceExpression)) return false;
|
||||
|
||||
Reference in New Issue
Block a user