Search in sources :

Example 56 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class GradleConsoleFilter method applyFilter.

@Nullable
@Override
public Result applyFilter(final String line, final int entireLength) {
    String[] filePrefixes = new String[] { "Build file '", "build file '" };
    String[] linePrefixes = new String[] { "' line: ", "': " };
    String filePrefix = null;
    String linePrefix = null;
    for (int i = 0; i < filePrefixes.length; i++) {
        int filePrefixIndex = StringUtil.indexOf(line, filePrefixes[i]);
        if (filePrefixIndex != -1) {
            filePrefix = filePrefixes[i];
            linePrefix = linePrefixes[i];
            break;
        }
    }
    if (filePrefix == null || linePrefix == null) {
        return null;
    }
    int filePrefixIndex = StringUtil.indexOf(line, filePrefix);
    final String fileAndLineNumber = line.substring(filePrefix.length() + filePrefixIndex);
    int linePrefixIndex = StringUtil.indexOf(fileAndLineNumber, linePrefix);
    if (linePrefixIndex == -1) {
        return null;
    }
    final String fileName = fileAndLineNumber.substring(0, linePrefixIndex);
    myFilteredFileName = fileName;
    String lineNumberStr = fileAndLineNumber.substring(linePrefixIndex + linePrefix.length(), fileAndLineNumber.length()).trim();
    int lineNumberEndIndex = 0;
    for (int i = 0; i < lineNumberStr.length(); i++) {
        if (Character.isDigit(lineNumberStr.charAt(i))) {
            lineNumberEndIndex = i;
        } else {
            break;
        }
    }
    lineNumberStr = lineNumberStr.substring(0, lineNumberEndIndex + 1);
    int lineNumber;
    try {
        lineNumber = Integer.parseInt(lineNumberStr);
        myFilteredLineNumber = lineNumber;
    } catch (NumberFormatException e) {
        return null;
    }
    final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fileName.replace(File.separatorChar, '/'));
    if (file == null) {
        return null;
    }
    int textStartOffset = entireLength - line.trim().length() + filePrefix.length() - 1;
    int highlightEndOffset = textStartOffset + fileName.length();
    OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject, file, Math.max(lineNumber - 1, 0));
    TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone();
    if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)) {
        Color color = UIUtil.getInactiveTextColor();
        attributes.setForegroundColor(color);
        attributes.setEffectColor(color);
    }
    return new Result(textStartOffset, highlightEndOffset, info, attributes);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class ChameleonSyntaxHighlightingPass method collectHighlights.

private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
    EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
    TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
    if (language == null)
        return;
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
    for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
        TextRange tr = token.getTextRange();
        if (tr.isEmpty())
            continue;
        IElementType type = PsiUtilCore.getElementType(token);
        TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
        // force attribute colors to override host' ones
        TextAttributes attributes = null;
        for (TextAttributesKey key : keys) {
            TextAttributes attrs2 = scheme.getAttributes(key);
            if (attrs2 != null) {
                attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
            }
        }
        TextAttributes forcedAttributes;
        if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
            forcedAttributes = TextAttributes.ERASE_MARKER;
        } else {
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
            (priorityRange.contains(tr) ? inside : outside).add(info);
            forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
        }
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
        (priorityRange.contains(tr) ? inside : outside).add(info);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PsiElement(com.intellij.psi.PsiElement)

Example 58 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class InjectedGeneralHighlightingPass method addInjectedPsiHighlights.

// returns false if canceled
private boolean addInjectedPsiHighlights(@NotNull final Set<PsiFile> injectedFiles, @NotNull final ProgressIndicator progress, @NotNull final Collection<HighlightInfo> outInfos) {
    if (injectedFiles.isEmpty())
        return true;
    final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(myProject);
    final TextAttributes injectedAttributes = myGlobalScheme.getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
    return JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(injectedFiles), progress, isFailFastOnAcquireReadAction(), injectedPsi -> addInjectedPsiHighlights(injectedPsi, injectedAttributes, outInfos, progress, injectedLanguageManager));
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 59 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class SeverityUtil method getSeverityBasedTextAttributes.

private static SeverityRegistrar.SeverityBasedTextAttributes getSeverityBasedTextAttributes(@NotNull SeverityRegistrar registrar, @NotNull HighlightInfoType type) {
    final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    final TextAttributes textAttributes = scheme.getAttributes(type.getAttributesKey());
    if (textAttributes != null) {
        return new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes, (HighlightInfoType.HighlightInfoTypeImpl) type);
    }
    TextAttributes severity = registrar.getTextAttributesBySeverity(type.getSeverity(null));
    return new SeverityRegistrar.SeverityBasedTextAttributes(severity, (HighlightInfoType.HighlightInfoTypeImpl) type);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 60 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class HighlightUsagesHandler method highlightOtherOccurrences.

public static void highlightOtherOccurrences(final List<PsiElement> otherOccurrences, Editor editor, boolean clearHighlights) {
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    PsiElement[] elements = PsiUtilCore.toPsiElementArray(otherOccurrences);
    doHighlightElements(editor, elements, attributes, clearHighlights);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)205 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)40 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)31 NotNull (org.jetbrains.annotations.NotNull)29 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)28 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)26 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)26 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)23 TextRange (com.intellij.openapi.util.TextRange)21 Nullable (org.jetbrains.annotations.Nullable)21 ArrayList (java.util.ArrayList)19 Editor (com.intellij.openapi.editor.Editor)18 Project (com.intellij.openapi.project.Project)17 PsiElement (com.intellij.psi.PsiElement)12 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 JBColor (com.intellij.ui.JBColor)10 Document (com.intellij.openapi.editor.Document)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)8