Skip to content

Commit

Permalink
Set hasValueArguments in KotlinAnnotationEntryStub to 'true' only if …
Browse files Browse the repository at this point in the history
…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()
  • Loading branch information
goodwinnk committed Oct 25, 2016
1 parent a344ad0 commit 22999fe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
Expand Up @@ -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).
Expand Down
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
@@ -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() {
}
Expand Down
12 changes: 12 additions & 0 deletions idea/testData/decompiler/stubBuilder/Annotations/Annotations.txt
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 22999fe

Please sign in to comment.