package com.simpleplugin;

import com.intellij.lang.annotation.*;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
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));
        }
      }
    }
  }
}

@@ -759,17 +759,23 @@
 : null;%0A
+      
 %0A
-
       if
@@ -1123,17 +1123,17 @@
 set() + 
-7
+8
 ,%0A      
@@ -1186,37 +1186,35 @@
 tTextRange().get
-Start
+End
 Offset() + 7);%0A 
@@ -1210,11 +1210,11 @@
 t() 
-+ 7
+- 1
 );%0A 
@@ -1586,16 +1586,20 @@
 Offset()
+ - 1
 );%0A     
@@ -1665,68 +1665,8 @@
 ty%22)
-.%0A              registerFix(new CreatePropertyQuickFix(key))
 ;%0A  
@@ -1691,10 +1691,9 @@
   %7D%0A  %7D%0A
+
 %7D
-%0A

Fix text ranges