diff --git a/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java b/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java index 17c5c46b4943..1628d54c3f1a 100644 --- a/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java +++ b/java/java-analysis-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java @@ -85,8 +85,6 @@ public class JavaHighlightingColors { = TextAttributesKey.createTextAttributesKey("ANONYMOUS_CLASS_NAME_ATTRIBUTES", CLASS_NAME_ATTRIBUTES); public static final TextAttributesKey IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES", CLASS_NAME_ATTRIBUTES); - public static final TextAttributesKey INLINE_PARAMETER_HINT - = TextAttributesKey.createTextAttributesKey("INLINE_PARAMETER_HINT"); public static final TextAttributesKey TYPE_PARAMETER_NAME_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("TYPE_PARAMETER_NAME_ATTRIBUTES", DefaultLanguageHighlighterColors.PARAMETER); public static final TextAttributesKey INTERFACE_NAME_ATTRIBUTES diff --git a/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java b/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java index a6c706f4b8f7..4f7aade54c94 100644 --- a/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java +++ b/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java @@ -74,7 +74,6 @@ public class JavaColorSettingsPage implements RainbowColorSettingsPage, Inspecti new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.reassigned.local.variable"), JavaHighlightingColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.reassigned.parameter"), JavaHighlightingColors.REASSIGNED_PARAMETER_ATTRIBUTES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.implicit.anonymous.parameter"), JavaHighlightingColors.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.inline.parameter.hint"), JavaHighlightingColors.INLINE_PARAMETER_HINT), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.instance.field"), JavaHighlightingColors.INSTANCE_FIELD_ATTRIBUTES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.instance.final.field"), JavaHighlightingColors.INSTANCE_FINAL_FIELD_ATTRIBUTES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.static.field"), JavaHighlightingColors.STATIC_FIELD_ATTRIBUTES), diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/DefaultLanguageHighlighterColors.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/DefaultLanguageHighlighterColors.java index 920f97ab0107..37cb1af8c419 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/DefaultLanguageHighlighterColors.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/DefaultLanguageHighlighterColors.java @@ -68,4 +68,5 @@ public class DefaultLanguageHighlighterColors { public static final TextAttributesKey MARKUP_TAG = TextAttributesKey.createTextAttributesKey("DEFAULT_TAG", HighlighterColors.TEXT); public static final TextAttributesKey MARKUP_ATTRIBUTE = TextAttributesKey.createTextAttributesKey("DEFAULT_ATTRIBUTE", IDENTIFIER); public static final TextAttributesKey MARKUP_ENTITY = TextAttributesKey.createTextAttributesKey("DEFAULT_ENTITY", IDENTIFIER); + public static final TextAttributesKey INLINE_PARAMETER_HINT = TextAttributesKey.createTextAttributesKey("INLINE_PARAMETER_HINT"); } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/SimpleEditorPreview.java b/platform/lang-impl/src/com/intellij/application/options/colors/SimpleEditorPreview.java index 401c9eb751c9..70f714601982 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/SimpleEditorPreview.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/SimpleEditorPreview.java @@ -22,7 +22,6 @@ import com.intellij.codeHighlighting.RainbowHighlighter; import com.intellij.codeInsight.daemon.UsedColors; import com.intellij.ide.highlighter.HighlighterFactory; import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.EditorSchemeAttributeDescriptor; import com.intellij.openapi.editor.colors.TextAttributesKey; @@ -36,6 +35,7 @@ import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.options.colors.ColorSettingsPage; import com.intellij.openapi.options.colors.EditorHighlightingProvidingColorSettingsPage; import com.intellij.openapi.options.colors.RainbowColorSettingsPage; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.TextRange; import com.intellij.psi.tree.IElementType; import com.intellij.util.Alarm; @@ -54,7 +54,12 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import static com.intellij.openapi.editor.colors.CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES; + public class SimpleEditorPreview implements PreviewPanel { + private static final Map INLINE_ELEMENTS = + Collections.singletonMap("parameter_hint", DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT); + private final ColorSettingsPage myPage; private final EditorEx myEditor; @@ -74,7 +79,7 @@ public class SimpleEditorPreview implements PreviewPanel { myOptions = options; myPage = page; - myHighlightsExtractor = new HighlightsExtractor(page.getAdditionalHighlightingTagToDescriptorMap()); + myHighlightsExtractor = new HighlightsExtractor(page.getAdditionalHighlightingTagToDescriptorMap(), INLINE_ELEMENTS); myEditor = (EditorEx)FontEditorPreview.createPreviewEditor( myHighlightsExtractor.extractHighlights(page.getDemoText(), myHighlightData), // text without tags 10, 3, -1, myOptions, false); @@ -187,7 +192,7 @@ public class SimpleEditorPreview implements PreviewPanel { private void updateHighlighters() { UIUtil.invokeLaterIfNeeded(() -> { if (myEditor.isDisposed()) return; - myEditor.getMarkupModel().removeAllHighlighters(); + removeDecorations(myEditor); final Map displayText = ColorSettingsUtil.keyToDisplayTextMap(myPage); for (final HighlightData data : myHighlightData) { data.addHighlToView(myEditor, myOptions.getSelectedScheme(), displayText); @@ -195,6 +200,13 @@ public class SimpleEditorPreview implements PreviewPanel { }); } + private static void removeDecorations(Editor editor) { + editor.getMarkupModel().removeAllHighlighters(); + for (Inlay inlay : editor.getInlayModel().getInlineElementsInRange(0, editor.getDocument().getTextLength())) { + Disposer.dispose(inlay); + } + } + private static final int BLINK_COUNT = 3 * 2; @Override @@ -248,18 +260,14 @@ public class SimpleEditorPreview implements PreviewPanel { final int count, final ColorSettingsPage page) { if (show && count <= 0) return Collections.emptyList(); - editor.getMarkupModel().removeAllHighlighters(); + removeDecorations(editor); boolean found = false; List highlights = new ArrayList<>(); List matchingHighlights = new ArrayList<>(); for (HighlightData highlightData : myHighlightData) { - String type = highlightData.getHighlightType(); - highlights.add(highlightData); - if (show && type.equals(attrKey)) { - highlightData = - new HighlightData(highlightData.getStartOffset(), highlightData.getEndOffset(), - CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); - highlights.add(highlightData); + boolean highlight = show && highlightData.getHighlightType().equals(attrKey); + highlightData.addToCollection(highlights, highlight); + if (highlight) { matchingHighlights.add(highlightData); found = true; } @@ -272,8 +280,7 @@ public class SimpleEditorPreview implements PreviewPanel { for (final TextAttributesKey tokenHighlight : tokenHighlights) { String type = tokenHighlight.getExternalName(); if (show && type != null && type.equals(attrKey)) { - HighlightData highlightData = new HighlightData(iterator.getStart(), iterator.getEnd(), - CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); + HighlightData highlightData = new HighlightData(iterator.getStart(), iterator.getEnd(), BLINKING_HIGHLIGHTS_ATTRIBUTES); highlights.add(highlightData); matchingHighlights.add(highlightData); } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightData.java b/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightData.java index 499605ab18b9..520bea82b884 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightData.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightData.java @@ -25,11 +25,15 @@ import com.intellij.openapi.editor.markup.HighlighterTargetArea; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; import java.awt.*; +import java.util.Collection; import java.util.Map; -public final class HighlightData { +import static com.intellij.openapi.editor.colors.CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES; + +public class HighlightData { private final int myStartOffset; private int myEndOffset; private final TextAttributesKey myHighlightType; @@ -45,6 +49,11 @@ public final class HighlightData { myHighlightType = highlightType; } + public void addToCollection(@NotNull Collection list, boolean highlighted) { + list.add(this); + if (highlighted) list.add(new HighlightData(getStartOffset(), getEndOffset(), BLINKING_HIGHLIGHTS_ATTRIBUTES)); + } + public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map displayText) { // XXX: Hack diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightsExtractor.java b/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightsExtractor.java index dd2c09bbee5e..c65a6d0cc3d0 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightsExtractor.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/HighlightsExtractor.java @@ -18,6 +18,8 @@ package com.intellij.application.options.colors.highlighting; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.Nullable; @@ -26,8 +28,8 @@ import java.util.List; import java.util.Map; public class HighlightsExtractor { - private final Map myTags; + private final Map myInlineElements; private int myStartOffset; private int myEndOffset; @@ -38,18 +40,29 @@ public class HighlightsExtractor { private List mySkipped = new ArrayList<>(); public HighlightsExtractor(@Nullable Map tags) { + this(tags, null); + } + + public HighlightsExtractor(@Nullable Map tags, @Nullable Map inlineElements) { myTags = tags; + myInlineElements = inlineElements; } public String extractHighlights(String text, List highlights) { mySkipped.clear(); - if (myTags == null || myTags.isEmpty()) return text; + if (ContainerUtil.isEmpty(myTags) && ContainerUtil.isEmpty(myInlineElements)) return text; resetIndices(); Stack highlightsStack = new Stack<>(); while (true) { String tagName = findTagName(text); if (tagName == null || myIndex < 0) break; - if (myTags.containsKey(tagName)) { + String tagNameWithoutParameters = StringUtil.substringBefore(tagName, " "); + if (myInlineElements != null && tagNameWithoutParameters != null && myInlineElements.containsKey(tagNameWithoutParameters)) { + mySkippedLen += tagName.length() + 2; + String hintText = tagName.substring(tagNameWithoutParameters.length()).trim(); + highlights.add(new InlineElementData(myStartOffset - mySkippedLen, myInlineElements.get(tagNameWithoutParameters), hintText)); + } + else if (myTags != null && myTags.containsKey(tagName)) { if (myIsOpeningTag) { mySkippedLen += tagName.length() + 2; HighlightData highlightData = new HighlightData(myStartOffset - mySkippedLen, myTags.get(tagName)); @@ -95,12 +108,13 @@ public class HighlightsExtractor { if (myIsOpeningTag) { myStartOffset = openTag + tagName.length() + 2; - if (myTags.containsKey(tagName)) { + if (myTags != null && myTags.containsKey(tagName) || + myInlineElements != null && myInlineElements.containsKey(StringUtil.substringBefore(tagName, " "))) { mySkipped.add(TextRange.from(openTag, tagName.length() + 2)); } } else { myEndOffset = openTag - 1; - if (myTags.containsKey(tagName)) { + if (myTags != null && myTags.containsKey(tagName)) { mySkipped.add(TextRange.from(openTag - 1, tagName.length() + 3)); } } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/InlineElementData.java b/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/InlineElementData.java new file mode 100644 index 000000000000..6f027c47346e --- /dev/null +++ b/platform/lang-impl/src/com/intellij/application/options/colors/highlighting/InlineElementData.java @@ -0,0 +1,100 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.application.options.colors.highlighting; + +import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorCustomElementRenderer; +import com.intellij.openapi.editor.Inlay; +import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.util.Disposer; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import static com.intellij.openapi.editor.colors.CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES; + +public class InlineElementData extends HighlightData { + private final String myText; + private boolean myAddBorder; + + public InlineElementData(int offset, TextAttributesKey attributesKey, String text) { + this(offset, attributesKey, text, false); + } + + private InlineElementData(int offset, TextAttributesKey attributesKey, String text, boolean highlighted) { + super(offset, offset, attributesKey); + myText = text; + myAddBorder = highlighted; + } + + public String getText() { + return myText; + } + + @Override + public void addHighlToView(Editor view, EditorColorsScheme scheme, Map displayText) { + int offset = getStartOffset(); + ParameterHintsPresentationManager.getInstance().addHint(view, offset, myText, false); + List inlays = view.getInlayModel().getInlineElementsInRange(offset, offset); + for (Inlay inlay : inlays) { + EditorCustomElementRenderer renderer = inlay.getRenderer(); + if (!(renderer instanceof RendererWrapper)) { + Disposer.dispose(inlay); + RendererWrapper wrapper = new RendererWrapper(renderer); + wrapper.drawBorder = myAddBorder; + view.getInlayModel().addInlineElement(offset, wrapper); + } + } + } + + @Override + public void addToCollection(@NotNull Collection list, boolean highlighted) { + list.add(new InlineElementData(getStartOffset(), getHighlightKey(), myText, highlighted)); + } + + public static class RendererWrapper implements EditorCustomElementRenderer { + private final EditorCustomElementRenderer myDelegate; + private boolean drawBorder; + + public RendererWrapper(EditorCustomElementRenderer delegate) { + myDelegate = delegate; + } + + @Override + public int calcWidthInPixels(@NotNull Editor editor) { + return myDelegate.calcWidthInPixels(editor); + } + + @Override + public void paint(@NotNull Editor editor, @NotNull Graphics g, @NotNull Rectangle r) { + myDelegate.paint(editor, g, r); + if (drawBorder) { + TextAttributes attributes = editor.getColorsScheme().getAttributes(BLINKING_HIGHLIGHTS_ATTRIBUTES); + if (attributes != null && attributes.getEffectColor() != null) { + g.setColor(attributes.getEffectColor()); + g.drawRect(r.x, r.y, r.width, r.height); + } + } + } + } + +} diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java similarity index 98% rename from java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java rename to platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java index a5e6821dde45..8763a0fc746e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ParameterHintsPresentationManager.java @@ -15,10 +15,10 @@ */ package com.intellij.codeInsight.daemon.impl; -import com.intellij.ide.highlighter.JavaHighlightingColors; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorCustomElementRenderer; import com.intellij.openapi.editor.Inlay; @@ -186,7 +186,7 @@ public class ParameterHintsPresentationManager implements Disposable { @Override public void paint(@NotNull Editor editor, @NotNull Graphics g, @NotNull Rectangle r) { if (myText != null && (step > steps || startWidth != 0)) { - TextAttributes attributes = editor.getColorsScheme().getAttributes(JavaHighlightingColors.INLINE_PARAMETER_HINT); + TextAttributes attributes = editor.getColorsScheme().getAttributes(DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT); if (attributes != null) { MyFontMetrics fontMetrics = getFontMetrics(editor); Color backgroundColor = attributes.getBackgroundColor(); diff --git a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java index 2f783d7732dc..2b01d308a5bd 100644 --- a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java +++ b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java @@ -148,6 +148,8 @@ public class DefaultLanguageColorsPage implements RainbowColorSettingsPage, Disp OptionsBundle.message("options.language.defaults.function.call"), DefaultLanguageHighlighterColors.FUNCTION_CALL), new AttributesDescriptor( OptionsBundle.message("options.language.defaults.parameter"), DefaultLanguageHighlighterColors.PARAMETER), + new AttributesDescriptor( + OptionsBundle.message("options.java.attribute.descriptor.inline.parameter.hint"), DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT), new AttributesDescriptor( OptionsBundle.message("options.language.defaults.interface.name"), DefaultLanguageHighlighterColors.INTERFACE_NAME), new AttributesDescriptor( @@ -220,7 +222,7 @@ public class DefaultLanguageColorsPage implements RainbowColorSettingsPage, Disp " */\n" + "Function declaration (parameter1 parameter2 parameter3 parameter4)\n" + " Local variable1 variable2 variable3 variable4\n" + - "Function call()\n" + + "Function call(0)\n" + "Interface Name\n" + "@Metadata\n" + "Class Name\n" + diff --git a/platform/platform-resources-en/src/messages/OptionsBundle.properties b/platform/platform-resources-en/src/messages/OptionsBundle.properties index 15f747c2c913..c8aae0db91f9 100644 --- a/platform/platform-resources-en/src/messages/OptionsBundle.properties +++ b/platform/platform-resources-en/src/messages/OptionsBundle.properties @@ -79,7 +79,7 @@ options.java.attribute.descriptor.local.variable=Variables//Local variable options.java.attribute.descriptor.reassigned.local.variable=Variables//Reassigned local variable options.java.attribute.descriptor.reassigned.parameter=Parameters//Reassigned parameter options.java.attribute.descriptor.implicit.anonymous.parameter=Parameters//Implicit anonymous class parameter -options.java.attribute.descriptor.inline.parameter.hint=Parameters//Inline parameter hint +options.java.attribute.descriptor.inline.parameter.hint=Inline parameter hint options.java.attribute.descriptor.instance.field=Class Fields//Instance field options.java.attribute.descriptor.instance.final.field=Class Fields//Instance final field options.java.attribute.descriptor.static.field=Class Fields//Static field