[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) {
|
||||
declaration.imports.forEach { import ->
|
||||
if (import is FirErrorImport) return@forEach
|
||||
if (import.isAllUnder && import !is FirResolvedImport) {
|
||||
checkAllUnderFromEnumEntry(import, context, reporter)
|
||||
}
|
||||
if (!import.isAllUnder) {
|
||||
if (import.isAllUnder) {
|
||||
if (import !is FirResolvedImport) {
|
||||
checkAllUnderFromEnumEntry(import, context, reporter)
|
||||
}
|
||||
} else {
|
||||
checkCanBeImported(import, context, reporter)
|
||||
if (import is FirResolvedImport) {
|
||||
checkOperatorRename(import, context, reporter)
|
||||
|
||||
+3
-2
@@ -109,8 +109,9 @@ object FirUninitializedEnumChecker : FirQualifiedAccessExpressionChecker() {
|
||||
it.getContainingClassSymbol(context.session) == enumClassSymbol
|
||||
}?.symbol ?: return
|
||||
|
||||
val enumMemberProperties = enumClassSymbol.declarationSymbols.filterIsInstance<FirPropertySymbol>()
|
||||
val enumEntries = enumClassSymbol.declarationSymbols.filterIsInstance<FirEnumEntrySymbol>()
|
||||
val declarationSymbols = enumClassSymbol.declarationSymbols
|
||||
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.,
|
||||
// enum JvmTarget(...) {
|
||||
|
||||
+3
-2
@@ -22,8 +22,9 @@ object ArrayEqualityCanBeReplacedWithEquals : FirBasicExpressionChecker() {
|
||||
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (expression !is FirEqualityOperatorCall) return
|
||||
if (expression.operation != FirOperation.EQ && expression.operation != FirOperation.NOT_EQ) return
|
||||
val left = expression.arguments.getOrNull(0) ?: return
|
||||
val right = expression.arguments.getOrNull(1) ?: return
|
||||
val arguments = expression.arguments
|
||||
val left = arguments.getOrNull(0) ?: return
|
||||
val right = arguments.getOrNull(1) ?: return
|
||||
|
||||
if (left.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,
|
||||
expression: LighterASTNode,
|
||||
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
|
||||
// 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.
|
||||
if (resolvedTypeRef.type is ConeClassErrorType) {
|
||||
val resolvedTypeRefType = resolvedTypeRef.type
|
||||
if (resolvedTypeRefType is ConeClassErrorType) {
|
||||
super.visitResolvedTypeRef(resolvedTypeRef, data)
|
||||
}
|
||||
if (resolvedTypeRef.source?.kind is KtFakeSourceElementKind) return
|
||||
@@ -184,7 +185,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
//the note about is just wrong
|
||||
//if we don't visit resolved type we can't make any diagnostics on them
|
||||
//so here we check resolvedTypeRef
|
||||
if (resolvedTypeRef.type !is ConeClassErrorType) {
|
||||
if (resolvedTypeRefType !is ConeClassErrorType) {
|
||||
withAnnotationContainer(resolvedTypeRef) {
|
||||
checkElement(resolvedTypeRef)
|
||||
}
|
||||
@@ -319,13 +320,14 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
inline fun <R> withAnnotationContainer(annotationContainer: FirAnnotationContainer, block: () -> R): R {
|
||||
val existingContext = context
|
||||
addSuppressedDiagnosticsToContext(annotationContainer)
|
||||
if (annotationContainer.annotations.isNotEmpty()) {
|
||||
val notEmptyAnnotations = annotationContainer.annotations.isNotEmpty()
|
||||
if (notEmptyAnnotations) {
|
||||
context = context.addAnnotationContainer(annotationContainer)
|
||||
}
|
||||
return try {
|
||||
block()
|
||||
} finally {
|
||||
if (annotationContainer.annotations.isNotEmpty()) {
|
||||
if (notEmptyAnnotations) {
|
||||
existingContext.dropAnnotationContainer()
|
||||
}
|
||||
context = existingContext
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ abstract class AbstractFirDeserializedSymbolProvider(
|
||||
return getPackageParts(classId.packageFqName).firstNotNullOfOrNull { part ->
|
||||
val ids = part.typeAliasNameIndex[classId.shortClassName]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -76,8 +76,9 @@ class FirSignatureEnhancement(
|
||||
): FirFunctionSymbol<*> {
|
||||
return enhancements.getOrPut(function) {
|
||||
enhance(function, name).also { enhancedVersion ->
|
||||
(enhancedVersion.fir.initialSignatureAttr as? FirSimpleFunction)?.let {
|
||||
enhancedVersion.fir.initialSignatureAttr = enhancedFunction(it.symbol, it.name).fir
|
||||
val enhancedVersionFir = enhancedVersion.fir
|
||||
(enhancedVersionFir.initialSignatureAttr as? FirSimpleFunction)?.let {
|
||||
enhancedVersionFir.initialSignatureAttr = enhancedFunction(it.symbol, it.name).fir
|
||||
}
|
||||
}
|
||||
} as FirFunctionSymbol<*>
|
||||
|
||||
+3
-6
@@ -52,7 +52,7 @@ class JavaClassUseSiteMemberScope(
|
||||
private val typeParameterStack = klass.javaTypeParameterStack
|
||||
private val specialFunctions = hashMapOf<Name, Collection<FirNamedFunctionSymbol>>()
|
||||
private val syntheticPropertyByNameMap = hashMapOf<Name, FirSyntheticPropertySymbol>()
|
||||
|
||||
|
||||
private val canUseSpecialGetters: Boolean by lazy { !klass.hasKotlinSuper(session) }
|
||||
|
||||
private val callableNamesCached by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
@@ -161,11 +161,8 @@ class JavaClassUseSiteMemberScope(
|
||||
scope: FirScope,
|
||||
): FirNamedFunctionSymbol? {
|
||||
val specialGetterName = if (canUseSpecialGetters) getBuiltinSpecialPropertyGetterName() else null
|
||||
if (specialGetterName != null) {
|
||||
return findGetterByName(specialGetterName.asString(), scope)
|
||||
}
|
||||
|
||||
return findGetterByName(JvmAbi.getterName(fir.name.asString()), scope)
|
||||
val name = specialGetterName?.asString() ?: JvmAbi.getterName(fir.name.asString())
|
||||
return findGetterByName(name, scope)
|
||||
}
|
||||
|
||||
private fun FirPropertySymbol.findGetterByName(
|
||||
|
||||
Reference in New Issue
Block a user