mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
generic API for console folding
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.intellij.execution.filters;
|
||||
|
||||
import com.intellij.execution.ConsoleFolding;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class AuxiliaryCallsFolding extends ConsoleFolding {
|
||||
@Override
|
||||
public boolean shouldFoldLine(String line) {
|
||||
final Trinity<String, String, TextRange> pair = ExceptionFilter.parseExceptionLine(line);
|
||||
return pair != null && shouldFold(pair.first);
|
||||
}
|
||||
|
||||
private static boolean shouldFold(String className) {
|
||||
for (StackFrameFilter provider : StackFrameFilter.EP_NAME.getExtensions()) {
|
||||
if (provider.isAuxiliaryFrame(className, "")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPlaceholderText(List<String> lines) {
|
||||
return " <" + lines.size() + " internal calls>";
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -30,6 +32,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -51,7 +54,8 @@ public class ExceptionFilter implements Filter, DumbAware {
|
||||
mySearchScope = scope;
|
||||
}
|
||||
|
||||
public Result applyFilter(final String line, final int textEndOffset) {
|
||||
@Nullable
|
||||
static Trinity<String, String, TextRange> parseExceptionLine(final String line) {
|
||||
int atIndex;
|
||||
if (line.startsWith(AT_PREFIX)){
|
||||
atIndex = 0;
|
||||
@@ -69,11 +73,6 @@ public class ExceptionFilter implements Filter, DumbAware {
|
||||
final int lastDotIndex = line.lastIndexOf('.', lparenthIndex);
|
||||
if (lastDotIndex < 0 || lastDotIndex < atIndex) return null;
|
||||
String className = line.substring(atIndex + AT.length() + 1, lastDotIndex).trim();
|
||||
final boolean isInternal = shouldFold(className);
|
||||
final int dollarIndex = className.indexOf('$');
|
||||
if (dollarIndex >= 0){
|
||||
className = className.substring(0, dollarIndex);
|
||||
}
|
||||
|
||||
//String methodName = text.substring(lastDotIndex + 1, lparenthIndex).trim();
|
||||
|
||||
@@ -81,6 +80,22 @@ public class ExceptionFilter implements Filter, DumbAware {
|
||||
if (rparenthIndex < 0) return null;
|
||||
|
||||
final String fileAndLine = line.substring(lparenthIndex + 1, rparenthIndex).trim();
|
||||
return Trinity.create(className, fileAndLine, new TextRange(lparenthIndex, rparenthIndex));
|
||||
}
|
||||
|
||||
public Result applyFilter(final String line, final int textEndOffset) {
|
||||
final Trinity<String, String, TextRange> info = parseExceptionLine(line);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String className = info.first;
|
||||
final int dollarIndex = className.indexOf('$');
|
||||
if (dollarIndex >= 0){
|
||||
className = className.substring(0, dollarIndex);
|
||||
}
|
||||
|
||||
final String fileAndLine = info.second;
|
||||
|
||||
final int colonIndex = fileAndLine.lastIndexOf(':');
|
||||
if (colonIndex < 0) return null;
|
||||
@@ -103,29 +118,21 @@ public class ExceptionFilter implements Filter, DumbAware {
|
||||
*/
|
||||
|
||||
final int textStartOffset = textEndOffset - line.length();
|
||||
final int highlightStartOffset = textStartOffset + lparenthIndex + 1;
|
||||
final int highlightEndOffset = textStartOffset + rparenthIndex;
|
||||
final int highlightStartOffset = textStartOffset + info.third.getStartOffset() + 1;
|
||||
final int highlightEndOffset = textStartOffset + info.third.getEndOffset();
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
final OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject, virtualFile, lineNumber - 1);
|
||||
final OpenFileHyperlinkInfo linkInfo = new OpenFileHyperlinkInfo(myProject, virtualFile, lineNumber - 1);
|
||||
TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone();
|
||||
if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(virtualFile)) {
|
||||
Color color = UIUtil.getTextInactiveTextColor();
|
||||
attributes.setForegroundColor(color);
|
||||
attributes.setEffectColor(color);
|
||||
}
|
||||
return new Result(highlightStartOffset, highlightEndOffset, info, attributes, isInternal);
|
||||
return new Result(highlightStartOffset, highlightEndOffset, linkInfo, attributes);
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldFold(String className) {
|
||||
for (StackFrameFilter provider : StackFrameFilter.EP_NAME.getExtensions()) {
|
||||
if (provider.isInternalFrame(className, "")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ package com.intellij.execution.filters;
|
||||
* @author peter
|
||||
*/
|
||||
public class ReflectionStackFrameFilter extends StackFrameFilter {
|
||||
public boolean isInternalFrame(String className, String methodName) {
|
||||
public boolean isAuxiliaryFrame(String className, String methodName) {
|
||||
return className.startsWith("sun.reflect.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
public abstract class StackFrameFilter {
|
||||
public static final ExtensionPointName<StackFrameFilter> EP_NAME = ExtensionPointName.create("com.intellij.stackFrameFilter");
|
||||
|
||||
public abstract boolean isInternalFrame(String className, String methodName);
|
||||
public abstract boolean isAuxiliaryFrame(String className, String methodName);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user