Create isCallee utility function
This commit is contained in:
@@ -357,6 +357,33 @@ fun KtStringTemplateExpression.getContentRange(): TextRange {
|
||||
return TextRange(start, if (lastChild.elementType == KtTokens.CLOSING_QUOTE) length - lastChild.textLength else length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check expression might be a callee of call with the same name.
|
||||
* Note that 'this' in 'this(args)' isn't considered to be a callee, also 'name' is not a callee in 'name++'.
|
||||
*/
|
||||
fun KtSimpleNameExpression.isCallee(): Boolean {
|
||||
val parent = parent
|
||||
return when (parent) {
|
||||
is KtCallElement -> parent.calleeExpression == this
|
||||
is KtBinaryExpression -> parent.operationReference == this
|
||||
else -> {
|
||||
val callElement =
|
||||
getStrictParentOfType<KtUserType>()
|
||||
?.getStrictParentOfType<KtTypeReference>()
|
||||
?.getStrictParentOfType<KtConstructorCalleeExpression>()
|
||||
?.getStrictParentOfType<KtCallElement>()
|
||||
|
||||
if (callElement != null) {
|
||||
val ktConstructorCalleeExpression = callElement.calleeExpression as? KtConstructorCalleeExpression
|
||||
(ktConstructorCalleeExpression?.typeReference?.typeElement as? KtUserType)?.referenceExpression == this
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val KtStringTemplateExpression.plainContent: String
|
||||
get() = getContentRange().substring(text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user