From 22999fe67dd27a1b03e2fc6c3c33e4d3cd9a00d9 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 24 Oct 2016 15:51:33 +0300 Subject: [PATCH] Set hasValueArguments in KotlinAnnotationEntryStub to 'true' only if some arguments exist Currently '()' is used for resolving ambiguity in parsing when annotating function types. This way a decompiled code will need brackets, but compile code will have annotation without parameters. This commit will allow to make both stub-trees consistent. Tested in ClsStubBuilderTestGenerated.testAnnotationsOnNullableTypes() --- .../jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt | 2 +- .../stubs/elements/KtAnnotationEntryElementType.java | 4 +++- .../stubBuilder/Annotations/Annotations.kt | 1 + .../stubBuilder/Annotations/Annotations.txt | 12 ++++++++++++ .../AnnotationsOnNullableTypes.txt | 5 +++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index 799db9ca2d6ee..ba05950535220 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -23,7 +23,7 @@ object KotlinStubVersions { // Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version // if you are not 100% sure it can be avoided. // Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version. - const val SOURCE_STUB_VERSION = 118 + const val SOURCE_STUB_VERSION = 119 // Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed // or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder). diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtAnnotationEntryElementType.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtAnnotationEntryElementType.java index dc17dd24546fc..ce05f8264a3e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtAnnotationEntryElementType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtAnnotationEntryElementType.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.psi.KtAnnotationEntry; import org.jetbrains.kotlin.psi.KtPsiUtil; +import org.jetbrains.kotlin.psi.KtValueArgumentList; import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub; import org.jetbrains.kotlin.psi.stubs.impl.KotlinAnnotationEntryStubImpl; import org.jetbrains.kotlin.name.Name; @@ -41,7 +42,8 @@ public KtAnnotationEntryElementType(@NotNull @NonNls String debugName) { public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) { Name shortName = KtPsiUtil.getShortName(psi); String resultName = shortName != null ? shortName.asString() : psi.getText(); - boolean hasValueArguments = psi.getValueArgumentList() != null; + KtValueArgumentList valueArgumentList = psi.getValueArgumentList(); + boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty(); return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments); } diff --git a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt index a764c5b9f76cf..60c60ebefd38e 100644 --- a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt +++ b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt @@ -1,4 +1,5 @@ @a public class Annotations private @a constructor(private @property:a @param:a val c1: Int, @property:a @param:a val c2: Int) { + @a() val hasValueArguments = 42 protected @a fun f() { } diff --git a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt index c35dc983f9f77..2d3ffb934f73d 100644 --- a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt +++ b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt @@ -88,6 +88,18 @@ PsiJetFileStubImpl[package=] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=Int] + PROPERTY[fqName=Annotations.hasValueArguments, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=hasValueArguments] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=a] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=a] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] PROPERTY[fqName=Annotations.withCustomAccessors, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=true, name=withCustomAccessors] MODIFIER_LIST[public final] TYPE_REFERENCE diff --git a/idea/testData/decompiler/stubBuilder/AnnotationsOnNullableTypes/AnnotationsOnNullableTypes.txt b/idea/testData/decompiler/stubBuilder/AnnotationsOnNullableTypes/AnnotationsOnNullableTypes.txt index 3982a3341350b..5f2eaa69c9c91 100644 --- a/idea/testData/decompiler/stubBuilder/AnnotationsOnNullableTypes/AnnotationsOnNullableTypes.txt +++ b/idea/testData/decompiler/stubBuilder/AnnotationsOnNullableTypes/AnnotationsOnNullableTypes.txt @@ -54,6 +54,11 @@ PsiJetFileStubImpl[package=] PROPERTY[fqName=AnnotationsOnNullableTypes.lambdaType, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=lambdaType] MODIFIER_LIST[public final] TYPE_REFERENCE + ANNOTATION_ENTRY[hasValueArguments=false, shortName=A] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] NULLABLE_TYPE FUNCTION_TYPE VALUE_PARAMETER_LIST