[FIR] Reuse calculated values and clean up code
This commit is contained in:
+5
-4
@@ -32,10 +32,11 @@ object FirImportsChecker : FirFileChecker() {
|
|||||||
override fun check(declaration: FirFile, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirFile, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
declaration.imports.forEach { import ->
|
declaration.imports.forEach { import ->
|
||||||
if (import is FirErrorImport) return@forEach
|
if (import is FirErrorImport) return@forEach
|
||||||
if (import.isAllUnder && import !is FirResolvedImport) {
|
if (import.isAllUnder) {
|
||||||
checkAllUnderFromEnumEntry(import, context, reporter)
|
if (import !is FirResolvedImport) {
|
||||||
}
|
checkAllUnderFromEnumEntry(import, context, reporter)
|
||||||
if (!import.isAllUnder) {
|
}
|
||||||
|
} else {
|
||||||
checkCanBeImported(import, context, reporter)
|
checkCanBeImported(import, context, reporter)
|
||||||
if (import is FirResolvedImport) {
|
if (import is FirResolvedImport) {
|
||||||
checkOperatorRename(import, context, reporter)
|
checkOperatorRename(import, context, reporter)
|
||||||
|
|||||||
+3
-2
@@ -109,8 +109,9 @@ object FirUninitializedEnumChecker : FirQualifiedAccessExpressionChecker() {
|
|||||||
it.getContainingClassSymbol(context.session) == enumClassSymbol
|
it.getContainingClassSymbol(context.session) == enumClassSymbol
|
||||||
}?.symbol ?: return
|
}?.symbol ?: return
|
||||||
|
|
||||||
val enumMemberProperties = enumClassSymbol.declarationSymbols.filterIsInstance<FirPropertySymbol>()
|
val declarationSymbols = enumClassSymbol.declarationSymbols
|
||||||
val enumEntries = enumClassSymbol.declarationSymbols.filterIsInstance<FirEnumEntrySymbol>()
|
val enumMemberProperties = declarationSymbols.filterIsInstance<FirPropertySymbol>()
|
||||||
|
val enumEntries = declarationSymbols.filterIsInstance<FirEnumEntrySymbol>()
|
||||||
|
|
||||||
// When checking enum member properties, accesses to enum entries in lazy delegation is legitimate, e.g.,
|
// When checking enum member properties, accesses to enum entries in lazy delegation is legitimate, e.g.,
|
||||||
// enum JvmTarget(...) {
|
// enum JvmTarget(...) {
|
||||||
|
|||||||
+3
-2
@@ -22,8 +22,9 @@ object ArrayEqualityCanBeReplacedWithEquals : FirBasicExpressionChecker() {
|
|||||||
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
if (expression !is FirEqualityOperatorCall) return
|
if (expression !is FirEqualityOperatorCall) return
|
||||||
if (expression.operation != FirOperation.EQ && expression.operation != FirOperation.NOT_EQ) return
|
if (expression.operation != FirOperation.EQ && expression.operation != FirOperation.NOT_EQ) return
|
||||||
val left = expression.arguments.getOrNull(0) ?: return
|
val arguments = expression.arguments
|
||||||
val right = expression.arguments.getOrNull(1) ?: return
|
val left = arguments.getOrNull(0) ?: return
|
||||||
|
val right = arguments.getOrNull(1) ?: return
|
||||||
|
|
||||||
if (left.typeRef.coneType.classId != StandardClassIds.Array) return
|
if (left.typeRef.coneType.classId != StandardClassIds.Array) return
|
||||||
if (right.typeRef.coneType.classId != StandardClassIds.Array) return
|
if (right.typeRef.coneType.classId != StandardClassIds.Array) return
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ object CanBeReplacedWithOperatorAssignmentChecker : FirVariableAssignmentChecker
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun lightTreeMatcher(
|
private fun lightTreeMatcher(
|
||||||
variable: LighterASTNode,
|
variable: LighterASTNode,
|
||||||
expression: LighterASTNode,
|
expression: LighterASTNode,
|
||||||
source: KtLightSourceElement,
|
source: KtLightSourceElement,
|
||||||
|
|||||||
+6
-4
@@ -176,7 +176,8 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
|||||||
// Assuming no errors, the children of FirResolvedTypeRef (currently this can be FirAnnotationCalls) will also be present
|
// Assuming no errors, the children of FirResolvedTypeRef (currently this can be FirAnnotationCalls) will also be present
|
||||||
// as children in delegatedTypeRef. We should make sure those elements are only visited once, otherwise diagnostics will be
|
// as children in delegatedTypeRef. We should make sure those elements are only visited once, otherwise diagnostics will be
|
||||||
// collected twice: once through resolvedTypeRef's children and another through resolvedTypeRef.delegatedTypeRef's children.
|
// collected twice: once through resolvedTypeRef's children and another through resolvedTypeRef.delegatedTypeRef's children.
|
||||||
if (resolvedTypeRef.type is ConeClassErrorType) {
|
val resolvedTypeRefType = resolvedTypeRef.type
|
||||||
|
if (resolvedTypeRefType is ConeClassErrorType) {
|
||||||
super.visitResolvedTypeRef(resolvedTypeRef, data)
|
super.visitResolvedTypeRef(resolvedTypeRef, data)
|
||||||
}
|
}
|
||||||
if (resolvedTypeRef.source?.kind is KtFakeSourceElementKind) return
|
if (resolvedTypeRef.source?.kind is KtFakeSourceElementKind) return
|
||||||
@@ -184,7 +185,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
|||||||
//the note about is just wrong
|
//the note about is just wrong
|
||||||
//if we don't visit resolved type we can't make any diagnostics on them
|
//if we don't visit resolved type we can't make any diagnostics on them
|
||||||
//so here we check resolvedTypeRef
|
//so here we check resolvedTypeRef
|
||||||
if (resolvedTypeRef.type !is ConeClassErrorType) {
|
if (resolvedTypeRefType !is ConeClassErrorType) {
|
||||||
withAnnotationContainer(resolvedTypeRef) {
|
withAnnotationContainer(resolvedTypeRef) {
|
||||||
checkElement(resolvedTypeRef)
|
checkElement(resolvedTypeRef)
|
||||||
}
|
}
|
||||||
@@ -319,13 +320,14 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
|||||||
inline fun <R> withAnnotationContainer(annotationContainer: FirAnnotationContainer, block: () -> R): R {
|
inline fun <R> withAnnotationContainer(annotationContainer: FirAnnotationContainer, block: () -> R): R {
|
||||||
val existingContext = context
|
val existingContext = context
|
||||||
addSuppressedDiagnosticsToContext(annotationContainer)
|
addSuppressedDiagnosticsToContext(annotationContainer)
|
||||||
if (annotationContainer.annotations.isNotEmpty()) {
|
val notEmptyAnnotations = annotationContainer.annotations.isNotEmpty()
|
||||||
|
if (notEmptyAnnotations) {
|
||||||
context = context.addAnnotationContainer(annotationContainer)
|
context = context.addAnnotationContainer(annotationContainer)
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
block()
|
block()
|
||||||
} finally {
|
} finally {
|
||||||
if (annotationContainer.annotations.isNotEmpty()) {
|
if (notEmptyAnnotations) {
|
||||||
existingContext.dropAnnotationContainer()
|
existingContext.dropAnnotationContainer()
|
||||||
}
|
}
|
||||||
context = existingContext
|
context = existingContext
|
||||||
|
|||||||
+1
-1
@@ -120,7 +120,7 @@ abstract class AbstractFirDeserializedSymbolProvider(
|
|||||||
return getPackageParts(classId.packageFqName).firstNotNullOfOrNull { part ->
|
return getPackageParts(classId.packageFqName).firstNotNullOfOrNull { part ->
|
||||||
val ids = part.typeAliasNameIndex[classId.shortClassName]
|
val ids = part.typeAliasNameIndex[classId.shortClassName]
|
||||||
if (ids == null || ids.isEmpty()) return@firstNotNullOfOrNull null
|
if (ids == null || ids.isEmpty()) return@firstNotNullOfOrNull null
|
||||||
val aliasProto = ids.map { part.proto.getTypeAlias(it) }.single()
|
val aliasProto = part.proto.getTypeAlias(ids.single())
|
||||||
part.context.memberDeserializer.loadTypeAlias(aliasProto).symbol
|
part.context.memberDeserializer.loadTypeAlias(aliasProto).symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -76,8 +76,9 @@ class FirSignatureEnhancement(
|
|||||||
): FirFunctionSymbol<*> {
|
): FirFunctionSymbol<*> {
|
||||||
return enhancements.getOrPut(function) {
|
return enhancements.getOrPut(function) {
|
||||||
enhance(function, name).also { enhancedVersion ->
|
enhance(function, name).also { enhancedVersion ->
|
||||||
(enhancedVersion.fir.initialSignatureAttr as? FirSimpleFunction)?.let {
|
val enhancedVersionFir = enhancedVersion.fir
|
||||||
enhancedVersion.fir.initialSignatureAttr = enhancedFunction(it.symbol, it.name).fir
|
(enhancedVersionFir.initialSignatureAttr as? FirSimpleFunction)?.let {
|
||||||
|
enhancedVersionFir.initialSignatureAttr = enhancedFunction(it.symbol, it.name).fir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} as FirFunctionSymbol<*>
|
} as FirFunctionSymbol<*>
|
||||||
|
|||||||
+3
-6
@@ -52,7 +52,7 @@ class JavaClassUseSiteMemberScope(
|
|||||||
private val typeParameterStack = klass.javaTypeParameterStack
|
private val typeParameterStack = klass.javaTypeParameterStack
|
||||||
private val specialFunctions = hashMapOf<Name, Collection<FirNamedFunctionSymbol>>()
|
private val specialFunctions = hashMapOf<Name, Collection<FirNamedFunctionSymbol>>()
|
||||||
private val syntheticPropertyByNameMap = hashMapOf<Name, FirSyntheticPropertySymbol>()
|
private val syntheticPropertyByNameMap = hashMapOf<Name, FirSyntheticPropertySymbol>()
|
||||||
|
|
||||||
private val canUseSpecialGetters: Boolean by lazy { !klass.hasKotlinSuper(session) }
|
private val canUseSpecialGetters: Boolean by lazy { !klass.hasKotlinSuper(session) }
|
||||||
|
|
||||||
private val callableNamesCached by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
private val callableNamesCached by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
@@ -161,11 +161,8 @@ class JavaClassUseSiteMemberScope(
|
|||||||
scope: FirScope,
|
scope: FirScope,
|
||||||
): FirNamedFunctionSymbol? {
|
): FirNamedFunctionSymbol? {
|
||||||
val specialGetterName = if (canUseSpecialGetters) getBuiltinSpecialPropertyGetterName() else null
|
val specialGetterName = if (canUseSpecialGetters) getBuiltinSpecialPropertyGetterName() else null
|
||||||
if (specialGetterName != null) {
|
val name = specialGetterName?.asString() ?: JvmAbi.getterName(fir.name.asString())
|
||||||
return findGetterByName(specialGetterName.asString(), scope)
|
return findGetterByName(name, scope)
|
||||||
}
|
|
||||||
|
|
||||||
return findGetterByName(JvmAbi.getterName(fir.name.asString()), scope)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirPropertySymbol.findGetterByName(
|
private fun FirPropertySymbol.findGetterByName(
|
||||||
|
|||||||
Reference in New Issue
Block a user