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()
This commit is contained in:
Nikolay Krasko
2016-10-24 15:51:33 +03:00
parent a344ad0644
commit 22999fe67d
5 changed files with 22 additions and 2 deletions
@@ -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).
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NonNls;
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 class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
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);
}
@@ -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() {
}
@@ -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
@@ -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