Add inspection "main should return Unit" #KT-16085 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8784d89f38
commit
1cd438c3f7
@@ -101,7 +101,11 @@ class MainFunctionDetector {
|
||||
|
||||
companion object {
|
||||
|
||||
fun isMain(descriptor: DeclarationDescriptor, checkJvmStaticAnnotation: Boolean = true): Boolean {
|
||||
fun isMain(
|
||||
descriptor: DeclarationDescriptor,
|
||||
checkJvmStaticAnnotation: Boolean = true,
|
||||
checkReturnType: Boolean = true
|
||||
): Boolean {
|
||||
if (descriptor !is FunctionDescriptor) return false
|
||||
|
||||
if (getJVMFunctionName(descriptor) != "main") {
|
||||
@@ -127,8 +131,7 @@ class MainFunctionDetector {
|
||||
return false
|
||||
}
|
||||
|
||||
val returnType = descriptor.returnType
|
||||
if (returnType == null || !KotlinBuiltIns.isUnit(returnType)) return false
|
||||
if (checkReturnType && !isMainReturnType(descriptor)) return false
|
||||
|
||||
if (DescriptorUtils.isTopLevelDeclaration(descriptor)) return true
|
||||
|
||||
@@ -138,6 +141,11 @@ class MainFunctionDetector {
|
||||
&& (descriptor.hasJvmStaticAnnotation() || !checkJvmStaticAnnotation)
|
||||
}
|
||||
|
||||
fun isMainReturnType(descriptor: FunctionDescriptor): Boolean {
|
||||
val returnType = descriptor.returnType
|
||||
return returnType != null && KotlinBuiltIns.isUnit(returnType)
|
||||
}
|
||||
|
||||
private fun getJVMFunctionName(functionDescriptor: FunctionDescriptor): String {
|
||||
return DescriptorUtils.getJvmName(functionDescriptor) ?: functionDescriptor.name.asString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user