Add KtType.isArrayOrPrimitiveArray/isNestedArray() to AA

This commit is contained in:
Jaebaek Seo
2022-09-23 18:40:48 +00:00
committed by Ilya Kirillov
parent 4436ce22b0
commit f8a101cf3a
3 changed files with 39 additions and 3 deletions
@@ -21,6 +21,8 @@ public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
public abstract fun getFunctionClassKind(type: KtType): FunctionClassKind?
public abstract fun canBeNull(type: KtType): Boolean
public abstract fun isDenotable(type: KtType): Boolean
public abstract fun isArrayOrPrimitiveArray(type: KtType): Boolean
public abstract fun isNestedArray(type: KtType): Boolean
}
public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
@@ -100,6 +102,17 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
}
}
/**
* Returns whether the given [KtType] is an array or a primitive array type or not.
*/
public fun KtType.isArrayOrPrimitiveArray(): Boolean =
withValidityAssertion { analysisSession.typeInfoProvider.isArrayOrPrimitiveArray(this) }
/**
* Returns whether the given [KtType] is an array or a primitive array type and its element is also an array type or not.
*/
public fun KtType.isNestedArray(): Boolean = withValidityAssertion { analysisSession.typeInfoProvider.isNestedArray(this) }
public fun KtType.isClassTypeWithClassId(classId: ClassId): Boolean = withValidityAssertion {
if (this !is KtNonErrorClassType) return false
return this.classId == classId