/** @author ilyas */
public class DefaultHighlighter {

  @NonNls static final String LINE_COMMENT_ID = "Line comment";
  @NonNls static final String BLOCK_COMMENT_ID = "Block comment";
  @NonNls static final String DOC_COMMENT_ID = "Groovydoc comment";
  @NonNls static final String DOC_COMMENT_TAG_ID = "Groovydoc tag";
  @NonNls static final String KEYWORD_ID = "Keyword";
  @NonNls static final String NUMBER_ID = "Number";
  @NonNls static final String GSTRING_ID = "GString";
  @NonNls static final String STRING_ID = "String";
  @NonNls static final String BRACES_ID = "Braces";
  @NonNls static final String BRACKETS_ID = "Brackets";
  @NonNls static final String PARENTHESES_ID = "Parentheses";

  @NonNls static final String OPERATION_SIGN_ID = "Operation sign";
  @NonNls static final String BAD_CHARACTER_ID = "Bad character";
  @NonNls static final String WRONG_STRING_ID = "Wrong string literal";

  @NonNls static final String ANNOTATION_ID = "Annotation";
  @NonNls static final String INSTANCE_FIELD_ID = "Instance field";
  @NonNls static final String STATIC_FIELD_ID = "Static field";
  @NonNls static final String METHOD_CALL_ID = "Method call";
  @NonNls static final String STATIC_METHOD_ACCESS_ID = "Static method access";
  @NonNls static final String CLASS_REFERENCE_ID = "Class";
  @NonNls static final String TYPE_PARAMETER_ID = "Type parameter";
  @NonNls static final String INSTANCE_PROPERTY_REFERENCE_ID = "Instance property reference ID";
  @NonNls static final String STATIC_PROPERTY_REFERENCE_ID = "Static property reference ID";
  @NonNls static final String MAP_KEY_ID = "Map key";

  @NonNls static final String UNRESOLVED_ACCESS_ID = "Unresolved reference access";
  static final String LITERAL_CONVERSION_ID = "List/map to object conversion";

  static final String VALID_STRING_ESCAPE_ID = "Valid string escape";
  static final String INVALID_STRING_ESCAPE_ID = "Invalid string escape";

  @NonNls static final String LABEL_ID = "Label";

  public static TextAttributesKey LINE_COMMENT =
      TextAttributesKey.createTextAttributesKey(
          LINE_COMMENT_ID, SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes());

