Search in sources :

Example 41 with TextAttributes

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

the class RainbowHighlighter method generateColors.

@NotNull
private static Color[] generateColors(@NotNull TextAttributesScheme colorsScheme, boolean withCorrectionAndCaching) {
    List<Color> stopRainbowColors = ContainerUtil.map(RAINBOW_COLOR_KEYS, key -> getRainbowColorFromAttribute(colorsScheme.getAttributes(key)));
    List<Color> rainbowColors = ColorGenerator.generateLinearColorSequence(stopRainbowColors, RAINBOW_COLORS_BETWEEN);
    if (withCorrectionAndCaching && (colorsScheme instanceof EditorColorsScheme)) {
        final EditorColorPalette palette = EditorColorPaletteFactory.getInstance().getPalette((EditorColorsScheme) colorsScheme, Language.ANY).collectColorsWithFilter(attr -> getRainbowColorFromAttribute(attr), true);
        final List<Pair<Color, Double>> colorCircles = new ArrayList<>();
        final Color background = ((EditorColorsScheme) colorsScheme).getDefaultBackground();
        final boolean schemeIsDark = ColorUtil.isDark(background);
        final double minDistanceWithOrdinal = schemeIsDark ? 0.06 : 0.10;
        final double minDistanceWithDiagnostic = schemeIsDark ? 0.12 : 0.20;
        colorCircles.add(Pair.create(background, 0.24));
        palette.getEntries().forEach(entry -> colorCircles.add(Pair.create(entry.getKey(), Collections.disjoint(CODE_INSIGHT_CONFLICT_KEYS, entry.getValue()) ? minDistanceWithOrdinal : minDistanceWithDiagnostic)));
        rainbowColors = ContainerUtil.map(rainbowColors, rainbowColor -> resolveConflict(colorCircles, rainbowColor, 0));
        final Map<TextAttributesKey, TextAttributes> cache = getGeneratedTextAttributesCache(colorsScheme);
        if (cache != null) {
            cache.entrySet().removeIf(entry -> isRainbowTempKey(entry.getKey()));
            int i = 0;
            for (Color rainbowColor : rainbowColors) {
                TextAttributesKey key = createRainbowKey(i++, rainbowColor);
                cache.put(key, key.getDefaultAttributes());
            }
        }
    }
    return rainbowColors.toArray(new Color[rainbowColors.size()]);
}
Also used : Language(com.intellij.lang.Language) java.util(java.util) ColorUtil(com.intellij.ui.ColorUtil) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) StringUtil(com.intellij.openapi.util.text.StringUtil) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) SchemeMetaInfo(com.intellij.openapi.options.SchemeMetaInfo) ContainerUtil(com.intellij.util.containers.ContainerUtil) com.intellij.openapi.editor.colors(com.intellij.openapi.editor.colors) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) DefaultLanguageHighlighterColors(com.intellij.openapi.editor.DefaultLanguageHighlighterColors) Contract(org.jetbrains.annotations.Contract) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pair(com.intellij.openapi.util.Pair) PsiElement(com.intellij.psi.PsiElement) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) UIBundle(com.intellij.ui.UIBundle) NotNull(org.jetbrains.annotations.NotNull) JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with TextAttributes

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

the class RainbowHighlighter method createRainbowKey.

