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.
This commit is contained in:
@@ -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<KotlinAnnotationEntrySt
|
||||
@Override
|
||||
public KtValueArgumentList getValueArgumentList() {
|
||||
KotlinAnnotationEntryStub stub = getStub();
|
||||
if (stub != null && !stub.hasValueArguments()) {
|
||||
return null;
|
||||
if (stub == null && getGreenStub() != null) {
|
||||
return (KtValueArgumentList) findChildByType(KtNodeTypes.VALUE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
return getStubOrPsiChild(KtStubElementTypes.VALUE_ARGUMENT_LIST);
|
||||
@@ -70,6 +71,11 @@ public class KtAnnotationEntry extends KtElementImplStub<KotlinAnnotationEntrySt
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends ValueArgument> getValueArguments() {
|
||||
KotlinAnnotationEntryStub stub = getStub();
|
||||
if (stub != null && !stub.hasValueArguments()) {
|
||||
return Collections.<KtValueArgument>emptyList();
|
||||
}
|
||||
|
||||
KtValueArgumentList list = getValueArgumentList();
|
||||
return list != null ? list.getArguments() : Collections.<KtValueArgument>emptyList();
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
|
||||
+3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T>
|
||||
|
||||
@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
|
||||
)
|
||||
@@ -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
|
||||
Generated
+5
@@ -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/");
|
||||
|
||||
Reference in New Issue
Block a user