Reformat RedundantExplicitTypeInspection
This commit is contained in:
committed by
Mikhail Glukhikh
parent
b9d8466fc0
commit
25952036af
@@ -16,57 +16,55 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
|
|
||||||
class RedundantExplicitTypeInspection : AbstractKotlinInspection() {
|
class RedundantExplicitTypeInspection : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
||||||
propertyVisitor(fun(property) {
|
propertyVisitor(fun(property) {
|
||||||
if (!property.isLocal) return
|
if (!property.isLocal) return
|
||||||
val typeReference = property.typeReference ?: return
|
val typeReference = property.typeReference ?: return
|
||||||
val initializer = property.initializer ?: return
|
val initializer = property.initializer ?: return
|
||||||
|
|
||||||
val type = property.resolveToDescriptorIfAny()?.type ?: return
|
val type = property.resolveToDescriptorIfAny()?.type ?: return
|
||||||
when (initializer) {
|
when (initializer) {
|
||||||
is KtConstantExpression -> {
|
is KtConstantExpression -> {
|
||||||
when (initializer.node.elementType) {
|
when (initializer.node.elementType) {
|
||||||
KtNodeTypes.BOOLEAN_CONSTANT -> {
|
KtNodeTypes.BOOLEAN_CONSTANT -> {
|
||||||
if (!KotlinBuiltIns.isBoolean(type)) return
|
if (!KotlinBuiltIns.isBoolean(type)) return
|
||||||
}
|
|
||||||
KtNodeTypes.INTEGER_CONSTANT -> {
|
|
||||||
if (initializer.text.endsWith("L")) {
|
|
||||||
if (!KotlinBuiltIns.isLong(type)) return
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!KotlinBuiltIns.isInt(type)) return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KtNodeTypes.FLOAT_CONSTANT -> {
|
|
||||||
if (initializer.text.endsWith("f") || initializer.text.endsWith("F")) {
|
|
||||||
if (!KotlinBuiltIns.isFloat(type)) return
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!KotlinBuiltIns.isDouble(type)) return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KtNodeTypes.CHARACTER_CONSTANT -> {
|
|
||||||
if (!KotlinBuiltIns.isChar(type)) return
|
|
||||||
}
|
|
||||||
else -> return
|
|
||||||
}
|
}
|
||||||
|
KtNodeTypes.INTEGER_CONSTANT -> {
|
||||||
|
if (initializer.text.endsWith("L")) {
|
||||||
|
if (!KotlinBuiltIns.isLong(type)) return
|
||||||
|
} else {
|
||||||
|
if (!KotlinBuiltIns.isInt(type)) return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KtNodeTypes.FLOAT_CONSTANT -> {
|
||||||
|
if (initializer.text.endsWith("f") || initializer.text.endsWith("F")) {
|
||||||
|
if (!KotlinBuiltIns.isFloat(type)) return
|
||||||
|
} else {
|
||||||
|
if (!KotlinBuiltIns.isDouble(type)) return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KtNodeTypes.CHARACTER_CONSTANT -> {
|
||||||
|
if (!KotlinBuiltIns.isChar(type)) return
|
||||||
|
}
|
||||||
|
else -> return
|
||||||
}
|
}
|
||||||
is KtStringTemplateExpression -> {
|
|
||||||
if (!KotlinBuiltIns.isString(type)) return
|
|
||||||
}
|
|
||||||
is KtNameReferenceExpression -> {
|
|
||||||
if (typeReference.text != initializer.getReferencedName()) return
|
|
||||||
}
|
|
||||||
is KtCallExpression -> {
|
|
||||||
if (typeReference.text != initializer.calleeExpression?.text) return
|
|
||||||
}
|
|
||||||
else -> return
|
|
||||||
}
|
}
|
||||||
|
is KtStringTemplateExpression -> {
|
||||||
|
if (!KotlinBuiltIns.isString(type)) return
|
||||||
|
}
|
||||||
|
is KtNameReferenceExpression -> {
|
||||||
|
if (typeReference.text != initializer.getReferencedName()) return
|
||||||
|
}
|
||||||
|
is KtCallExpression -> {
|
||||||
|
if (typeReference.text != initializer.calleeExpression?.text) return
|
||||||
|
}
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
|
||||||
holder.registerProblem(
|
holder.registerProblem(
|
||||||
typeReference,
|
typeReference,
|
||||||
"Explicitly given type is redundant here",
|
"Explicitly given type is redundant here",
|
||||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||||
IntentionWrapper(RemoveExplicitTypeIntention(), property.containingKtFile)
|
IntentionWrapper(RemoveExplicitTypeIntention(), property.containingKtFile)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user