@NotNull
private static TextAttributesKey createRainbowKey(int i, Color rainbowColor) {
    //noinspection deprecation
    TextAttributesKey key = TextAttributesKey.createTextAttributesKey(RAINBOW_TEMP_PREF + i, new TextAttributes());
    key.getDefaultAttributes().setForegroundColor(rainbowColor);
    return key;
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with TextAttributes

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

the class AccessStaticViaInstanceFix method checkSideEffects.

private boolean checkSideEffects(final Project project, PsiClass containingClass, final PsiExpression qualifierExpression, PsiElementFactory factory, final PsiElement myExpression, Editor editor) {
    final List<PsiElement> sideEffects = new ArrayList<>();
    boolean hasSideEffects = RemoveUnusedVariableUtil.checkSideEffects(qualifierExpression, null, sideEffects);
    if (hasSideEffects && !myOnTheFly)
        return false;
    if (!hasSideEffects || ApplicationManager.getApplication().isUnitTestMode()) {
        return true;
    }
    if (editor == null) {
        return false;
    }
    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    HighlightManager.getInstance(project).addOccurrenceHighlights(editor, PsiUtilCore.toPsiElementArray(sideEffects), attributes, true, null);
    try {
        hasSideEffects = PsiUtil.isStatement(factory.createStatementFromText(qualifierExpression.getText(), qualifierExpression));
    } catch (IncorrectOperationException e) {
        hasSideEffects = false;
    }
    final PsiReferenceExpression qualifiedWithClassName = (PsiReferenceExpression) myExpression.copy();
    qualifiedWithClassName.setQualifierExpression(factory.createReferenceExpression(containingClass));
    final PsiStatement statement = PsiTreeUtil.getParentOfType(myExpression, PsiStatement.class);
    final boolean canCopeWithSideEffects = hasSideEffects && statement != null;
    final SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, null, sideEffects.get(0).getText(), PsiExpressionTrimRenderer.render(qualifierExpression), canCopeWithSideEffects) {

        @Override
        protected String sideEffectsDescription() {
            if (canCopeWithSideEffects) {
                return "<html><body>" + "  There are possible side effects found in expression '" + qualifierExpression.getText() + "'<br>" + "  You can:<ul><li><b>Remove</b> class reference along with whole expressions involved, or</li>" + "  <li><b>Transform</b> qualified expression into the statement on its own.<br>" + "  That is,<br>" + "  <table border=1><tr><td><code>" + myExpression.getText() + "</code></td></tr></table><br> becomes: <br>" + "  <table border=1><tr><td><code>" + qualifierExpression.getText() + ";<br>" + qualifiedWithClassName.getText() + "       </code></td></tr></table></li>" + "  </body></html>";
            }
            return "<html><body>  There are possible side effects found in expression '" + qualifierExpression.getText() + "'<br>" + "You can:<ul><li><b>Remove</b> class reference along with whole expressions involved, or</li></body></html>";
        }
    };
    dialog.show();
    int res = dialog.getExitCode();
    if (res == RemoveUnusedVariableUtil.RemoveMode.CANCEL.ordinal())
        return false;
    if (res == RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT.ordinal()) {
        final PsiStatement statementFromText = factory.createStatementFromText(qualifierExpression.getText() + ";", null);
        LOG.assertTrue(statement != null);
        WriteAction.run(() -> {
            try {
                statement.getParent().addBefore(statementFromText, statement);
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
        });
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) IncorrectOperationException(com.intellij.util.IncorrectOperationException) LocalQuickFixAndIntentionActionOnPsiElement(com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)

Example 44 with TextAttributes

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

the class RemoveUnusedVariableFix method showSideEffectsWarning.

public static RemoveUnusedVariableUtil.RemoveMode showSideEffectsWarning(List<PsiElement> sideEffects, PsiVariable variable, Editor editor, boolean canCopeWithSideEffects, @NonNls String beforeText, @NonNls String afterText) {
    if (sideEffects.isEmpty())
        return RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return canCopeWithSideEffects ? RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT : RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
    }
    Project project = editor.getProject();
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    PsiElement[] elements = PsiUtilCore.toPsiElementArray(sideEffects);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    highlightManager.addOccurrenceHighlights(editor, elements, attributes, true, null);
    SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, variable, beforeText, afterText, canCopeWithSideEffects);
    dialog.show();
    int code = dialog.getExitCode();
    return RemoveUnusedVariableUtil.RemoveMode.values()[code];
}
Also used : Project(com.intellij.openapi.project.Project) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 45 with TextAttributes

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

the class EditorView method dumpState.

@NotNull
@Override
public String dumpState() {
    String prefixText = myPrefixText;
    TextAttributes prefixAttributes = myPrefixAttributes;
    synchronized (myLock) {
        return "[prefix text: " + prefixText + ", prefix attributes: " + prefixAttributes + ", space width: " + myPlainSpaceWidth + ", line height: " + myLineHeight + ", descent: " + myDescent + ", char height: " + myCharHeight + ", max char width: " + myMaxCharWidth + ", tab size: " + myTabSize + " ,size manager: " + mySizeManager.dumpState() + " ,logical position cache: " + myLogicalPositionCache.dumpState() + "]";
    }
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

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