Pull Up: Support super-interfaces

This commit is contained in:
Alexey Sedunov
2015-07-20 21:19:45 +03:00
parent 1a09741c0a
commit 7dc430e50b
19 changed files with 266 additions and 19 deletions
@@ -39,6 +39,29 @@ abstract public class JetClassOrObject : JetTypeParameterListOwnerStub<KotlinCla
public fun getDelegationSpecifierList(): JetDelegationSpecifierList? = getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST)
open public fun getDelegationSpecifiers(): List<JetDelegationSpecifier> = getDelegationSpecifierList()?.getDelegationSpecifiers().orEmpty()
public fun addDelegationSpecifier(delegationSpecifier: JetDelegationSpecifier): JetDelegationSpecifier {
getDelegationSpecifierList()?.let {
return EditCommaSeparatedListHelper.addItem(it, getDelegationSpecifiers(), delegationSpecifier)
}
val psiFactory = JetPsiFactory(this)
val specifierListToAdd = psiFactory.createDelegatorToSuperCall("A()").replace(delegationSpecifier).getParent()
val colon = addBefore(psiFactory.createColon(), getBody())
return (addAfter(specifierListToAdd, colon) as JetDelegationSpecifierList).getDelegationSpecifiers().first()
}
public fun removeDelegationSpecifier(delegationSpecifier: JetDelegationSpecifier) {
val specifierList = getDelegationSpecifierList() ?: return
assert(delegationSpecifier.getParent() === specifierList)
if (specifierList.getDelegationSpecifiers().size() > 1) {
EditCommaSeparatedListHelper.removeItem<JetElement>(delegationSpecifier)
}
else {
deleteChildRange(findChildByType<PsiElement>(JetTokens.COLON) ?: specifierList, specifierList)
}
}
public fun getAnonymousInitializers(): List<JetClassInitializer> = getBody()?.getAnonymousInitializers().orEmpty()
public fun getNameAsDeclaration(): JetObjectDeclarationName? =
@@ -378,6 +378,10 @@ public class JetPsiFactory(private val project: Project) {
return createClass("class A: $text").getDelegationSpecifiers().first() as JetDelegatorToSuperCall
}
public fun createDelegatorToSuperClass(text: String): JetDelegatorToSuperClass {
return createClass("class A: $text").getDelegationSpecifiers().first() as JetDelegatorToSuperClass
}
public fun createConstructorDelegationCall(text: String): JetConstructorDelegationCall {
val colonOrEmpty = if (text.isEmpty()) "" else ": "
return createClass("class A { constructor()$colonOrEmpty$text {}").getSecondaryConstructors().first().getDelegationCall()