Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kotlin][idea] Fixed cross-language ChangeAnnotationAction for java annotations used in kotlin code. #2852

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rollczi
Copy link
Contributor

@Rollczi Rollczi commented Sep 30, 2024

This PR fixes the problem with JvmElementActionsFactory#createChangeAnnotationAttributeActions.
When executing invoke, if we modify, for example, a class in Kotlin that uses java annotations, then the attributes are not assigned correctly. I found this bug while migrating to K2.

Java Annotations work differently than Kotlin Annotations in Kotlin code. Because varargs for an array do not exist in Kotlin annotations. After all, kotlin supports java syntax if annotation is from a Java source file.

How to reproduce a bug

IDE Opened project

Permission.java

public @interface Permission {
    String[] value();
}

SomeCode.kt

@Permission("before1", "before2", "before3")

IDE Plugin

JvmElementActionsFactory factory = // ...;
List<IntentionAction> actions = factory.createChangeAnnotationAttributeActions(
    permissionAnnotation,
    -1,
    new AnnotationAttributeRequest(
        "value",
        new ArrayValue(
            List.of(
                new StringValue("after1"),
                new StringValue("after2"),
                new StringValue("after3")
            )
        )
    ),
    "Change value",
    "Change value"
);

for (IntentionAction intentionAction : actions) {
    intentionAction.invoke(project, new ImaginaryEditor(project, document), annotation.getContainingFile());
}

Before my changes

SomeCode.kt

@Permission("before1", "before2", "before3", "after1")

After my changes

SomeCode.kt

@Permission("after1", "after2", "after3")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant