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()]);
}
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;
}
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;
}
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];
}
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() + "]";
}
}
Aggregations