diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index 6a35e852f10..b7f16c2dd15 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -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( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt index d1eafbd7399..0685ba8de85 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt @@ -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 accept(visitor: KtVisitor, 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) } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt index c0134efae17..1b6551bee45 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt @@ -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) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt index a3f74bc21cd..32643668874 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt @@ -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 diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt index 5d7ddd6d5a8..693df0dfe4c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt @@ -79,7 +79,7 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention