From a9c3b27d3efecda70b9a59ef87eda4e67e4f90b0 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 18 Oct 2018 13:32:18 +0300 Subject: [PATCH] Don't generate stub for value arguments list when no arguments present (KT-23738) Need this to conform stubs list obtained by decompiler. Also ignore green stub, because is might not contain actual psi node. --- .../kotlin/psi/KtAnnotationEntry.java | 10 +- .../kotlin/psi/stubs/KotlinStubVersions.kt | 2 +- .../KtValueArgumentListElementType.java | 3 + .../AnnotationValues/AnnotationValues.kt | 109 ++++++++++++++++++ .../AnnotationValues/AnnotationValues.txt | 103 +++++++++++++++++ .../ClsStubBuilderTestGenerated.java | 5 + 6 files changed, 229 insertions(+), 3 deletions(-) create mode 100644 idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.kt create mode 100644 idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.txt diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtAnnotationEntry.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtAnnotationEntry.java index 9ba7306f130..8f80e5e3d27 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtAnnotationEntry.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtAnnotationEntry.java @@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.KtNodeTypes; import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub; @@ -60,8 +61,8 @@ public class KtAnnotationEntry extends KtElementImplStub getValueArguments() { + KotlinAnnotationEntryStub stub = getStub(); + if (stub != null && !stub.hasValueArguments()) { + return Collections.emptyList(); + } + KtValueArgumentList list = getValueArgumentList(); return list != null ? list.getArguments() : Collections.emptyList(); } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index 0064033bcb3..6e203c23ec5 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/psi/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 = 133 + const val SOURCE_STUB_VERSION = 134 // 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/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtValueArgumentListElementType.java b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtValueArgumentListElementType.java index 6f37e74235d..282d47a0691 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtValueArgumentListElementType.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtValueArgumentListElementType.java @@ -22,6 +22,9 @@ public class KtValueArgumentListElementType extends KtPlaceHolderStubElementType return false; } + KtValueArgumentList psi = node.getPsi(KtValueArgumentList.class); + if (psi.getArguments().isEmpty()) return false; + return super.shouldCreateStub(node); } } diff --git a/idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.kt b/idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.kt new file mode 100644 index 00000000000..91075a60deb --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.kt @@ -0,0 +1,109 @@ +package test + +import test.E.E1 +import kotlin.reflect.KClass + +const val CONSTANT = 12 + +class AnnotationValues { + @Simple( + 12, + 12L, + 12, + + 3.3, + f = 3.3F, + + c = 'a', + + b1 = true, + b2 = false + ) + class WithSimple + + @StringLiteral("some", "", "H$CONSTANT") + class WithStringLiteral + + @EnumLiteral(E1, E.E2, e3 = test.E.E2) + class WithEnumLiteral + + @VarArg(1, 2, 3) + class WithVarArg + + @Arrays( + [1, 2, 3], + [1L], + [], + [2.2], + ['a'], + [true, false] + ) + class WithArrays + + @ClassLiteral( + WithClassLiteral::class, + String::class + ) + class WithClassLiteral + + @Outer("value", nested = Nested(12, "nested value")) + class WithNested +} + +annotation class Simple( + val i: Int, + val l: Long, + val b: Byte, + + val d: Double, + val f: Float, + + val c: Char, + + val b1: Boolean, + val b2: Boolean +) + +annotation class StringLiteral( + val s1: String, + val s2: String, + val s3: String +) + +enum class E { + E1, E2 +} +annotation class EnumLiteral( + val e1: E, + val e2: E, + val e3: E +) + +annotation class VarArg( + vararg val v: Int +) + +annotation class Arrays( + val ia: IntArray, + val la: LongArray, + val fa: FloatArray, + val da: DoubleArray, + val ca: CharArray, + val ba: BooleanArray +) + +annotation class ClassLiteral( + val c1: KClass<*>, + val c2: KClass<*> +) + + +annotation class Nested( + val i: Int, + val s: String +) + +annotation class Outer( + val some: String, + val nested: Nested +) diff --git a/idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.txt b/idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.txt new file mode 100644 index 00000000000..86103271709 --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/AnnotationValues/AnnotationValues.txt @@ -0,0 +1,103 @@ +PsiJetFileStubImpl[package=test] + PACKAGE_DIRECTIVE + REFERENCE_EXPRESSION[referencedName=test] + IMPORT_LIST + CLASS[fqName=test.AnnotationValues, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=AnnotationValues, superNames=[]] + MODIFIER_LIST[public final] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithArrays, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithArrays, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=Arrays] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=Arrays] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithClassLiteral, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithClassLiteral, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=ClassLiteral] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=ClassLiteral] + TYPE_PARAMETER_LIST + TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=T] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithEnumLiteral, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithEnumLiteral, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=EnumLiteral] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=EnumLiteral] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithNested, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithNested, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=Outer] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=Outer] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithSimple, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithSimple, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=Simple] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=Simple] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithStringLiteral, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithStringLiteral, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=StringLiteral] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=StringLiteral] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + CLASS[fqName=test.AnnotationValues.WithVarArg, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=WithVarArg, superNames=[]] + MODIFIER_LIST[public final] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=VarArg] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=VarArg] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java index 015b6145c78..3b2e01e560c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java @@ -39,6 +39,11 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest { runTest("idea/testData/decompiler/stubBuilder/AnnotationClass/"); } + @TestMetadata("AnnotationValues") + public void testAnnotationValues() throws Exception { + runTest("idea/testData/decompiler/stubBuilder/AnnotationValues/"); + } + @TestMetadata("Annotations") public void testAnnotations() throws Exception { runTest("idea/testData/decompiler/stubBuilder/Annotations/");