org.jetbrains.kotlin.psi
Class KtPsiUtil

java.lang.Object
  extended by org.jetbrains.kotlin.psi.KtPsiUtil

public class KtPsiUtil
extends java.lang.Object


Nested Class Summary
static interface KtPsiUtil.KtExpressionWrapper
           
 
Field Summary
static com.google.common.base.Predicate<KtElement> ANY_JET_ELEMENT
           
 
Method Summary
static boolean areParenthesesNecessary(KtExpression innerExpression, KtExpression currentInner, KtElement parentElement)
           
static boolean areParenthesesUseless(KtParenthesizedExpression expression)
           
static com.intellij.psi.PsiElement ascendIfPropertyAccessor(com.intellij.psi.PsiElement element)
           
static boolean checkVariableDeclarationInBlock(KtBlockExpression block, java.lang.String varName)
           
static boolean checkWhenExpressionHasSingleElse(KtWhenExpression whenExpression)
           
static KtExpression deparenthesize(KtExpression expression)
           
static KtExpression deparenthesizeOnce(KtExpression expression)
           
static com.intellij.psi.PsiElement findChildByType(com.intellij.psi.PsiElement element, com.intellij.psi.tree.IElementType type)
           
static java.util.Set<KtElement> findRootExpressions(java.util.Collection<KtElement> unreachableElements)
           
static Name getAliasName(KtImportDirective importDirective)
           
static KtClassOrObject getClassIfParameterIsProperty(KtParameter jetParameter)
           
static Name getConventionName(KtSimpleNameExpression simpleNameExpression)
           
static
<T extends com.intellij.psi.PsiElement>
T
getDirectParentOfTypeForBlock(KtBlockExpression block, java.lang.Class<T> aClass)
           
static KtElement getEnclosingElementForLocalDeclaration(KtDeclaration declaration)
           
static KtElement getEnclosingElementForLocalDeclaration(KtDeclaration declaration, boolean skipParameters)
           
static KtExpression getExpressionOrLastStatementInBlock(KtExpression expression)
           
static
<T extends com.intellij.psi.PsiElement>
T
getLastChildByType(com.intellij.psi.PsiElement root, java.lang.Class<? extends T>... elementTypes)
           
static KtExpression getLastElementDeparenthesized(KtExpression expression, StatementFilter statementFilter)
           
static KtSimpleNameExpression getLastReference(KtExpression importedReference)
           
static KtExpression getLastStatementInABlock(KtBlockExpression blockExpression)
           
static java.lang.String getNullableText(com.intellij.psi.PsiElement element)
           
static KtToken getOperationToken(KtOperationExpression expression)
           
static KtClassOrObject getOutermostClassOrObject(KtClassOrObject classOrObject)
           
static KtElement getOutermostDescendantElement(com.intellij.psi.PsiElement root, boolean first, com.google.common.base.Predicate<KtElement> predicate)
           
static com.intellij.psi.PsiElement getOutermostParent(com.intellij.psi.PsiElement element, com.intellij.psi.PsiElement upperBound, boolean strict)
           
static java.lang.String getPackageName(KtElement element)
           
static KtExpression getParentCallIfPresent(KtExpression expression)
           
static com.intellij.psi.PsiElement getPreviousWord(com.intellij.psi.PsiElement element, java.lang.String word, com.intellij.psi.tree.TokenSet suffixTokens)
          Example: code: async* {} element = "{}" word = "async" suffixTokens = [+, -, *, /, %] result = async
static KtScript getScript(KtDeclaration namedDeclaration)
           
static Name getShortName(KtAnnotationEntry annotation)
           
static java.lang.String getText(com.intellij.psi.PsiElement element)
           
static com.intellij.psi.PsiElement getTopmostParentOfTypes(com.intellij.psi.PsiElement element, java.lang.Class<? extends com.intellij.psi.PsiElement>... parentTypes)
           
static boolean isAbstract(KtDeclarationWithBody declaration)
           
static boolean isAssignment(com.intellij.psi.PsiElement element)
           
