mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
simple language: cleanup SimpleAnnotator
This commit is contained in:
parent
45ebe1e663
commit
62264e1eb4
@ -5,6 +5,7 @@ package org.intellij.sdk.language;
|
||||
import com.intellij.lang.annotation.AnnotationBuilder;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@ -15,10 +16,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.lang.annotation.HighlightSeverity.ERROR;
|
||||
import static com.intellij.lang.annotation.HighlightSeverity.INFORMATION;
|
||||
|
||||
|
||||
public class SimpleAnnotator implements Annotator {
|
||||
|
||||
// Define strings for the Simple language prefix - used for annotations, line markers, etc.
|
||||
@ -32,7 +29,7 @@ public class SimpleAnnotator implements Annotator {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure the Psi element contains a string that starts with the key and separator
|
||||
// Ensure the Psi element contains a string that starts with the prefix and separator
|
||||
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
|
||||
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
|
||||
if ((value == null) || !value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR)) {
|
||||
@ -52,13 +49,13 @@ public class SimpleAnnotator implements Annotator {
|
||||
List<SimpleProperty> properties = SimpleUtil.findProperties(project, possibleProperties);
|
||||
|
||||
// Set the annotations using the text ranges - Normally there would be one range, set by the element itself.
|
||||
holder.newAnnotation(INFORMATION, "")
|
||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||
.range(prefixRange).textAttributes(DefaultLanguageHighlighterColors.KEYWORD).create();
|
||||
holder.newAnnotation(INFORMATION, "")
|
||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||
.range(separatorRange).textAttributes(SimpleSyntaxHighlighter.SEPARATOR).create();
|
||||
if (properties.isEmpty()) {
|
||||
// No well-formed property found following the key-separator
|
||||
AnnotationBuilder builder = holder.newAnnotation(ERROR, "Unresolved property").range(keyRange);
|
||||
AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, "Unresolved property").range(keyRange);
|
||||
// Force the text attributes to Simple syntax bad character
|
||||
builder.textAttributes(SimpleSyntaxHighlighter.BAD_CHARACTER);
|
||||
// ** Tutorial step 18.3 - Add a quick fix for the string containing possible properties
|
||||
@ -67,7 +64,8 @@ public class SimpleAnnotator implements Annotator {
|
||||
builder.create();
|
||||
} else {
|
||||
// Found at least one property, force the text attributes to Simple syntax value character
|
||||
holder.newAnnotation(INFORMATION, "").range(keyRange).textAttributes(SimpleSyntaxHighlighter.VALUE).create();
|
||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||
.range(keyRange).textAttributes(SimpleSyntaxHighlighter.VALUE).create();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user