Minor: rename and refactor contract-related PSI checks in ktPsiUtil
This commit is contained in:
@@ -293,17 +293,20 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(
|
||||
|
||||
// ----------- Contracts -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
fun fastCheckIfContractPresent(element: KtElement): Boolean {
|
||||
if (!isContractAllowedHere(element)) return false
|
||||
val firstExpression = ((element as? KtFunction)?.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: return false
|
||||
return isContractDescriptionCallFastCheck(firstExpression)
|
||||
fun KtElement.isContractPresentPsiCheck(): Boolean {
|
||||
val contractAllowedHere = this is KtNamedFunction &&
|
||||
isTopLevel &&
|
||||
hasBlockBody() &&
|
||||
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
||||
if (!contractAllowedHere) return false
|
||||
|
||||
val firstExpression = ((this as? KtFunction)?.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: return false
|
||||
|
||||
return firstExpression.isContractDescriptionCallPsiCheck()
|
||||
}
|
||||
|
||||
private fun isContractAllowedHere(element: KtElement): Boolean =
|
||||
element is KtNamedFunction && element.isTopLevel && element.hasBlockBody() && !element.hasModifier(KtTokens.OPERATOR_KEYWORD)
|
||||
|
||||
fun isContractDescriptionCallFastCheck(expression: KtExpression): Boolean =
|
||||
expression is KtCallExpression && expression.calleeExpression?.text == "contract"
|
||||
fun KtExpression.isContractDescriptionCallPsiCheck(): Boolean =
|
||||
this is KtCallExpression && calleeExpression?.text == "contract"
|
||||
|
||||
|
||||
// ----------- Other -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user