static boolean isBackingFieldReference(DeclarationDescriptor descriptor)
           
static boolean isDeprecated(KtModifierListOwner owner)
           
static boolean isInComment(com.intellij.psi.PsiElement element)
          CommentUtilCore.isComment fails if element inside comment.
static boolean isLabelIdentifierExpression(com.intellij.psi.PsiElement element)
           
static boolean isLHSOfDot(KtExpression expression)
           
static boolean isLocal(KtDeclaration declaration)
           
static boolean isNullConstant(KtExpression expression)
           
static boolean isOrdinaryAssignment(com.intellij.psi.PsiElement element)
           
static boolean isScriptDeclaration(KtDeclaration namedDeclaration)
           
static boolean isSelectorInQualified(KtSimpleNameExpression nameExpression)
           
static boolean isTrait(KtClassOrObject classOrObject)
           
static boolean isTrueConstant(KtExpression condition)
           
static boolean isVariableNotParameterDeclaration(KtDeclaration declaration)
           
static com.intellij.psi.PsiElement prevLeafIgnoringWhitespaceAndComments(com.intellij.psi.PsiElement element)
           
static KtModifierList replaceModifierList(KtModifierListOwner owner, KtModifierList modifierList)
           
static KtExpression safeDeparenthesize(KtExpression expression)
           
static Name safeName(java.lang.String name)
           
static com.intellij.psi.PsiElement skipSiblingsBackwardByPredicate(com.intellij.psi.PsiElement element, com.google.common.base.Predicate<com.intellij.psi.PsiElement> elementsToSkip)
           
static com.intellij.psi.PsiElement skipTrailingWhitespacesAndComments(com.intellij.psi.PsiElement element)
           
static FqName toQualifiedName(KtUserType userType)
           
static java.lang.String unquoteIdentifier(java.lang.String quoted)
           
static java.lang.String unquoteIdentifierOrFieldReference(java.lang.String quoted)
           
static
<D> void
visitChildren(KtElement element, KtVisitor<java.lang.Void,D> visitor, D data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANY_JET_ELEMENT

public static final com.google.common.base.Predicate<KtElement> ANY_JET_ELEMENT
Method Detail

visitChildren

public static <D> void visitChildren(@NotNull
                                     KtElement element,
                                     @NotNull
                                     KtVisitor<java.lang.Void,D> visitor,
                                     D data)

safeDeparenthesize

@NotNull
public static KtExpression safeDeparenthesize(@NotNull
                                                      KtExpression expression)

deparenthesize

@Nullable
public static KtExpression deparenthesize(@Nullable
                                                   KtExpression expression)

deparenthesizeOnce

@Nullable
public static KtExpression deparenthesizeOnce(@Nullable
                                                       KtExpression expression)

safeName

@NotNull
public static Name safeName(@Nullable
                                    java.lang.String name)

findRootExpressions

@NotNull
public static java.util.Set<KtElement> findRootExpressions(@NotNull
                                                                   java.util.Collection<KtElement> unreachableElements)

unquoteIdentifier

@NotNull
public static java.lang.String unquoteIdentifier(@NotNull
                                                         java.lang.String quoted)

unquoteIdentifierOrFieldReference

@NotNull
public static java.lang.String unquoteIdentifierOrFieldReference(@NotNull
                                                                         java.lang.String quoted)

toQualifiedName

@Nullable
public static FqName toQualifiedName(@NotNull
                                              KtUserType userType)
Returns:
null iff the tye has syntactic errors

getShortName

@Nullable
public static Name getShortName(@NotNull
                                         KtAnnotationEntry annotation)

isDeprecated

public static boolean isDeprecated(@NotNull
                                   KtModifierListOwner owner)

getDirectParentOfTypeForBlock

@Nullable
public static <T extends com.intellij.psi.PsiElement> T getDirectParentOfTypeForBlock(@NotNull
                                                                                               KtBlockExpression block,
                                                                                               @NotNull
                                                                                               java.lang.Class<T> aClass)

getAliasName

@Nullable
public static Name getAliasName(@NotNull
                                         KtImportDirective importDirective)

getLastReference

@Nullable
public static KtSimpleNameExpression getLastReference(@NotNull
                                                               KtExpression importedReference)

isSelectorInQualified

public static boolean isSelectorInQualified(@NotNull
                                            KtSimpleNameExpression nameExpression)

isLHSOfDot

public static boolean isLHSOfDot(@NotNull
                                 KtExpression expression)

isScriptDeclaration

public static boolean isScriptDeclaration(@NotNull
                                          KtDeclaration namedDeclaration)

getScript

@Nullable
public static KtScript getScript(@NotNull
                                          KtDeclaration namedDeclaration)

isVariableNotParameterDeclaration

public static boolean isVariableNotParameterDeclaration(@NotNull
                                                        KtDeclaration declaration)

getConventionName

@Nullable
public static Name getConventionName(@NotNull
                                              KtSimpleNameExpression simpleNameExpression)

getTopmostParentOfTypes

@Nullable
@Contract(value="null, _ -> null")
public static com.intellij.psi.PsiElement getTopmostParentOfTypes(@Nullable
                                                                                    com.intellij.psi.PsiElement element,
                                                                                    @NotNull
                                                                                    java.lang.Class<? extends com.intellij.psi.PsiElement>... parentTypes)

isNullConstant

public static boolean isNullConstant(@NotNull
                                     KtExpression expression)

isTrueConstant

public static boolean isTrueConstant(@Nullable
                                     KtExpression condition)

isAbstract

public static boolean isAbstract(@NotNull
                                 KtDeclarationWithBody declaration)

isBackingFieldReference

public static boolean isBackingFieldReference(@Nullable
                                              DeclarationDescriptor descriptor)

getExpressionOrLastStatementInBlock

@Nullable
public static KtExpression getExpressionOrLastStatementInBlock(@Nullable
                                                                        KtExpression expression)

getLastStatementInABlock

@Nullable
public static KtExpression getLastStatementInABlock(@Nullable
                                                             KtBlockExpression blockExpression)

isTrait

public static boolean isTrait(@NotNull
                              KtClassOrObject classOrObject)

getOutermostClassOrObject

@Nullable
public static KtClassOrObject getOutermostClassOrObject(@NotNull
                                                                 KtClassOrObject classOrObject)

getClassIfParameterIsProperty

@Nullable
public static KtClassOrObject getClassIfParameterIsProperty(@NotNull
                                                                     KtParameter jetParameter)

areParenthesesUseless

public static boolean areParenthesesUseless(@NotNull
                                            KtParenthesizedExpression expression)

areParenthesesNecessary

public static boolean areParenthesesNecessary(@NotNull
                                              KtExpression innerExpression,
                                              @NotNull
                                              KtExpression currentInner,
                                              @NotNull
                                              KtElement parentElement)

isAssignment

public static boolean isAssignment(@NotNull
                                   com.intellij.psi.PsiElement element)

isOrdinaryAssignment

public static boolean isOrdinaryAssignment(@NotNull
                                           com.intellij.psi.PsiElement element)

checkVariableDeclarationInBlock

public static boolean checkVariableDeclarationInBlock(@NotNull
                                                      KtBlockExpression block,
                                                      @NotNull
                                                      java.lang.String varName)

checkWhenExpressionHasSingleElse

public static boolean checkWhenExpressionHasSingleElse(@NotNull
                                                       KtWhenExpression whenExpression)

skipTrailingWhitespacesAndComments

@Nullable
public static com.intellij.psi.PsiElement skipTrailingWhitespacesAndComments(@Nullable
                                                                                      com.intellij.psi.PsiElement element)

prevLeafIgnoringWhitespaceAndComments

@Nullable
public static com.intellij.psi.PsiElement prevLeafIgnoringWhitespaceAndComments(@NotNull
                                                                                         com.intellij.psi.PsiElement element)

getPreviousWord

@Nullable
public static com.intellij.psi.PsiElement getPreviousWord(@NotNull
                                                                   com.intellij.psi.PsiElement element,
                                                                   @NotNull
                                                                   java.lang.String word,
                                                                   @NotNull
                                                                   com.intellij.psi.tree.TokenSet suffixTokens)
Example: code: async* {} element = "{}" word = "async" suffixTokens = [+, -, *, /, %] result = async


getText

@NotNull
public static java.lang.String getText(@Nullable
                                               com.intellij.psi.PsiElement element)

getNullableText

@Nullable
public static java.lang.String getNullableText(@Nullable
                                                        com.intellij.psi.PsiElement element)

isInComment

public static boolean isInComment(com.intellij.psi.PsiElement element)
CommentUtilCore.isComment fails if element inside comment. Also, we can not add KDocTokens to COMMENTS TokenSet, because it is used in KotlinParserDefinition.getCommentTokens(), and therefor all COMMENTS tokens will be ignored by PsiBuilder.

Parameters:
element -
Returns:

getOutermostParent

@Nullable
public static com.intellij.psi.PsiElement getOutermostParent(@NotNull
                                                                      com.intellij.psi.PsiElement element,
                                                                      @NotNull
                                                                      com.intellij.psi.PsiElement upperBound,
                                                                      boolean strict)

getLastChildByType

public static <T extends com.intellij.psi.PsiElement> T getLastChildByType(@NotNull
                                                                           com.intellij.psi.PsiElement root,
                                                                           @NotNull
                                                                           java.lang.Class<? extends T>... elementTypes)

getOutermostDescendantElement

@Nullable
public static KtElement getOutermostDescendantElement(@Nullable
                                                               com.intellij.psi.PsiElement root,
                                                               boolean first,
                                                               @NotNull
                                                               com.google.common.base.Predicate<KtElement> predicate)

findChildByType

@Nullable
public static com.intellij.psi.PsiElement findChildByType(@NotNull
                                                                   com.intellij.psi.PsiElement element,
                                                                   @NotNull
                                                                   com.intellij.psi.tree.IElementType type)

skipSiblingsBackwardByPredicate

@Nullable
public static com.intellij.psi.PsiElement skipSiblingsBackwardByPredicate(@Nullable
                                                                                   com.intellij.psi.PsiElement element,
                                                                                   com.google.common.base.Predicate<com.intellij.psi.PsiElement> elementsToSkip)

ascendIfPropertyAccessor

public static com.intellij.psi.PsiElement ascendIfPropertyAccessor(com.intellij.psi.PsiElement element)

replaceModifierList

@Nullable
public static KtModifierList replaceModifierList(@NotNull
                                                          KtModifierListOwner owner,
                                                          @Nullable
                                                          KtModifierList modifierList)

getPackageName

@Nullable
public static java.lang.String getPackageName(@NotNull
                                                       KtElement element)

getEnclosingElementForLocalDeclaration

@Nullable
public static KtElement getEnclosingElementForLocalDeclaration(@NotNull
                                                                        KtDeclaration declaration)

getEnclosingElementForLocalDeclaration

@Nullable
public static KtElement getEnclosingElementForLocalDeclaration(@NotNull
                                                                        KtDeclaration declaration,
                                                                        boolean skipParameters)

isLocal

public static boolean isLocal(@NotNull
                              KtDeclaration declaration)

getOperationToken

@Nullable
public static KtToken getOperationToken(@NotNull
                                                 KtOperationExpression expression)

isLabelIdentifierExpression

public static boolean isLabelIdentifierExpression(com.intellij.psi.PsiElement element)

getParentCallIfPresent

@Nullable
public static KtExpression getParentCallIfPresent(@NotNull
                                                           KtExpression expression)

getLastElementDeparenthesized

@Nullable
public static KtExpression getLastElementDeparenthesized(@Nullable
                                                                  KtExpression expression,
                                                                  @NotNull
                                                                  StatementFilter statementFilter)