cleanup KtClassOrObject and KtClass
This commit is contained in:
committed by
Mikhail Glukhikh
parent
214e1d3015
commit
2198a8c8d0
@@ -62,7 +62,7 @@ open class KtClass : KtClassOrObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun getQualifiedName(): String? {
|
protected fun getQualifiedName(): String? {
|
||||||
val stub = getStub()
|
val stub = stub
|
||||||
if (stub != null) {
|
if (stub != null) {
|
||||||
val fqName = stub.getFqName()
|
val fqName = stub.getFqName()
|
||||||
return fqName?.asString()
|
return fqName?.asString()
|
||||||
@@ -71,12 +71,12 @@ open class KtClass : KtClassOrObject {
|
|||||||
val parts = ArrayList<String>()
|
val parts = ArrayList<String>()
|
||||||
var current: KtClassOrObject? = this
|
var current: KtClassOrObject? = this
|
||||||
while (current != null) {
|
while (current != null) {
|
||||||
parts.add(current.getName()!!)
|
parts.add(current.name!!)
|
||||||
current = PsiTreeUtil.getParentOfType<KtClassOrObject>(current, KtClassOrObject::class.java)
|
current = PsiTreeUtil.getParentOfType<KtClassOrObject>(current, KtClassOrObject::class.java)
|
||||||
}
|
}
|
||||||
val file = getContainingFile()
|
val file = containingFile
|
||||||
if (file !is KtFile) return null
|
if (file !is KtFile) return null
|
||||||
val fileQualifiedName = file.getPackageFqName().asString()
|
val fileQualifiedName = file.packageFqName.asString()
|
||||||
if (!fileQualifiedName.isEmpty()) {
|
if (!fileQualifiedName.isEmpty()) {
|
||||||
parts.add(fileQualifiedName)
|
parts.add(fileQualifiedName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ abstract class KtClassOrObject :
|
|||||||
constructor(stub: KotlinClassOrObjectStub<out KtClassOrObject>, nodeType: IStubElementType<*, *>) : super(stub, nodeType)
|
constructor(stub: KotlinClassOrObjectStub<out KtClassOrObject>, nodeType: IStubElementType<*, *>) : super(stub, nodeType)
|
||||||
|
|
||||||
fun getSuperTypeList(): KtSuperTypeList? = getStubOrPsiChild(KtStubElementTypes.SUPER_TYPE_LIST)
|
fun getSuperTypeList(): KtSuperTypeList? = getStubOrPsiChild(KtStubElementTypes.SUPER_TYPE_LIST)
|
||||||
open fun getSuperTypeListEntries(): List<KtSuperTypeListEntry> = getSuperTypeList()?.getEntries().orEmpty()
|
open fun getSuperTypeListEntries(): List<KtSuperTypeListEntry> = getSuperTypeList()?.entries.orEmpty()
|
||||||
|
|
||||||
fun addSuperTypeListEntry(superTypeListEntry: KtSuperTypeListEntry): KtSuperTypeListEntry {
|
fun addSuperTypeListEntry(superTypeListEntry: KtSuperTypeListEntry): KtSuperTypeListEntry {
|
||||||
getSuperTypeList()?.let {
|
getSuperTypeList()?.let {
|
||||||
@@ -42,16 +42,16 @@ abstract class KtClassOrObject :
|
|||||||
}
|
}
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(this)
|
val psiFactory = KtPsiFactory(this)
|
||||||
val specifierListToAdd = psiFactory.createSuperTypeCallEntry("A()").replace(superTypeListEntry).getParent()
|
val specifierListToAdd = psiFactory.createSuperTypeCallEntry("A()").replace(superTypeListEntry).parent
|
||||||
val colon = addBefore(psiFactory.createColon(), getBody())
|
val colon = addBefore(psiFactory.createColon(), getBody())
|
||||||
return (addAfter(specifierListToAdd, colon) as KtSuperTypeList).getEntries().first()
|
return (addAfter(specifierListToAdd, colon) as KtSuperTypeList).entries.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeSuperTypeListEntry(superTypeListEntry: KtSuperTypeListEntry) {
|
fun removeSuperTypeListEntry(superTypeListEntry: KtSuperTypeListEntry) {
|
||||||
val specifierList = getSuperTypeList() ?: return
|
val specifierList = getSuperTypeList() ?: return
|
||||||
assert(superTypeListEntry.getParent() === specifierList)
|
assert(superTypeListEntry.parent === specifierList)
|
||||||
|
|
||||||
if (specifierList.getEntries().size > 1) {
|
if (specifierList.entries.size > 1) {
|
||||||
EditCommaSeparatedListHelper.removeItem<KtElement>(superTypeListEntry)
|
EditCommaSeparatedListHelper.removeItem<KtElement>(superTypeListEntry)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -65,33 +65,33 @@ abstract class KtClassOrObject :
|
|||||||
|
|
||||||
fun addDeclaration(declaration: KtDeclaration): KtDeclaration {
|
fun addDeclaration(declaration: KtDeclaration): KtDeclaration {
|
||||||
val body = getOrCreateBody()
|
val body = getOrCreateBody()
|
||||||
val anchor = PsiTreeUtil.skipSiblingsBackward(body.rBrace ?: body.getLastChild()!!, PsiWhiteSpace::class.java)
|
val anchor = PsiTreeUtil.skipSiblingsBackward(body.rBrace ?: body.lastChild!!, PsiWhiteSpace::class.java)
|
||||||
return body.addAfter(declaration, anchor) as KtDeclaration
|
return body.addAfter(declaration, anchor) as KtDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addDeclarationAfter(declaration: KtDeclaration, anchor: PsiElement?): KtDeclaration {
|
fun addDeclarationAfter(declaration: KtDeclaration, anchor: PsiElement?): KtDeclaration {
|
||||||
val anchorBefore = anchor ?: getDeclarations().lastOrNull() ?: return addDeclaration(declaration)
|
val anchorBefore = anchor ?: declarations.lastOrNull() ?: return addDeclaration(declaration)
|
||||||
return getOrCreateBody().addAfter(declaration, anchorBefore) as KtDeclaration
|
return getOrCreateBody().addAfter(declaration, anchorBefore) as KtDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addDeclarationBefore(declaration: KtDeclaration, anchor: PsiElement?): KtDeclaration {
|
fun addDeclarationBefore(declaration: KtDeclaration, anchor: PsiElement?): KtDeclaration {
|
||||||
val anchorAfter = anchor ?: getDeclarations().firstOrNull() ?: return addDeclaration(declaration)
|
val anchorAfter = anchor ?: declarations.firstOrNull() ?: return addDeclaration(declaration)
|
||||||
return getOrCreateBody().addBefore(declaration, anchorAfter) as KtDeclaration
|
return getOrCreateBody().addBefore(declaration, anchorAfter) as KtDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTopLevel(): Boolean = getStub()?.isTopLevel() ?: (getParent() is KtFile)
|
fun isTopLevel(): Boolean = stub?.isTopLevel() ?: (parent is KtFile)
|
||||||
|
|
||||||
fun isLocal(): Boolean = getStub()?.isLocal() ?: KtPsiUtil.isLocal(this)
|
fun isLocal(): Boolean = stub?.isLocal() ?: KtPsiUtil.isLocal(this)
|
||||||
|
|
||||||
override fun getDeclarations() = getBody()?.getDeclarations().orEmpty()
|
override fun getDeclarations() = getBody()?.declarations.orEmpty()
|
||||||
|
|
||||||
override fun getPresentation(): ItemPresentation? = ItemPresentationProviders.getItemPresentation(this)
|
override fun getPresentation(): ItemPresentation? = ItemPresentationProviders.getItemPresentation(this)
|
||||||
|
|
||||||
fun getPrimaryConstructor(): KtPrimaryConstructor? = getStubOrPsiChild(KtStubElementTypes.PRIMARY_CONSTRUCTOR)
|
fun getPrimaryConstructor(): KtPrimaryConstructor? = getStubOrPsiChild(KtStubElementTypes.PRIMARY_CONSTRUCTOR)
|
||||||
|
|
||||||
fun getPrimaryConstructorModifierList(): KtModifierList? = getPrimaryConstructor()?.getModifierList()
|
fun getPrimaryConstructorModifierList(): KtModifierList? = getPrimaryConstructor()?.modifierList
|
||||||
fun getPrimaryConstructorParameterList(): KtParameterList? = getPrimaryConstructor()?.getValueParameterList()
|
fun getPrimaryConstructorParameterList(): KtParameterList? = getPrimaryConstructor()?.valueParameterList
|
||||||
fun getPrimaryConstructorParameters(): List<KtParameter> = getPrimaryConstructorParameterList()?.getParameters().orEmpty()
|
fun getPrimaryConstructorParameters(): List<KtParameter> = getPrimaryConstructorParameterList()?.parameters.orEmpty()
|
||||||
|
|
||||||
fun hasExplicitPrimaryConstructor(): Boolean = getPrimaryConstructor() != null
|
fun hasExplicitPrimaryConstructor(): Boolean = getPrimaryConstructor() != null
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ abstract class KtClassOrObject :
|
|||||||
CheckUtil.checkWritable(this);
|
CheckUtil.checkWritable(this);
|
||||||
|
|
||||||
val file = getContainingKtFile();
|
val file = getContainingKtFile();
|
||||||
if (!isTopLevel() || file.getDeclarations().size > 1) {
|
if (!isTopLevel() || file.declarations.size > 1) {
|
||||||
super.delete()
|
super.delete()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user