mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
42 lines
2.0 KiB
Java
42 lines
2.0 KiB
Java
package com.simpleplugin;
|
|
|
|
import com.intellij.lang.annotation.Annotation;
|
|
import com.intellij.lang.annotation.AnnotationHolder;
|
|
import com.intellij.lang.annotation.Annotator;
|
|
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
|
import com.intellij.openapi.project.Project;
|
|
import com.intellij.openapi.util.TextRange;
|
|
import com.intellij.psi.PsiElement;
|
|
import com.intellij.psi.PsiLiteralExpression;
|
|
import com.simpleplugin.psi.SimpleProperty;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.List;
|
|
|
|
public class SimpleAnnotator implements Annotator {
|
|
@Override
|
|
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
|
|
if (element instanceof PsiLiteralExpression) {
|
|
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
|
|
String value = literalExpression.getValue() instanceof String ? (String)literalExpression.getValue() : null;
|
|
|
|
if (value != null && value.startsWith("simple"+":")) {
|
|
Project project = element.getProject();
|
|
String key = value.substring(7);
|
|
List<SimpleProperty> properties = SimpleUtil.findProperties(project, key);
|
|
if (properties.size() == 1) {
|
|
TextRange range = new TextRange(element.getTextRange().getStartOffset() + 7,
|
|
element.getTextRange().getStartOffset() + 7);
|
|
Annotation annotation = holder.createInfoAnnotation(range, null);
|
|
annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
|
|
} else if (properties.size() == 0) {
|
|
TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8,
|
|
element.getTextRange().getEndOffset());
|
|
holder.createErrorAnnotation(range, "Unresolved property").
|
|
registerFix(new CreatePropertyQuickFix(key));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|