com.intellij.lang.annotation
Class Annotation

java.lang.Object
  extended by com.intellij.lang.annotation.Annotation

public final class Annotation
extends java.lang.Object

Defines an annotation, which is displayed as a gutter bar mark or an extra highlight in the editor.

See Also:
Annotator, AnnotationHolder, RangeHighlighter

Constructor Summary
Annotation(int startOffset, int endOffset, HighlightSeverity severity, java.lang.String message, java.lang.String tooltip)
          Creates an instance of the annotation.
 
Method Summary
 int getEndOffset()
          Returns the end offset of the text range covered by the annotation.
 ProblemHighlightType getHighlightType()
          If the annotation matches one of commonly encountered problem types, returns the ID of that problem type so that an appropriate color can be used for highlighting the annotation.
 java.lang.String getMessage()
          Returns the description of the annotation (shown in the status bar or by "View | Error Description" action).
 java.util.List<Pair<IntentionAction,TextRange>> getQuickFixes()
          Returns the list of quick fixes registered for the annotation.
 HighlightSeverity getSeverity()
          Returns the severity of the problem indicated by the annotation (highlight, warning or error).
 int getStartOffset()
          Returns the start offset of the text range covered by the annotation.
 TextAttributesKey getTextAttributes()
          Returns the text attribute key used for highlighting the annotation.
 java.lang.String getTooltip()
          Returns the tooltip for the annotation (shown when hovering the mouse in the gutter bar).
 boolean isAfterEndOfLine()
          Returns the flag indicating whether the annotation is shown after the end of line containing it.
 boolean needsUpdateOnTyping()
          Gets a flag indicating what happens with the annotation when the user starts typing.
 void registerFix(IntentionAction fix)
          Registers a quick fix for the annotation.
 void registerFix(IntentionAction fix, TextRange range)
          Registers a quick fix for the annotation which is only available on a particular range of text within the annotation.
 void setAfterEndOfLine(boolean afterEndOfLine)
          Sets the flag indicating whether the annotation is shown after the end of line containing it.
 void setHighlightType(ProblemHighlightType highlightType)
          If the annotation matches one of commonly encountered problem types, sets the ID of that problem type so that an appropriate color can be used for highlighting the annotation.
 void setNeedsUpdateOnTyping(boolean b)
          Sets a flag indicating what happens with the annotation when the user starts typing.
 void setTextAttributes(TextAttributesKey enforcedAttributes)
          Sets the text attributes key used for highlighting the annotation.
 void setTooltip(java.lang.String tooltip)
          Sets the tooltip for the annotation (shown when hovering the mouse in the gutter bar).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Annotation

public Annotation(int startOffset,
                  int endOffset,
                  HighlightSeverity severity,
                  java.lang.String message,
                  java.lang.String tooltip)
Creates an instance of the annotation.

Parameters:
startOffset - the start offset of the text range covered by the annotation.
endOffset - the end offset of the text range covered by the annotation.
severity - the severity of the problem indicated by the annotation (highlight, warning or error).
message - the description of the annotation (shown in the status bar or by "View | Error Description" action)
tooltip - the tooltip for the annotation (shown when hovering the mouse in the gutter bar)
See Also:
AnnotationHolder.createErrorAnnotation(com.intellij.psi.PsiElement, java.lang.String), AnnotationHolder.createWarningAnnotation(com.intellij.psi.PsiElement, java.lang.String), AnnotationHolder.createInfoAnnotation(com.intellij.psi.PsiElement, java.lang.String)
Method Detail

registerFix

public void registerFix(IntentionAction fix)
Registers a quick fix for the annotation.

Parameters:
fix - the quick fix implementation.

registerFix

public void registerFix(IntentionAction fix,
                        TextRange range)
Registers a quick fix for the annotation which is only available on a particular range of text within the annotation.

Parameters:
fix - the quick fix implementation.
range - the text range (relative to the document) where the quick fix is available.

setNeedsUpdateOnTyping

public void setNeedsUpdateOnTyping(boolean b)
Sets a flag indicating what happens with the annotation when the user starts typing. If the parameter is true, the annotation is removed as soon as the user starts typing and is possibly restored by a later run of the annotator. If false, the annotation remains in place while the user is typing.

Parameters:
b - whether the annotation needs to be removed on typing.
See Also:
needsUpdateOnTyping()

needsUpdateOnTyping

public boolean needsUpdateOnTyping()
Gets a flag indicating what happens with the annotation when the user starts typing.

Returns:
true if the annotation is removed on typing, false otherwise.
See Also:
setNeedsUpdateOnTyping(boolean)

getStartOffset

public int getStartOffset()
Returns the start offset of the text range covered by the annotation.

Returns:
the annotation start offset.

getEndOffset

public int getEndOffset()
Returns the end offset of the text range covered by the annotation.

Returns:
the annotation end offset.

getSeverity

public HighlightSeverity getSeverity()
Returns the severity of the problem indicated by the annotation (highlight, warning or error).

Returns:
the annotation severity.

getHighlightType

public ProblemHighlightType getHighlightType()
If the annotation matches one of commonly encountered problem types, returns the ID of that problem type so that an appropriate color can be used for highlighting the annotation.

Returns:
the common problem type.

getTextAttributes

public TextAttributesKey getTextAttributes()
Returns the text attribute key used for highlighting the annotation. If not specified explicitly, the key is determined automatically based on the problem highlight type and the annotation severity.

Returns:
the text attribute key used for highlighting

getQuickFixes

@Nullable
public java.util.List<Pair<IntentionAction,TextRange>> getQuickFixes()
Returns the list of quick fixes registered for the annotation.

Returns:
the list of quick fixes, or null if none have been registered.

getMessage

public java.lang.String getMessage()
Returns the description of the annotation (shown in the status bar or by "View | Error Description" action).

Returns:
the description of the annotation.

getTooltip

public java.lang.String getTooltip()
Returns the tooltip for the annotation (shown when hovering the mouse in the gutter bar).

Returns:
the tooltip for the annotation.

setTooltip

public void setTooltip(java.lang.String tooltip)
Sets the tooltip for the annotation (shown when hovering the mouse in the gutter bar).

Parameters:
tooltip - the tooltip text.

setHighlightType

public void setHighlightType(ProblemHighlightType highlightType)
If the annotation matches one of commonly encountered problem types, sets the ID of that problem type so that an appropriate color can be used for highlighting the annotation.

Parameters:
highlightType - the ID of the problem type.

setTextAttributes

public void setTextAttributes(TextAttributesKey enforcedAttributes)
Sets the text attributes key used for highlighting the annotation.

Parameters:
enforcedAttributes - the text attributes key for highlighting,

isAfterEndOfLine

public boolean isAfterEndOfLine()
Returns the flag indicating whether the annotation is shown after the end of line containing it.

Returns:
true if the annotation is shown after the end of line, false otherwise.

setAfterEndOfLine

public void setAfterEndOfLine(boolean afterEndOfLine)
Sets the flag indicating whether the annotation is shown after the end of line containing it. This can be used for errors like "unclosed string literal", "missing semicolon" and so on.

Parameters:
afterEndOfLine - true if the annotation should be shown after the end of line, false otherwise.