Change semantics of getObjectKeyword() function

This commit is contained in:
Yan Zhulanow
2016-03-31 19:55:54 +03:00
parent 41979de71e
commit 726bfca540
5 changed files with 11 additions and 11 deletions
@@ -51,7 +51,7 @@ object PositioningStrategies {
when (element) {
is KtObjectLiteralExpression -> {
val objectDeclaration = element.objectDeclaration
val objectKeyword = objectDeclaration.getObjectKeyword()
val objectKeyword = objectDeclaration.getObjectKeyword()!!
val delegationSpecifierList = objectDeclaration.getSuperTypeList()
if (delegationSpecifierList == null) {
return markElement(objectKeyword)
@@ -60,8 +60,8 @@ object PositioningStrategies {
}
is KtObjectDeclaration -> {
return markRange(
element.getObjectKeyword(),
element.getNameIdentifier() ?: element.getObjectKeyword()
element.getObjectKeyword()!!,
element.getNameIdentifier() ?: element.getObjectKeyword()!!
)
}
is KtConstructorDelegationCall -> {
@@ -265,7 +265,7 @@ object PositioningStrategies {
}
val elementToMark = when (element) {
is KtObjectDeclaration -> element.getObjectKeyword()
is KtObjectDeclaration -> element.getObjectKeyword()!!
is KtPropertyAccessor -> element.getNamePlaceholder()
is KtAnonymousInitializer -> element
else -> throw IllegalArgumentException(
@@ -45,8 +45,8 @@ class KtObjectDeclaration : KtClassOrObject {
override fun setName(@NonNls name: String): PsiElement {
if (nameIdentifier == null) {
val psiFactory = KtPsiFactory(project)
val result = addAfter(psiFactory.createIdentifier(name), getObjectKeyword())
addAfter(psiFactory.createWhiteSpace(), getObjectKeyword())
val result = addAfter(psiFactory.createIdentifier(name), getObjectKeyword()!!)
addAfter(psiFactory.createWhiteSpace(), getObjectKeyword()!!)
return result
}
@@ -58,7 +58,7 @@ class KtObjectDeclaration : KtClassOrObject {
fun isCompanion(): Boolean = _stub?.isCompanion() ?: hasModifier(KtTokens.COMPANION_KEYWORD)
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 {
return visitor.visitObjectDeclaration(this, data)
@@ -66,5 +66,5 @@ class KtObjectDeclaration : KtClassOrObject {
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
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))
} else {
Pair(declaration.nameIdentifier!!, null)
@@ -103,7 +103,7 @@ open class ChangeVisibilityModifierIntention protected constructor(
is KtNamedFunction -> declaration.funKeyword?.textRange
is KtProperty -> declaration.valOrVarKeyword.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 KtSecondaryConstructor -> declaration.getConstructorKeyword().textRange
is KtParameter -> declaration.valOrVarKeyword?.textRange
@@ -79,7 +79,7 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiter
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?) {