PsiElement methodCall = ...; // get a method call expression element PsiElement prevSibling = methodCall.getPrevSibling(); if (prevSibling instanceof PsiWhiteSpace) { // if previous sibling is a whitespace, get the one before it prevSibling = prevSibling.getPrevSibling(); } // do something with the previous sibling element
val statement = // get a statement element in a Kotlin file val prevSibling = statement.prevSibling if (prevSibling is PsiWhiteSpace) { // if previous sibling is a whitespace, get the one before it prevSibling = prevSibling.prevSibling } // do something with the previous sibling elementThe PsiElement class and its methods are part of the IntelliJ IDEA Platform API.