  public static TextAttributesKey ANNOTATION =
      TextAttributesKey.createTextAttributesKey(
          ANNOTATION_ID,
          HighlightInfoType.ANNOTATION_NAME.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey LOCAL_VARIABLE =
      TextAttributesKey.createTextAttributesKey(
          "Groovy var", HighlightInfoType.LOCAL_VARIABLE.getAttributesKey().getDefaultAttributes());
  public static TextAttributesKey REASSIGNED_LOCAL_VARIABLE =
      TextAttributesKey.createTextAttributesKey(
          "Groovy reassigned var",
          HighlightInfoType.REASSIGNED_LOCAL_VARIABLE.getAttributesKey().getDefaultAttributes());
  public static TextAttributesKey PARAMETER =
      TextAttributesKey.createTextAttributesKey(
          "Groovy parameter",
          HighlightInfoType.PARAMETER.getAttributesKey().getDefaultAttributes());
  public static TextAttributesKey REASSIGNED_PARAMETER =
      TextAttributesKey.createTextAttributesKey(
          "Groovy reassigned parameter",
          HighlightInfoType.REASSIGNED_PARAMETER.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey METHOD_DECLARATION =
      TextAttributesKey.createTextAttributesKey(
          "Groovy method declaration",
          HighlightInfoType.METHOD_DECLARATION.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey INSTANCE_FIELD =
      TextAttributesKey.createTextAttributesKey(
          INSTANCE_FIELD_ID,
          HighlightInfoType.INSTANCE_FIELD.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey METHOD_CALL =
      TextAttributesKey.createTextAttributesKey(
          METHOD_CALL_ID, HighlightInfoType.METHOD_CALL.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey STATIC_FIELD =
      TextAttributesKey.createTextAttributesKey(
          STATIC_FIELD_ID,
          HighlightInfoType.STATIC_FINAL_FIELD.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey STATIC_METHOD_ACCESS =
      TextAttributesKey.createTextAttributesKey(
          STATIC_METHOD_ACCESS_ID,
          HighlightInfoType.STATIC_METHOD.getAttributesKey().getDefaultAttributes());

  public static TextAttributesKey BLOCK_COMMENT =
      TextAttributesKey.createTextAttributesKey(
          BLOCK_COMMENT_ID, SyntaxHighlighterColors.JAVA_BLOCK_COMMENT.getDefaultAttributes());

  public static TextAttributesKey DOC_COMMENT_CONTENT =
      TextAttributesKey.createTextAttributesKey(
          DOC_COMMENT_ID, SyntaxHighlighterColors.DOC_COMMENT.getDefaultAttributes());

  public static TextAttributesKey DOC_COMMENT_TAG =
      TextAttributesKey.createTextAttributesKey(
          DOC_COMMENT_TAG_ID, SyntaxHighlighterColors.DOC_COMMENT_TAG.getDefaultAttributes());

  public static TextAttributesKey CLASS_REFERENCE =
      TextAttributesKey.createTextAttributesKey(
          CLASS_REFERENCE_ID, HighlighterColors.TEXT.getDefaultAttributes().clone());

  public static TextAttributesKey TYPE_PARAMETER =
      TextAttributesKey.createTextAttributesKey(
          TYPE_PARAMETER_ID,
          CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES.getDefaultAttributes().clone());

  public static final TextAttributes INSTANCE_PROPERTY_REFERENCE_ATTRIBUTES =
      INSTANCE_FIELD.getDefaultAttributes().clone();
  public static final TextAttributes STATIC_PROPERTY_REFERENCE_ATTRIBUTES =
      STATIC_FIELD.getDefaultAttributes().clone();

  static {
    INSTANCE_PROPERTY_REFERENCE_ATTRIBUTES.setFontType(Font.PLAIN);
    STATIC_PROPERTY_REFERENCE_ATTRIBUTES.setFontType(Font.ITALIC);
  }

  public static TextAttributesKey INSTANCE_PROPERTY_REFERENCE =
      TextAttributesKey.createTextAttributesKey(
          INSTANCE_PROPERTY_REFERENCE_ID, INSTANCE_PROPERTY_REFERENCE_ATTRIBUTES);

  public static TextAttributesKey STATIC_PROPERTY_REFERENCE =
      TextAttributesKey.createTextAttributesKey(
          STATIC_PROPERTY_REFERENCE_ID, STATIC_PROPERTY_REFERENCE_ATTRIBUTES);

  public static final TextAttributes KEYWORD_ATTRIBUTES =
      SyntaxHighlighterColors.KEYWORD.getDefaultAttributes().clone();

  static {
    KEYWORD_ATTRIBUTES.setForegroundColor(new Color(0, 0, 67));
    KEYWORD_ATTRIBUTES.setFontType(Font.BOLD);
  }

  public static TextAttributesKey KEYWORD =
      TextAttributesKey.createTextAttributesKey(
          "GROOVY_" + KEYWORD_ID.toUpperCase(), KEYWORD_ATTRIBUTES);

  public static TextAttributesKey NUMBER =
      TextAttributesKey.createTextAttributesKey(
          NUMBER_ID, SyntaxHighlighterColors.NUMBER.getDefaultAttributes());

  public static TextAttributesKey GSTRING =
      TextAttributesKey.createTextAttributesKey(
          GSTRING_ID, SyntaxHighlighterColors.STRING.getDefaultAttributes());

  public static TextAttributesKey STRING =
      TextAttributesKey.createTextAttributesKey(
          STRING_ID, SyntaxHighlighterColors.STRING.getDefaultAttributes());

  public static TextAttributesKey BRACES =
      TextAttributesKey.createTextAttributesKey(
          BRACES_ID, SyntaxHighlighterColors.BRACES.getDefaultAttributes());

  public static TextAttributesKey BRACKETS =
      TextAttributesKey.createTextAttributesKey(
          BRACKETS_ID, SyntaxHighlighterColors.BRACKETS.getDefaultAttributes());

  public static TextAttributesKey PARENTHESES =
      TextAttributesKey.createTextAttributesKey(
          PARENTHESES_ID, SyntaxHighlighterColors.PARENTHS.getDefaultAttributes());

  public static TextAttributesKey OPERATION_SIGN =
      TextAttributesKey.createTextAttributesKey(
          OPERATION_SIGN_ID, SyntaxHighlighterColors.OPERATION_SIGN.getDefaultAttributes());

  public static TextAttributesKey BAD_CHARACTER =
      TextAttributesKey.createTextAttributesKey(
          BAD_CHARACTER_ID, CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES.getDefaultAttributes());

  public static TextAttributesKey WRONG_STRING =
      TextAttributesKey.createTextAttributesKey(
          WRONG_STRING_ID, SyntaxHighlighterColors.STRING.getDefaultAttributes());

  public static final TextAttributes UNRESOLVED_ACCESS_ATTRIBUTES =
      HighlighterColors.TEXT.getDefaultAttributes().clone();

  static {
    UNRESOLVED_ACCESS_ATTRIBUTES.setForegroundColor(Color.BLACK);
    UNRESOLVED_ACCESS_ATTRIBUTES.setEffectColor(Color.GRAY);
    UNRESOLVED_ACCESS_ATTRIBUTES.setEffectType(EffectType.LINE_UNDERSCORE);
  }

  public static final TextAttributes LITERAL_CONVERSION_ATTRIBUTES =
      HighlighterColors.TEXT.getDefaultAttributes().clone();

  static {
    LITERAL_CONVERSION_ATTRIBUTES.setForegroundColor(PlatformColors.BLUE);
    LITERAL_CONVERSION_ATTRIBUTES.setFontType(Font.BOLD);
  }

  public static final TextAttributes MAP_KEY_ATTRIBUTES =
      HighlighterColors.TEXT.getDefaultAttributes().clone();

  public static final Color MAP_KEY_COLOR = new Color(0, 128, 0);

  static {
    MAP_KEY_ATTRIBUTES.setForegroundColor(MAP_KEY_COLOR);
  }

  public static TextAttributesKey UNRESOLVED_ACCESS =
      TextAttributesKey.createTextAttributesKey(UNRESOLVED_ACCESS_ID, UNRESOLVED_ACCESS_ATTRIBUTES);
  public static TextAttributesKey LITERAL_CONVERSION =
      TextAttributesKey.createTextAttributesKey(
          LITERAL_CONVERSION_ID, LITERAL_CONVERSION_ATTRIBUTES);

  public static TextAttributesKey MAP_KEY =
      TextAttributesKey.createTextAttributesKey(MAP_KEY_ID, MAP_KEY_ATTRIBUTES);

  public static final TextAttributesKey VALID_STRING_ESCAPE =
      TextAttributesKey.createTextAttributesKey(
          VALID_STRING_ESCAPE_ID,
          SyntaxHighlighterColors.VALID_STRING_ESCAPE.getDefaultAttributes());
  public static final TextAttributesKey INVALID_STRING_ESCAPE =
      TextAttributesKey.createTextAttributesKey(
          INVALID_STRING_ESCAPE_ID,
          SyntaxHighlighterColors.INVALID_STRING_ESCAPE.getDefaultAttributes());

  public static final TextAttributes LABEL_ATTRIBUTES =
      HighlighterColors.TEXT.getDefaultAttributes().clone();

  public static final TextAttributesKey LABEL =
      TextAttributesKey.createTextAttributesKey(LABEL_ID, LABEL_ATTRIBUTES);

  private DefaultHighlighter() {}
}
/** Syntax highlighter defines token colors. */
public class PropsSyntaxHighlighter extends SyntaxHighlighterBase {

  private static final Map<IElementType, TextAttributesKey> keys1;
  private static final Map<IElementType, TextAttributesKey> keys2;

  @NotNull
  public Lexer getHighlightingLexer() {
    return new PropsLexer();
  }

  public static final TextAttributesKey PROP_KEY =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.KEY", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes());
  public static final TextAttributesKey PROP_VALUE =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.VALUE", SyntaxHighlighterColors.STRING.getDefaultAttributes());
  public static final TextAttributesKey PROP_COMMENT =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.LINE_COMMENT", SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes());
  public static final TextAttributesKey PROP_KEY_VALUE_SEPARATOR =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.KEY_VALUE_SEPARATOR",
          SyntaxHighlighterColors.OPERATION_SIGN.getDefaultAttributes());
  public static final TextAttributesKey PROP_VALID_STRING_ESCAPE =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.VALID_STRING_ESCAPE",
          SyntaxHighlighterColors.VALID_STRING_ESCAPE.getDefaultAttributes());
  public static final TextAttributesKey PROP_INVALID_STRING_ESCAPE =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.INVALID_STRING_ESCAPE",
          SyntaxHighlighterColors.INVALID_STRING_ESCAPE.getDefaultAttributes());
  public static final TextAttributesKey PROP_SECTION =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.SECTION", new TextAttributes(new Color(0x660066), null, null, null, Font.BOLD));
  public static final TextAttributesKey PROP_MACRO =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.MACRO", new TextAttributes(new Color(0x0055BB), null, null, null, Font.BOLD));
  public static final TextAttributesKey PROP_PROFILE =
      TextAttributesKey.createTextAttributesKey(
          "PROPS.PROFILE", new TextAttributes(new Color(0x0000FF), null, null, null, Font.BOLD));

  static {
    keys1 = new HashMap<IElementType, TextAttributesKey>();
    keys2 = new HashMap<IElementType, TextAttributesKey>();

    keys1.put(PropsTokenTypes.TOKEN_VALUE, PROP_VALUE);
    keys1.put(PropsTokenTypes.TOKEN_EOL_COMMENT, PROP_COMMENT);
    keys1.put(PropsTokenTypes.TOKEN_KEY, PROP_KEY);
    keys1.put(PropsTokenTypes.TOKEN_KEY_VALUE_SEPARATOR, PROP_KEY_VALUE_SEPARATOR);
    keys1.put(PropsTokenTypes.TOKEN_SECTION, PROP_SECTION);
    keys1.put(PropsTokenTypes.TOKEN_MACRO, PROP_MACRO);
    keys1.put(PropsTokenTypes.TOKEN_PROFILE, PROP_PROFILE);

    keys1.put(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, PROP_VALID_STRING_ESCAPE);

    // in fact all back-slashed escapes are allowed
    keys1.put(StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN, PROP_INVALID_STRING_ESCAPE);
    keys1.put(StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN, PROP_INVALID_STRING_ESCAPE);
  }

  @NotNull
  public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    return pack(keys1.get(tokenType), keys2.get(tokenType));
  }

  public static final Map<TextAttributesKey, Pair<String, HighlightSeverity>> DISPLAY_NAMES =
      new HashMap<TextAttributesKey, Pair<String, HighlightSeverity>>(7);

  static {
    DISPLAY_NAMES.put(PROP_KEY, new Pair<String, HighlightSeverity>("Property key", null));
    DISPLAY_NAMES.put(PROP_VALUE, new Pair<String, HighlightSeverity>("Property value", null));
    DISPLAY_NAMES.put(
        PROP_KEY_VALUE_SEPARATOR, new Pair<String, HighlightSeverity>("Key value separator", null));
    DISPLAY_NAMES.put(PROP_COMMENT, new Pair<String, HighlightSeverity>("Comment", null));
    DISPLAY_NAMES.put(
        PROP_VALID_STRING_ESCAPE, new Pair<String, HighlightSeverity>("String escape", null));
    DISPLAY_NAMES.put(
        PROP_INVALID_STRING_ESCAPE,
        new Pair<String, HighlightSeverity>("String escape (invalid)", HighlightSeverity.WARNING));
    DISPLAY_NAMES.put(PROP_SECTION, new Pair<String, HighlightSeverity>("Section", null));
    DISPLAY_NAMES.put(PROP_MACRO, new Pair<String, HighlightSeverity>("Macro", null));
    DISPLAY_NAMES.put(PROP_PROFILE, new Pair<String, HighlightSeverity>("Profile", null));
  }
}