/platform/platform-api/src/com/intellij/lang/annotation/HighlightSeverity.java

https://bitbucket.org/nbargnesi/idea · Java · 123 lines · 49 code · 26 blank · 48 comment · 6 complexity · 836a615f5af15482e346003bb0daa0e5 MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.lang.annotation;
  17. import com.intellij.openapi.util.DefaultJDOMExternalizer;
  18. import com.intellij.openapi.util.InvalidDataException;
  19. import com.intellij.openapi.util.JDOMExternalizable;
  20. import com.intellij.openapi.util.WriteExternalException;
  21. import org.jdom.Element;
  22. import org.jetbrains.annotations.NonNls;
  23. /**
  24. * Defines a highlighting severity level for an annotation.
  25. *
  26. * @author max
  27. * @see com.intellij.lang.annotation.Annotation
  28. */
  29. public class HighlightSeverity implements Comparable<HighlightSeverity>, JDOMExternalizable {
  30. public String myName;
  31. public int myVal;
  32. /**
  33. * The standard severity level for information annotations.
  34. */
  35. public static final HighlightSeverity INFORMATION = new HighlightSeverity("INFORMATION", 10);
  36. /**
  37. * The severity level for errors or warnings obtained from server.
  38. */
  39. public static final HighlightSeverity GENERIC_SERVER_ERROR_OR_WARNING = new HighlightSeverity("SERVER PROBLEM", 100);
  40. /**
  41. * The standard severity level for 'weak' :) warning annotations.
  42. */
  43. @Deprecated
  44. public static final HighlightSeverity INFO = new HighlightSeverity("INFO", 200);
  45. public static final HighlightSeverity WEAK_WARNING = new HighlightSeverity("WEAK WARNING", 200);
  46. /**
  47. * The standard severity level for warning annotations.
  48. */
  49. public static final HighlightSeverity WARNING = new HighlightSeverity("WARNING", 300);
  50. /**
  51. * The standard severity level for error annotations.
  52. */
  53. public static final HighlightSeverity ERROR = new HighlightSeverity("ERROR", 400);
  54. /**
  55. * Standard severities levels
  56. */
  57. public static final HighlightSeverity[] DEFAULT_SEVERITIES = {INFORMATION, GENERIC_SERVER_ERROR_OR_WARNING, INFO, WEAK_WARNING, WARNING, ERROR};
  58. /**
  59. * Creates a new highlighting severity level with the specified name and value.
  60. *
  61. * @param name the name of the highlighting level.
  62. * @param val the value of the highlighting level. Used for comparing the annotations -
  63. * if two annotations with different severity levels cover the same text range, only
  64. * the annotation with a higher severity level is displayed.
  65. */
  66. public HighlightSeverity(@NonNls String name, int val) {
  67. myName = name;
  68. myVal = val;
  69. }
  70. //read external only
  71. public HighlightSeverity() {
  72. }
  73. public String toString() {
  74. return myName;
  75. }
  76. @Override
  77. public int compareTo(final HighlightSeverity highlightSeverity) {
  78. return myVal - highlightSeverity.myVal;
  79. }
  80. @Override
  81. public void readExternal(Element element) throws InvalidDataException {
  82. DefaultJDOMExternalizer.readExternal(this, element);
  83. }
  84. @Override
  85. public void writeExternal(final Element element) throws WriteExternalException {
  86. DefaultJDOMExternalizer.writeExternal(this, element);
  87. }
  88. public boolean equals(final Object o) {
  89. if (this == o) return true;
  90. if (o == null || getClass() != o.getClass()) return false;
  91. final HighlightSeverity that = (HighlightSeverity)o;
  92. return myName.equals(that.myName);
  93. }
  94. public int hashCode() {
  95. return myName.hashCode();
  96. }
  97. }