From cd180949295d76cd9f74f2fad3cae6ec8f347c57 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 20:00:45 +0400 Subject: [PATCH] Added special highlighting for invalid string escape. --- .../jet/plugin/highlighter/JetColorSettingsPage.java | 1 + .../jet/plugin/highlighter/JetHighlightingColors.java | 5 +++++ .../jetbrains/jet/plugin/highlighter/JetPsiChecker.java | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index f5f8968eaad..11ed1ca98e0 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -103,6 +103,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.valid.escape.in.string"), JetHighlightingColors.VALID_STRING_ESCAPE), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string"), JetHighlightingColors.INVALID_STRING_ESCAPE), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 67152e7c09e..96f3fd62730 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -51,6 +51,11 @@ public class JetHighlightingColors { SyntaxHighlighterColors.VALID_STRING_ESCAPE.getDefaultAttributes() ); + public static final TextAttributesKey INVALID_STRING_ESCAPE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_INVALID_STRING_ESCAPE", + SyntaxHighlighterColors.INVALID_STRING_ESCAPE.getDefaultAttributes() + ); + public static final TextAttributesKey LINE_COMMENT = TextAttributesKey.createTextAttributesKey( "KOTLIN_LINE_COMMENT", SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes() diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 55bac4696e8..4ce6180a790 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -147,6 +147,13 @@ public class JetPsiChecker implements Annotator { return; } + if (diagnostic.getFactory() == Errors.ILLEGAL_ESCAPE_SEQUENCE) { + for (TextRange textRange : diagnostic.getTextRanges()) { + Annotation annotation = holder.createErrorAnnotation(textRange, diagnostic.getMessage()); + annotation.setTextAttributes(JetHighlightingColors.INVALID_STRING_ESCAPE); + } + } + if (diagnostic instanceof RedeclarationDiagnostic) { RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic)diagnostic; registerQuickFix(markRedeclaration(redeclarations, redeclarationDiagnostic, holder), diagnostic);