[FIR] Fix redundant modality modifier checker
Fixed function FirDeclaration.hasBody() and some others improvement
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a988234bbf
commit
a8ff5d17dc
+24
-10
@@ -1,3 +1,27 @@
|
||||
// Interface
|
||||
interface Interface {
|
||||
// Redundant
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>open<!> val gav: Int
|
||||
get() = 42
|
||||
// Redundant
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>abstract<!> fun foo()
|
||||
// Redundant
|
||||
private <!REDUNDANT_MODALITY_MODIFIER!>final<!> fun bar() {}
|
||||
}
|
||||
interface B {
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>abstract<!> var bar: Unit
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>abstract<!> fun foo()
|
||||
}
|
||||
|
||||
expect abstract class AbstractClass : Foo {
|
||||
abstract override fun foo()
|
||||
|
||||
abstract fun bar()
|
||||
|
||||
abstract val baz: Int
|
||||
}
|
||||
|
||||
|
||||
// Abstract
|
||||
abstract class Base {
|
||||
// Redundant final
|
||||
@@ -23,16 +47,6 @@ open class OpenDerived : Base() {
|
||||
}
|
||||
// Redundant final
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>final<!> class Final
|
||||
// Interface
|
||||
interface Interface {
|
||||
// Redundant
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>abstract<!> fun foo()
|
||||
// Redundant
|
||||
private <!REDUNDANT_MODALITY_MODIFIER!>final<!> fun bar() {}
|
||||
// Redundant
|
||||
<!REDUNDANT_MODALITY_MODIFIER!>open<!> val gav: Int
|
||||
get() = 42
|
||||
}
|
||||
// Derived interface
|
||||
interface Derived : Interface {
|
||||
// Redundant
|
||||
|
||||
+33
-12
@@ -1,4 +1,37 @@
|
||||
FILE: RedundantModalityModifierChecker.kt
|
||||
public abstract interface Interface : R|kotlin/Any| {
|
||||
public open val gav: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int| {
|
||||
^ Int(42)
|
||||
}
|
||||
|
||||
public abstract fun foo(): R|kotlin/Unit|
|
||||
|
||||
private final fun bar(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface B : R|kotlin/Any| {
|
||||
public abstract var bar: R|kotlin/Unit|
|
||||
public get(): R|kotlin/Unit|
|
||||
public set(value: R|kotlin/Unit|): R|kotlin/Unit|
|
||||
|
||||
public abstract fun foo(): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
public abstract expect class AbstractClass : R|ERROR CLASS: Symbol not found, for `Foo`| {
|
||||
public expect constructor(): R|AbstractClass| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public abstract expect override fun foo(): R|kotlin/Unit|
|
||||
|
||||
public abstract expect fun bar(): R|kotlin/Unit|
|
||||
|
||||
public abstract expect val baz: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
}
|
||||
public abstract class Base : R|kotlin/Any| {
|
||||
public constructor(): R|Base| {
|
||||
super<R|kotlin/Any|>()
|
||||
@@ -42,18 +75,6 @@ FILE: RedundantModalityModifierChecker.kt
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface Interface : R|kotlin/Any| {
|
||||
public abstract fun foo(): R|kotlin/Unit|
|
||||
|
||||
private final fun bar(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
public open val gav: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int| {
|
||||
^ Int(42)
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface Derived : R|Interface| {
|
||||
public open override fun foo(): R|kotlin/Unit| {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.FirSymbolOwner
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyExpressionBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
||||
@@ -268,7 +269,7 @@ fun FirMemberDeclaration.implicitModality(context: CheckerContext): KtModifierKe
|
||||
private fun FirDeclaration.modifierListOrNull() = (this.source.getModifierList() as? FirPsiModifierList)?.modifierList
|
||||
|
||||
private fun FirDeclaration.hasBody(): Boolean = when (this) {
|
||||
is FirSimpleFunction -> this.body != null && this.body !is FirSingleExpressionBlock
|
||||
is FirProperty -> this.setter != null || this.getter != null
|
||||
is FirSimpleFunction -> this.body != null && this.body !is FirEmptyExpressionBlock
|
||||
is FirProperty -> this.setter?.body !is FirEmptyExpressionBlock? || this.getter?.body !is FirEmptyExpressionBlock?
|
||||
else -> false
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.extended.RedundantModalityModifierChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.extended.RedundantVisibilityModifierChecker
|
||||
|
||||
object ExtendedDeclarationCheckers : DeclarationCheckers() {
|
||||
override val declarationCheckers = listOf(RedundantVisibilityModifierChecker, RedundantVisibilityModifierChecker)
|
||||
|
||||
override val memberDeclarationCheckers = listOf(RedundantModalityModifierChecker)
|
||||
|
||||
}
|
||||
+1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.psi
|
||||
import org.jetbrains.kotlin.fir.toFirPsiSourceElement
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.modalityModifier
|
||||
|
||||
|
||||
Reference in New Issue
Block a user