Pull Up: Initial support
#KT-7330 Fixed
This commit is contained in:
@@ -21,9 +21,11 @@ import com.intellij.lang.ASTNode
|
||||
import com.intellij.navigation.ItemPresentation
|
||||
import com.intellij.navigation.ItemPresentationProviders
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.impl.CheckUtil
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
|
||||
import com.intellij.psi.stubs.IStubElementType
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.JetNodeTypes
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
@@ -46,6 +48,22 @@ abstract public class JetClassOrObject : JetTypeParameterListOwnerStub<KotlinCla
|
||||
|
||||
public fun getOrCreateBody(): JetClassBody = getBody() ?: add(JetPsiFactory(this).createEmptyClassBody()) as JetClassBody
|
||||
|
||||
public fun addDeclaration(declaration: JetDeclaration): JetDeclaration {
|
||||
val body = getOrCreateBody()
|
||||
val anchor = PsiTreeUtil.skipSiblingsBackward(body.getRBrace() ?: body.getLastChild()!!, javaClass<PsiWhiteSpace>())
|
||||
return body.addAfter(declaration, anchor) as JetDeclaration
|
||||
}
|
||||
|
||||
public fun addDeclarationAfter(declaration: JetDeclaration, anchor: PsiElement?): JetDeclaration {
|
||||
val anchorBefore = anchor ?: getDeclarations().lastOrNull() ?: return addDeclaration(declaration)
|
||||
return getOrCreateBody().addAfter(declaration, anchorBefore) as JetDeclaration
|
||||
}
|
||||
|
||||
public fun addDeclarationBefore(declaration: JetDeclaration, anchor: PsiElement?): JetDeclaration {
|
||||
val anchorAfter = anchor ?: getDeclarations().firstOrNull() ?: return addDeclaration(declaration)
|
||||
return getOrCreateBody().addBefore(declaration, anchorAfter) as JetDeclaration
|
||||
}
|
||||
|
||||
public fun isTopLevel(): Boolean = getStub()?.isTopLevel() ?: (getParent() is JetFile)
|
||||
|
||||
public fun isLocal(): Boolean = getStub()?.isLocal() ?: JetPsiUtil.isLocal(this)
|
||||
|
||||
@@ -157,6 +157,11 @@ public class JetProperty extends JetTypeParameterListOwnerStub<KotlinPropertyStu
|
||||
return findChildByType(JetTokens.COLON);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getEqualsToken() {
|
||||
return findChildByType(JetTokens.EQ);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetPropertyAccessor> getAccessors() {
|
||||
return getStubOrPsiChildrenAsList(JetStubElementTypes.PROPERTY_ACCESSOR);
|
||||
|
||||
@@ -134,6 +134,15 @@ public fun JetExpression.getQualifiedExpressionForSelectorOrThis(): JetExpressio
|
||||
return getQualifiedExpressionForSelector() ?: this
|
||||
}
|
||||
|
||||
public fun JetExpression.getQualifiedExpressionForReceiver(): JetQualifiedExpression? {
|
||||
val parent = getParent()
|
||||
return if (parent is JetQualifiedExpression && parent.getReceiverExpression() == this) parent else null
|
||||
}
|
||||
|
||||
public fun JetExpression.getQualifiedExpressionForReceiverOrThis(): JetExpression {
|
||||
return getQualifiedExpressionForReceiver() ?: this
|
||||
}
|
||||
|
||||
public fun JetExpression.isDotReceiver(): Boolean =
|
||||
(getParent() as? JetDotQualifiedExpression)?.getReceiverExpression() == this
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.UserDataHolder
|
||||
import com.intellij.psi.PsiElement
|
||||
|
||||
public class UserDataProperty<in R: UserDataHolder, T : Any>(val key: Key<T>, val default: T? = null) : ReadWriteProperty<R, T?> {
|
||||
override fun get(thisRef: R, desc: kotlin.PropertyMetadata): T? {
|
||||
@@ -39,3 +40,13 @@ public class NotNullableUserDataProperty<in R: UserDataHolder, T : Any>(val key:
|
||||
thisRef.putUserData(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public class CopyableUserDataProperty<in R: PsiElement, T : Any>(val key: Key<T>, val default: T? = null) : ReadWriteProperty<R, T?> {
|
||||
override fun get(thisRef: R, property: PropertyMetadata): T? {
|
||||
return thisRef.getCopyableUserData(key)
|
||||
}
|
||||
|
||||
override fun set(thisRef: R, property: PropertyMetadata, value: T?) {
|
||||
thisRef.putCopyableUserData(key, value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user