Class JavaLikeLangLineIndentProvider

java.lang.Object
com.intellij.psi.impl.source.codeStyle.lineIndent.JavaLikeLangLineIndentProvider
All Implemented Interfaces:
LineIndentProvider

public abstract class JavaLikeLangLineIndentProvider extends Object implements LineIndentProvider
  • Constructor Details

    • JavaLikeLangLineIndentProvider

      public JavaLikeLangLineIndentProvider(@NotNull @NotNull CharSequence charSequence, @NotNull @NotNull ITokenSequence tokenSequence, @NotNull @NotNull IndentOptions indentOptions)
  • Method Details

    • getLineIndent

      @Nullable public @Nullable String getLineIndent(int offset)
      Description copied from interface: LineIndentProvider
      Calculates the indent that should be used for the line at specified offset in the specified document.
      Specified by:
      getLineIndent in interface LineIndentProvider
      Parameters:
      offset - The caret offset in the editor.
      Returns:
      The indent string (possibly consisting of tabs and/or white spaces), null if LineIndentProvider can't calculate the indent (in this case indent calculation is delegated to formatter if smart indent mode is used) or LineIndentProvider.DO_NOT_ADJUST constant to leave the current caret position as is without any further formatter-based adjustment.
    • getIndent

      @Nullable protected @Nullable IndentCalculator getIndent(int offset)
    • isInArray

      protected boolean isInArray(int offset)
      Checks that the current offset is inside array. By default it is assumed to be after opening array bracket but can be overridden for more complicated logic, for example, the following case in Java: []{<caret>}.
      Parameters:
      offset - The current offset in the editor.
      Returns:
      true if the position is inside array.
    • dropIndentAfterReturnLike

      protected boolean dropIndentAfterReturnLike(@NotNull @NotNull SemanticEditorPosition statementBeforeSemicolon)
      Checking the document context in position for return-like token (i.e. return, break, continue), after that we need to reduce the indent (for example after break; in switch statement).
      Parameters:
      statementBeforeSemicolon - position in the document context
      Returns:
      true, if need to reduce the indent
    • isColonAfterLabelOrCase

      protected boolean isColonAfterLabelOrCase(@NotNull @NotNull SemanticEditorPosition position)
    • isInsideForLikeConstruction

      protected boolean isInsideForLikeConstruction(SemanticEditorPosition position)
    • getBlockStatementStartOffset

      protected int getBlockStatementStartOffset(@NotNull @NotNull SemanticEditorPosition position)
      Returns the start offset of the statement or new-line-'{' that owns the code block in position.

      Custom implementation for language can overwrite the default behavior for multi-lines statements like

      
          template<class T>
          class A {};
       
      or check indentation after new-line-'{' vs the brace style.
      Parameters:
      position - the position in the code block
    • getDeepBlockStatementStartOffset

      protected int getDeepBlockStatementStartOffset(@NotNull @NotNull SemanticEditorPosition position)
      Returns the start offset of the statement that owns the code block in position
      Parameters:
      position - the position in the code block
    • isStartOfStatementWithOptionalBlock

      protected boolean isStartOfStatementWithOptionalBlock(@NotNull @NotNull SemanticEditorPosition position)
      Returns true if the position starts a statement that can have a code block and the statement is the first in the code line. In C-like languages it is one of if, else, for, while, do, try.
      Parameters:
      position -
    • isIndentProvider

      protected boolean isIndentProvider(@NotNull @NotNull SemanticEditorPosition statementStartPosition, boolean ignoreLabels)
      Checking the document context in position as indent-provider.
      Parameters:
      statementStartPosition - position is the document
      ignoreLabels - true, if labels cannot be used as indent-providers in the context.
      Returns:
      true, if statement is indent-provider (by default)
    • getPosition

      public SemanticEditorPosition getPosition(int offset)
      Returns abstract semantic position in editor for indent calculation.
      Parameters:
      offset - the offset in the editor
    • getIteratorAtPosition

      @NotNull protected @NotNull LexemeIterator getIteratorAtPosition(int offset)
    • mapType

      @Nullable protected abstract SemanticEditorPosition.SyntaxElement mapType(@NotNull @NotNull IElementType tokenType)
    • getIndentInBlock

      @Nullable protected @Nullable Indent getIndentInBlock(@NotNull @NotNull SemanticEditorPosition blockStartPosition)
    • getDefaultIndentFromType

      @Contract("null -> null") protected static Indent getDefaultIndentFromType(@Nullable @Nullable Indent.Type type)
    • isSuitableFor

      @Contract("null -> false") public final boolean isSuitableFor(@Nullable @Nullable Language language)
      Specified by:
      isSuitableFor in interface LineIndentProvider
    • isSuitableForLanguage

      public abstract boolean isSuitableForLanguage(@NotNull @NotNull Language language)
    • getIndentTypeInBrackets

      protected Indent.Type getIndentTypeInBrackets()
    • getIndentInBrackets

      protected Indent getIndentInBrackets()