/** Patches attributes to be visible under debugger active line */ @SuppressWarnings("UseJBColor") private static TextAttributes patchAttributesColor( TextAttributes attributes, TextRange range, Editor editor) { int line = editor.offsetToLogicalPosition(range.getStartOffset()).line; for (RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) { if (!highlighter.isValid()) continue; if (highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE && editor.offsetToLogicalPosition(highlighter.getStartOffset()).line == line) { TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color color = textAttributes.getBackgroundColor(); if (color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128) { TextAttributes clone = attributes.clone(); clone.setForegroundColor(Color.orange); clone.setEffectColor(Color.orange); return clone; } } } } return attributes; }
public void execute(final String line, final int textEndOffset) { myResult = null; myInfo = parseExceptionLine(line); if (myInfo == null) { return; } myMethod = myInfo.getSecond().substring(line); final int lparenthIndex = myInfo.third.getStartOffset(); final int rparenthIndex = myInfo.third.getEndOffset(); final String fileAndLine = line.substring(lparenthIndex + 1, rparenthIndex).trim(); final int colonIndex = fileAndLine.lastIndexOf(':'); if (colonIndex < 0) return; final String lineString = fileAndLine.substring(colonIndex + 1); try { final int lineNumber = Integer.parseInt(lineString); myClass = findPositionClass(line); myFile = myClass == null ? null : (PsiFile) myClass.getContainingFile().getNavigationElement(); if (myFile == null) { // try find the file with the required name PsiFile[] files = PsiShortNamesCache.getInstance(myProject) .getFilesByName(fileAndLine.substring(0, colonIndex).trim()); if (files.length > 0) { myFile = files[0]; } } if (myFile == null) return; /* IDEADEV-4976: Some scramblers put something like SourceFile mock instead of real class name. final String filePath = fileAndLine.substring(0, colonIndex).replace('/', File.separatorChar); final int slashIndex = filePath.lastIndexOf(File.separatorChar); final String shortFileName = slashIndex < 0 ? filePath : filePath.substring(slashIndex + 1); if (!file.getName().equalsIgnoreCase(shortFileName)) return null; */ final int textStartOffset = textEndOffset - line.length(); final int highlightStartOffset = textStartOffset + lparenthIndex + 1; final int highlightEndOffset = textStartOffset + rparenthIndex; final VirtualFile virtualFile = myFile.getVirtualFile(); HyperlinkInfo linkInfo = new MyHyperlinkInfo(myProject, virtualFile, lineNumber); TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone(); if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(virtualFile)) { Color color = UIUtil.getInactiveTextColor(); attributes.setForegroundColor(color); attributes.setEffectColor(color); } myResult = new Filter.Result(highlightStartOffset, highlightEndOffset, linkInfo, attributes); } catch (NumberFormatException e) { // } }
private void highlightUsages() { if (mySearchResults.getEditor() == null) return; if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit()) return; for (FindResult range : mySearchResults.getOccurrences()) { TextAttributes attributes = EditorColorsManager.getInstance() .getGlobalScheme() .getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); if (range.getLength() == 0) { attributes = attributes.clone(); attributes.setEffectType(EffectType.BOXED); attributes.setEffectColor(attributes.getBackgroundColor()); } if (mySearchResults.isExcluded(range)) { highlightRange(range, strikout(attributes), myHighlighters); } else { highlightRange(range, attributes, myHighlighters); } } updateInSelectionHighlighters(); if (!myListeningSelection) { mySearchResults.getEditor().getSelectionModel().addSelectionListener(this); myListeningSelection = true; } }
/** Patches attributes to be visible under debugger active line */ @SuppressWarnings("UseJBColor") public static TextAttributes patchAttributesColor( TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) { if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null) return attributes; MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); if (model != null) { if (!((MarkupModelEx) model) .processRangeHighlightersOverlappingWith( range.getStartOffset(), range.getEndOffset(), highlighter -> { if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color color = textAttributes.getBackgroundColor(); return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128); } } return true; })) { TextAttributes clone = attributes.clone(); clone.setForegroundColor(Color.orange); clone.setEffectColor(Color.orange); return clone; } } return attributes; }
private static TextAttributes strikout(TextAttributes attributes) { TextAttributes textAttributes = attributes.clone(); textAttributes.setEffectColor(Color.BLACK); textAttributes.setEffectType(EffectType.STRIKEOUT); return textAttributes; }