This commit is contained in:
Alexey Kudravtsev
2016-12-19 14:32:27 +03:00
parent 15f812f4fe
commit b99bb074c2
5 changed files with 29 additions and 36 deletions
@@ -74,17 +74,16 @@ public class ExceptionExFilterFactory implements ExceptionFilterFactory {
final int lineStartOffset = copiedFragment.getLineStartOffset(i);
final int lineEndOffset = copiedFragment.getLineEndOffset(i);
String text = copiedFragment.getText(new TextRange(lineStartOffset, lineEndOffset));
if (!text.contains(".java:")) continue;
Trinity<TextRange, TextRange, TextRange> info = visited.get(text);
String lineText = copiedFragment.getText(new TextRange(lineStartOffset, lineEndOffset));
if (!lineText.contains(".java:")) continue;
Trinity<TextRange, TextRange, TextRange> info = visited.get(lineText);
if (info == emptyInfo) continue;
if (info == null) {
info = emptyInfo;
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
worker.execute(text, lineEndOffset);
Result result = worker.getResult();
Result result = worker.execute(lineText, lineEndOffset);
if (result == null) continue;
HyperlinkInfo hyperlinkInfo = result.getHyperlinkInfo();
if (!(hyperlinkInfo instanceof FileHyperlinkInfo)) continue;
@@ -105,7 +104,7 @@ public class ExceptionExFilterFactory implements ExceptionFilterFactory {
}
finally {
token.finish();
visited.put(text, info);
visited.put(lineText, info);
}
}
int off = startOffset + lineStartOffset;
@@ -26,9 +26,9 @@ public class ExceptionFilter implements Filter, DumbAware {
myCache = new ExceptionInfoCache(scope);
}
@Override
public Result applyFilter(final String line, final int textEndOffset) {
ExceptionWorker worker = new ExceptionWorker(myCache);
worker.execute(line, textEndOffset);
return worker.getResult();
return worker.execute(line, textEndOffset);
}
}
@@ -106,12 +106,8 @@ public class VcsContentAnnotationExceptionFilter implements Filter, FilterMixin
final int lineStartOffset = copiedFragment.getLineStartOffset(i);
final int lineEndOffset = copiedFragment.getLineEndOffset(i);
final ExceptionWorker worker = new ExceptionWorker(myCache);
final String[] lineText = new String[1];
ApplicationManager.getApplication().runReadAction(() -> {
lineText[0] = copiedFragment.getText(new TextRange(lineStartOffset, lineEndOffset));
worker.execute(lineText[0], lineEndOffset);
});
if (worker.getResult() != null) {
final String lineText = copiedFragment.getText(new TextRange(lineStartOffset, lineEndOffset));
if (ApplicationManager.getApplication().runReadAction((Computable<Result>)() -> worker.execute(lineText, lineEndOffset)) != null) {
VirtualFile vf = worker.getFile().getVirtualFile();
if (vf.getFileSystem().isReadOnly()) continue;
@@ -133,7 +129,7 @@ public class VcsContentAnnotationExceptionFilter implements Filter, FilterMixin
if (document == null) return;
int startFileOffset = worker.getInfo().getThird().getStartOffset();
int idx = lineText[0].indexOf(':', startFileOffset);
int idx = lineText.indexOf(':', startFileOffset);
int endIdx = idx == -1 ? worker.getInfo().getThird().getEndOffset() : idx;
consumer.consume(new MyAdditionalHighlight(startOffset + lineStartOffset + startFileOffset + 1, startOffset + lineStartOffset + endIdx));
@@ -61,11 +61,11 @@ public class ExceptionWorker {
myCache = cache;
}
public void execute(final String line, final int textEndOffset) {
public Filter.Result execute(final String line, final int textEndOffset) {
myResult = null;
myInfo = parseExceptionLine(line);
if (myInfo == null) {
return;
return null;
}
myMethod = myInfo.getSecond().substring(line);
@@ -75,10 +75,10 @@ public class ExceptionWorker {
final String fileAndLine = line.substring(lparenthIndex + 1, rparenthIndex).trim();
final int colonIndex = fileAndLine.lastIndexOf(':');
if (colonIndex < 0) return;
if (colonIndex < 0) return null;
final int lineNumber = getLineNumber(fileAndLine.substring(colonIndex + 1));
if (lineNumber < 0) return;
if (lineNumber < 0) return null;
Pair<PsiClass[], PsiFile[]> pair = myCache.resolveClass(myInfo.first.substring(line).trim());
myClasses = pair.first;
@@ -88,7 +88,7 @@ public class ExceptionWorker {
//todo[nik] it would be better to use FilenameIndex here to honor the scope by it isn't accessible in Open API
myFiles = PsiShortNamesCache.getInstance(myProject).getFilesByName(fileAndLine.substring(0, colonIndex).trim());
}
if (myFiles.length == 0) return;
if (myFiles.length == 0) return null;
/*
IDEADEV-4976: Some scramblers put something like SourceFile mock instead of real class name.
@@ -130,7 +130,9 @@ public class ExceptionWorker {
virtualFiles = virtualFilesInContent;
}
HyperlinkInfo linkInfo = HyperlinkInfoFactory.getInstance().createMultipleFilesHyperlinkInfo(virtualFiles, lineNumber - 1, myProject);
myResult = new Filter.Result(highlightStartOffset, highlightEndOffset, linkInfo, attributes);
Filter.Result result = new Filter.Result(highlightStartOffset, highlightEndOffset, linkInfo, attributes);
myResult = result;
return result;
}
private static int getLineNumber(String lineString) {
@@ -19,7 +19,6 @@ import com.intellij.execution.filters.Filter;
import com.intellij.execution.filters.HyperlinkInfo;
import com.intellij.execution.filters.HyperlinkInfoBase;
import com.intellij.ide.OccurenceNavigator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
@@ -59,8 +58,7 @@ import java.util.Map;
* @author peter
*/
public class EditorHyperlinkSupport {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.impl.EditorHyperlinkSupport");
public static final Key<TextAttributes> OLD_HYPERLINK_TEXT_ATTRIBUTES = Key.create("OLD_HYPERLINK_TEXT_ATTRIBUTES");
private static final Key<TextAttributes> OLD_HYPERLINK_TEXT_ATTRIBUTES = Key.create("OLD_HYPERLINK_TEXT_ATTRIBUTES");
private static final Key<HyperlinkInfoTextAttributes> HYPERLINK = Key.create("HYPERLINK");
private final Editor myEditor;
@@ -86,6 +84,7 @@ public class EditorHyperlinkSupport {
});
editor.getContentComponent().addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(final MouseEvent e) {
final HyperlinkInfo info = getHyperlinkInfoByPoint(e.getPoint());
if (info != null) {
@@ -131,7 +130,7 @@ public class EditorHyperlinkSupport {
return null;
}
final RangeHighlighter range = findLinkRangeAt(this.myEditor.logicalPositionToOffset(logical));
final RangeHighlighter range = findLinkRangeAt(myEditor.logicalPositionToOffset(logical));
if (range != null) {
final HyperlinkInfo hyperlinkInfo = getHyperlinkInfo(range);
if (hyperlinkInfo != null) {
@@ -178,7 +177,7 @@ public class EditorHyperlinkSupport {
return getHyperlinks(lineStart, lineEnd, myEditor);
}
public static List<RangeHighlighter> getHyperlinks(int startOffset, int endOffset, final Editor editor) {
private static List<RangeHighlighter> getHyperlinks(int startOffset, int endOffset, final Editor editor) {
final MarkupModelEx markupModel = (MarkupModelEx)editor.getMarkupModel();
final CommonProcessors.CollectProcessor<RangeHighlighterEx> processor = new CommonProcessors.CollectProcessor<>();
markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset,
@@ -257,13 +256,9 @@ public class EditorHyperlinkSupport {
@Deprecated
public void highlightHyperlinks(final Filter customFilter, final Filter predefinedMessageFilter, final int line1, final int endLine) {
highlightHyperlinks(new Filter() {
@Nullable
@Override
public Result applyFilter(String line, int entireLength) {
Result result = customFilter.applyFilter(line, entireLength);
return result != null ? result : predefinedMessageFilter.applyFilter(line, entireLength);
}
highlightHyperlinks((line, entireLength) -> {
Filter.Result result = customFilter.applyFilter(line, entireLength);
return result != null ? result : predefinedMessageFilter.applyFilter(line, entireLength);
}, line1, endLine);
}
@@ -330,7 +325,7 @@ public class EditorHyperlinkSupport {
break;
}
}
i = i % ranges.size();
i %= ranges.size();
int newIndex = i;
while (newIndex < ranges.size() && newIndex >= 0) {
newIndex = (newIndex + delta + ranges.size()) % ranges.size();
@@ -341,6 +336,7 @@ public class EditorHyperlinkSupport {
boolean inCollapsedRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(next.getStartOffset()) != null;
if (!inCollapsedRegion) {
return new OccurenceNavigator.OccurenceInfo(new NavigatableAdapter() {
@Override
public void navigate(final boolean requestFocus) {
action.consume(next);
linkFollowed(editor, ranges, next);
@@ -391,7 +387,7 @@ public class EditorHyperlinkSupport {
private final HyperlinkInfo myHyperlinkInfo;
private final TextAttributes myFollowedHyperlinkAttributes;
public HyperlinkInfoTextAttributes(@NotNull HyperlinkInfo hyperlinkInfo, @Nullable TextAttributes followedHyperlinkAttributes) {
HyperlinkInfoTextAttributes(@NotNull HyperlinkInfo hyperlinkInfo, @Nullable TextAttributes followedHyperlinkAttributes) {
myHyperlinkInfo = hyperlinkInfo;
myFollowedHyperlinkAttributes = followedHyperlinkAttributes;
}
@@ -402,7 +398,7 @@ public class EditorHyperlinkSupport {
}
@Nullable
public TextAttributes getFollowedHyperlinkAttributes() {
TextAttributes getFollowedHyperlinkAttributes() {
return myFollowedHyperlinkAttributes;
}
}