Change semantics of getObjectKeyword() function
This commit is contained in:
@@ -51,7 +51,7 @@ object PositioningStrategies {
|
|||||||
when (element) {
|
when (element) {
|
||||||
is KtObjectLiteralExpression -> {
|
is KtObjectLiteralExpression -> {
|
||||||
val objectDeclaration = element.objectDeclaration
|
val objectDeclaration = element.objectDeclaration
|
||||||
val objectKeyword = objectDeclaration.getObjectKeyword()
|
val objectKeyword = objectDeclaration.getObjectKeyword()!!
|
||||||
val delegationSpecifierList = objectDeclaration.getSuperTypeList()
|
val delegationSpecifierList = objectDeclaration.getSuperTypeList()
|
||||||
if (delegationSpecifierList == null) {
|
if (delegationSpecifierList == null) {
|
||||||
return markElement(objectKeyword)
|
return markElement(objectKeyword)
|
||||||
@@ -60,8 +60,8 @@ object PositioningStrategies {
|
|||||||
}
|
}
|
||||||
is KtObjectDeclaration -> {
|
is KtObjectDeclaration -> {
|
||||||
return markRange(
|
return markRange(
|
||||||
element.getObjectKeyword(),
|
element.getObjectKeyword()!!,
|
||||||
element.getNameIdentifier() ?: element.getObjectKeyword()
|
element.getNameIdentifier() ?: element.getObjectKeyword()!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is KtConstructorDelegationCall -> {
|
is KtConstructorDelegationCall -> {
|
||||||
@@ -265,7 +265,7 @@ object PositioningStrategies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val elementToMark = when (element) {
|
val elementToMark = when (element) {
|
||||||
is KtObjectDeclaration -> element.getObjectKeyword()
|
is KtObjectDeclaration -> element.getObjectKeyword()!!
|
||||||
is KtPropertyAccessor -> element.getNamePlaceholder()
|
is KtPropertyAccessor -> element.getNamePlaceholder()
|
||||||
is KtAnonymousInitializer -> element
|
is KtAnonymousInitializer -> element
|
||||||
else -> throw IllegalArgumentException(
|
else -> throw IllegalArgumentException(
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ class KtObjectDeclaration : KtClassOrObject {
|
|||||||
override fun setName(@NonNls name: String): PsiElement {
|
override fun setName(@NonNls name: String): PsiElement {
|
||||||
if (nameIdentifier == null) {
|
if (nameIdentifier == null) {
|
||||||
val psiFactory = KtPsiFactory(project)
|
val psiFactory = KtPsiFactory(project)
|
||||||
val result = addAfter(psiFactory.createIdentifier(name), getObjectKeyword())
|
val result = addAfter(psiFactory.createIdentifier(name), getObjectKeyword()!!)
|
||||||
addAfter(psiFactory.createWhiteSpace(), getObjectKeyword())
|
addAfter(psiFactory.createWhiteSpace(), getObjectKeyword()!!)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ class KtObjectDeclaration : KtClassOrObject {
|
|||||||
fun isCompanion(): Boolean = _stub?.isCompanion() ?: hasModifier(KtTokens.COMPANION_KEYWORD)
|
fun isCompanion(): Boolean = _stub?.isCompanion() ?: hasModifier(KtTokens.COMPANION_KEYWORD)
|
||||||
|
|
||||||
override fun getTextOffset(): Int = nameIdentifier?.textRange?.startOffset
|
override fun getTextOffset(): Int = nameIdentifier?.textRange?.startOffset
|
||||||
?: getObjectKeyword().textRange.startOffset
|
?: getObjectKeyword()!!.textRange.startOffset
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
|
||||||
return visitor.visitObjectDeclaration(this, data)
|
return visitor.visitObjectDeclaration(this, data)
|
||||||
@@ -66,5 +66,5 @@ class KtObjectDeclaration : KtClassOrObject {
|
|||||||
|
|
||||||
fun isObjectLiteral(): Boolean = _stub?.isObjectLiteral() ?: (parent is KtObjectLiteralExpression)
|
fun isObjectLiteral(): Boolean = _stub?.isObjectLiteral() ?: (parent is KtObjectLiteralExpression)
|
||||||
|
|
||||||
fun getObjectKeyword(): PsiElement = findChildByType(KtTokens.OBJECT_KEYWORD)!!
|
fun getObjectKeyword(): PsiElement? = findChildByType(KtTokens.OBJECT_KEYWORD)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
|||||||
if (declaration is KtClassOrObject && classOrObjectHasTextUsages(declaration)) return
|
if (declaration is KtClassOrObject && classOrObjectHasTextUsages(declaration)) return
|
||||||
|
|
||||||
val (inspectionTarget, textRange) = if (isCompanionObject && declaration.nameIdentifier == null) {
|
val (inspectionTarget, textRange) = if (isCompanionObject && declaration.nameIdentifier == null) {
|
||||||
val objectKeyword = (declaration as KtObjectDeclaration).getObjectKeyword()
|
val objectKeyword = (declaration as KtObjectDeclaration).getObjectKeyword()!!
|
||||||
Pair(declaration, TextRange(0, objectKeyword.startOffsetInParent + objectKeyword.textLength))
|
Pair(declaration, TextRange(0, objectKeyword.startOffsetInParent + objectKeyword.textLength))
|
||||||
} else {
|
} else {
|
||||||
Pair(declaration.nameIdentifier!!, null)
|
Pair(declaration.nameIdentifier!!, null)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ open class ChangeVisibilityModifierIntention protected constructor(
|
|||||||
is KtNamedFunction -> declaration.funKeyword?.textRange
|
is KtNamedFunction -> declaration.funKeyword?.textRange
|
||||||
is KtProperty -> declaration.valOrVarKeyword.textRange
|
is KtProperty -> declaration.valOrVarKeyword.textRange
|
||||||
is KtClass -> declaration.getClassOrInterfaceKeyword()?.textRange
|
is KtClass -> declaration.getClassOrInterfaceKeyword()?.textRange
|
||||||
is KtObjectDeclaration -> declaration.getObjectKeyword().textRange
|
is KtObjectDeclaration -> declaration.getObjectKeyword()?.textRange
|
||||||
is KtPrimaryConstructor -> declaration.valueParameterList?.let { TextRange.from(it.startOffset, 0) } //TODO: use constructor keyword if exist
|
is KtPrimaryConstructor -> declaration.valueParameterList?.let { TextRange.from(it.startOffset, 0) } //TODO: use constructor keyword if exist
|
||||||
is KtSecondaryConstructor -> declaration.getConstructorKeyword().textRange
|
is KtSecondaryConstructor -> declaration.getConstructorKeyword().textRange
|
||||||
is KtParameter -> declaration.valOrVarKeyword?.textRange
|
is KtParameter -> declaration.valOrVarKeyword?.textRange
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiter
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextRange(element.objectDeclaration.getObjectKeyword().startOffset, baseTypeRef.endOffset)
|
return TextRange(element.objectDeclaration.getObjectKeyword()!!.startOffset, baseTypeRef.endOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: KtObjectLiteralExpression, editor: Editor?) {
|
override fun applyTo(element: KtObjectLiteralExpression, editor: Editor?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user