Class PsiUtils

java.lang.Object
org.openrewrite.python.internal.PsiUtils

public abstract class PsiUtils extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    elementsBetween(@Nullable com.intellij.psi.PsiElement begin, @Nullable com.intellij.psi.PsiElement endInclusive)
     
    static com.intellij.psi.PsiElement
    findChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType)
     
    static com.intellij.psi.PsiElement
    findFirstChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType, com.jetbrains.python.psi.PyElementType... otherElementTypes)
     
    static org.openrewrite.java.tree.Space
    findLeadingSpaceInTree(com.intellij.psi.PsiElement current)
    Finds the space immediately preceding the element in the document text.
    static com.intellij.psi.impl.source.tree.LeafPsiElement
    findPreviousSiblingToken(com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType)
     
    static com.intellij.psi.PsiElement
    findSpaceEnd(@Nullable com.intellij.psi.PsiElement spaceElement)
     
    static com.intellij.psi.PsiElement
    findSpaceStart(@Nullable com.intellij.psi.PsiElement spaceElement)
     
    static boolean
    isHiddenElement(com.intellij.psi.PsiElement element)
     
    static boolean
    isLeafToken(@Nullable com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType)
     
    static boolean
    isWhitespaceOrComment(@Nullable com.intellij.psi.PsiElement element)
     
    static boolean
    matchesTokenSequence(com.intellij.psi.PsiElement current, com.jetbrains.python.psi.PyElementType... tokens)
     
    static @Nullable com.intellij.psi.PsiElement
    maybeFindChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType)
     
    static @Nullable com.intellij.psi.PsiElement
    maybeFindFirstChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType, com.jetbrains.python.psi.PyElementType... otherElementTypes)
     
    static @Nullable com.intellij.psi.impl.source.tree.LeafPsiElement
    maybeFindPreviousSiblingToken(com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType)
     
    static org.openrewrite.java.tree.Space
    mergeSpace(com.intellij.psi.PsiElement firstSpaceOrComment, com.intellij.psi.PsiElement lastSpaceOrComment)
     
    static @Nullable com.intellij.psi.PsiElement
    nextSiblingSkipWhitespace(@Nullable com.intellij.psi.PsiElement element)
     
    static org.openrewrite.java.tree.Space
    spaceAfter(@Nullable com.intellij.psi.PsiElement element)
    Collects all continuous space (whitespace and comments) that immediately follows an element as a sibling.
    static org.openrewrite.java.tree.Space
    spaceBefore(@Nullable com.intellij.psi.PsiElement element)
    Collects all continuous space (whitespace and comments) that immediately precedes an element as a sibling.
    static org.openrewrite.java.tree.Space
    trailingSpace(@Nullable com.intellij.psi.PsiElement element)
    Collects trailing space inside of an element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isHiddenElement

      public static boolean isHiddenElement(com.intellij.psi.PsiElement element)
    • isLeafToken

      public static boolean isLeafToken(@Nullable @Nullable com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType)
    • maybeFindChildToken

      @Nullable public static @Nullable com.intellij.psi.PsiElement maybeFindChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType)
    • maybeFindFirstChildToken

      @Nullable public static @Nullable com.intellij.psi.PsiElement maybeFindFirstChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType, com.jetbrains.python.psi.PyElementType... otherElementTypes)
    • findFirstChildToken

      public static com.intellij.psi.PsiElement findFirstChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType, com.jetbrains.python.psi.PyElementType... otherElementTypes)
    • findChildToken

      public static com.intellij.psi.PsiElement findChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType)
    • nextSiblingSkipWhitespace

      @Nullable public static @Nullable com.intellij.psi.PsiElement nextSiblingSkipWhitespace(@Nullable @Nullable com.intellij.psi.PsiElement element)
    • maybeFindPreviousSiblingToken

      @Nullable public static @Nullable com.intellij.psi.impl.source.tree.LeafPsiElement maybeFindPreviousSiblingToken(com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType)
    • findLeadingSpaceInTree

      public static org.openrewrite.java.tree.Space findLeadingSpaceInTree(com.intellij.psi.PsiElement current)
      Finds the space immediately preceding the element in the document text.
      This is *not the same* as spaceBefore(com.intellij.psi.PsiElement), which only collects space from preceding sibling PSI nodes.
      This method will also look in preceding sibling nodes, but will also continue up the tree to parent nodes (and their preceding siblings) until either whitespace is found or the current text offset has changed.
    • findPreviousSiblingToken

      public static com.intellij.psi.impl.source.tree.LeafPsiElement findPreviousSiblingToken(com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType)
    • matchesTokenSequence

      public static boolean matchesTokenSequence(com.intellij.psi.PsiElement current, com.jetbrains.python.psi.PyElementType... tokens)
    • findSpaceStart

      public static com.intellij.psi.PsiElement findSpaceStart(@Nullable @Nullable com.intellij.psi.PsiElement spaceElement)
    • findSpaceEnd

      public static com.intellij.psi.PsiElement findSpaceEnd(@Nullable @Nullable com.intellij.psi.PsiElement spaceElement)
    • spaceBefore

      public static org.openrewrite.java.tree.Space spaceBefore(@Nullable @Nullable com.intellij.psi.PsiElement element)
      Collects all continuous space (whitespace and comments) that immediately precedes an element as a sibling. This method will skip zero-length placeholder elements before looking for whitespace.
    • spaceAfter

      public static org.openrewrite.java.tree.Space spaceAfter(@Nullable @Nullable com.intellij.psi.PsiElement element)
      Collects all continuous space (whitespace and comments) that immediately follows an element as a sibling. This method will skip zero-length placeholder elements before looking for whitespace.
    • trailingSpace

      public static org.openrewrite.java.tree.Space trailingSpace(@Nullable @Nullable com.intellij.psi.PsiElement element)
      Collects trailing space inside of an element.

      The PSI model for some elements (including statements) stores whitespace following an element inside of that element, up to the first newline. This includes trailing comments.

    • mergeSpace

      public static org.openrewrite.java.tree.Space mergeSpace(com.intellij.psi.PsiElement firstSpaceOrComment, com.intellij.psi.PsiElement lastSpaceOrComment)
    • isWhitespaceOrComment

      public static boolean isWhitespaceOrComment(@Nullable @Nullable com.intellij.psi.PsiElement element)
    • elementsBetween

      public static PsiUtils.PsiElementCursor elementsBetween(@Nullable @Nullable com.intellij.psi.PsiElement begin, @Nullable @Nullable com.intellij.psi.PsiElement endInclusive)