From 73e7b99e0505162b6f0ee40f61cc745b05989bdc Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Thu, 7 Apr 2022 14:56:23 +0300 Subject: [PATCH] [FIR] LightTree builder: get rid of unwanted asText calls --- .../fir/lightTree/converter/BaseConverter.kt | 10 ++------ .../converter/DeclarationsConverter.kt | 23 ++++++++----------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt index 79bff61eb93..13382885efa 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt @@ -156,7 +156,7 @@ abstract class BaseConverter( when (node.tokenType) { type -> container += node } - } ?: listOf() + } ?: emptyList() } fun LighterASTNode?.getChildrenAsArray(): Array { @@ -168,13 +168,7 @@ abstract class BaseConverter( } fun LighterASTNode?.getFirstChild(): LighterASTNode? { - val firstChild: LighterASTNode? - try { - firstChild = getChildrenAsArray()[0] - } catch (e: ArrayIndexOutOfBoundsException) { - return null - } - return firstChild + return getChildrenAsArray().firstOrNull() } @OptIn(ExperimentalContracts::class) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index 05ee8c35793..4b1edf4ce4b 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -1001,7 +1001,7 @@ class DeclarationsConverter( } } - val isImplicit = constructorDelegationCall.asText.isEmpty() + val isImplicit = constructorDelegationCall.textLength == 0 val isThis = thisKeywordPresent //|| (isImplicit && classWrapper.hasPrimaryConstructor) val delegatedType = when { @@ -1785,7 +1785,7 @@ class DeclarationsConverter( val firValueArguments = mutableListOf() constructorInvocation.forEachChildren { when (it.tokenType) { - CONSTRUCTOR_CALLEE -> if (it.asText.isNotEmpty()) firTypeRef = convertType(it) //is empty in enum entry constructor + CONSTRUCTOR_CALLEE -> firTypeRef = convertType(it) VALUE_ARGUMENT_LIST -> firValueArguments += expressionConverter.convertValueArguments(it) } } @@ -1930,12 +1930,6 @@ class DeclarationsConverter( */ fun convertType(type: LighterASTNode): FirTypeRef { val typeRefSource = type.toFirSourceElement() - if (type.asText.isEmpty()) { - return buildErrorTypeRef { - source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Unwrapped type is null", DiagnosticKind.Syntax) - } - } // There can be MODIFIER_LIST children on the TYPE_REFERENCE node AND the descendant NULLABLE_TYPE nodes. // We aggregate them to get modifiers and annotations. Not only that, there could be multiple modifier lists on each. Examples: @@ -2230,12 +2224,13 @@ class DeclarationsConverter( isNoinline = modifiers.hasNoinline() isVararg = modifiers.hasVararg() val isFromPrimaryConstructor = valueParameterDeclaration == ValueParameterDeclaration.PRIMARY_CONSTRUCTOR - annotations += modifiers.annotations.filter { - !isFromPrimaryConstructor || it.useSiteTarget == null || - it.useSiteTarget == CONSTRUCTOR_PARAMETER || - it.useSiteTarget == RECEIVER || - it.useSiteTarget == FILE - } + annotations += if (!isFromPrimaryConstructor) + modifiers.annotations + else + modifiers.annotations.filter { + val useSiteTarget = it.useSiteTarget + useSiteTarget == null || useSiteTarget == CONSTRUCTOR_PARAMETER || useSiteTarget == RECEIVER || useSiteTarget == FILE + } annotations += additionalAnnotations } return ValueParameter(isVal, isVar, modifiers, firValueParameter, destructuringDeclaration)