Package org.openrewrite.python.internal
Class PsiUtils
java.lang.Object
org.openrewrite.python.internal.PsiUtils
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic PsiUtils.PsiElementCursorelementsBetween(@Nullable com.intellij.psi.PsiElement begin, @Nullable com.intellij.psi.PsiElement endInclusive) static com.intellij.psi.PsiElementfindChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType) static com.intellij.psi.PsiElementfindFirstChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType, com.jetbrains.python.psi.PyElementType... otherElementTypes) static org.openrewrite.java.tree.SpacefindLeadingSpaceInTree(com.intellij.psi.PsiElement current) Finds the space immediately preceding the element in the document text.static com.intellij.psi.impl.source.tree.LeafPsiElementfindPreviousSiblingToken(com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType) static com.intellij.psi.PsiElementfindSpaceEnd(@Nullable com.intellij.psi.PsiElement spaceElement) static com.intellij.psi.PsiElementfindSpaceStart(@Nullable com.intellij.psi.PsiElement spaceElement) static booleanisHiddenElement(com.intellij.psi.PsiElement element) static booleanisLeafToken(@Nullable com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType) static booleanisWhitespaceOrComment(@Nullable com.intellij.psi.PsiElement element) static booleanmatchesTokenSequence(com.intellij.psi.PsiElement current, com.jetbrains.python.psi.PyElementType... tokens) static @Nullable com.intellij.psi.PsiElementmaybeFindChildToken(com.intellij.psi.PsiElement parent, com.jetbrains.python.psi.PyElementType elementType) static @Nullable com.intellij.psi.PsiElementmaybeFindFirstChildToken(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.LeafPsiElementmaybeFindPreviousSiblingToken(com.intellij.psi.PsiElement element, com.jetbrains.python.psi.PyElementType elementType) static org.openrewrite.java.tree.SpacemergeSpace(com.intellij.psi.PsiElement firstSpaceOrComment, com.intellij.psi.PsiElement lastSpaceOrComment) static @Nullable com.intellij.psi.PsiElementnextSiblingSkipWhitespace(@Nullable com.intellij.psi.PsiElement element) static org.openrewrite.java.tree.SpacespaceAfter(@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.SpacespaceBefore(@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.SpacetrailingSpace(@Nullable com.intellij.psi.PsiElement element) Collects trailing space inside of an element.
-
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* asspaceBefore(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)
-