Skip to content

JBRes-7073: Add transformation for renaming methods#35

Merged
dragoi75 merged 12 commits intomainfrom
adragoi/feature/method-rename
Feb 8, 2026
Merged

JBRes-7073: Add transformation for renaming methods#35
dragoi75 merged 12 commits intomainfrom
adragoi/feature/method-rename

Conversation

@dragoi75
Copy link
Collaborator

@dragoi75 dragoi75 commented Jan 3, 2026

Changes

  1. Moved Grazie and Koog dependencies from core to be main build.gradle.kts. See commit.
    → This was necessary to be able to send an LLM request from the java module.
  2. Had to change how we close the project, see commit
    → Because Koog must be called with runBlocking, which requires coroutines, I had to add the dependency back, see here. But then I was once again getting a LinkageError. I think the issue is that IntelliJ 2025.1 and lower comes with an older version of coroutines. I tried changing to 2025.2 or newer, but that breaks the indexing in headless mode. And in the older version the limitedParallelism method does not exist, leading to an error.
  3. Added the RenameMethodTransformation class:
    a. Finds all methods that meet the criteria (not a getter/setter/constructor, if it is part of an interface that implements from a library file, if the method overrides a different method, etc).
    b. Calls an LLM to find a substitute name (which is then checked for uniqueness).
    c. Renames all usages and references of the original method.

@github-actions
Copy link

github-actions bot commented Jan 3, 2026

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/[email protected]
        with:
          upload-result: true
Contact Qodana team

Contact us at [email protected]

@dragoi75 dragoi75 marked this pull request as ready for review January 3, 2026 11:16
Copy link
Collaborator

@Vladislav0Art Vladislav0Art left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, good! 🎉

Left some comments. Highly suggest integrating them.

Comment on lines +120 to +122
private fun haveSameSignature(m1: PsiMethod, m2: PsiMethod): Boolean {
return m1.manager.areElementsEquivalent(m1.parameterList, m2.parameterList)
}
Copy link
Collaborator

@Vladislav0Art Vladislav0Art Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question; making sure] Is the order of parameters preserved? i.e., haveSameSignature(f1, f2) == false, with the f1 and f2 defined below.

fun f1(a: Int, b: String) {}

fun f2(b: String, a: Int) {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. The method's javadoc says: "Checks if the specified two PSI elements represent the same source element". From what I undestand, this means for f1 and f2 it would return false.

Comment on lines 52 to 64
val suggestedName = getNewMethodName(method)

// Validation check
if (isNameAvailable(method, suggestedName)) {
method to suggestedName
} else {
// Fallback: try adding a suffix or skip
val fallbackName = "${suggestedName}Internal"
if (isNameAvailable(method, fallbackName)) {
method to fallbackName
} else {
null // Skip this method to avoid compilation errors
}
Copy link
Collaborator

@Vladislav0Art Vladislav0Art Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[important] The implementation is nicely done! 👍🏻 and we can improve on this piece of code.


Proposal

You generate a single suggested name. What if you do, let's say, 10? or N?

I suggest making getNewMethodName generate a list of suggested names (parameterized by N), sorted by the most fitting first. Then, here, you'll iterate over each and try to apply.

In the prompt used in getNewMethodName, ask AI generate a list of N sorted name suggestions separated by a newline.

In general, it's better to implement all such suggestion-generating functions this way, instead of requesting a single suggestion over a single call.


Notes

  1. You can add "${suggestedName}Internal" at the end of the generated list, so that you don't need an else-block.
  2. null // Skip this method to avoid compilation errors - do not silently ignore the failure; log it instead. There is a HeadlessLogger just for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Addressed in db03396.

Comment on lines 231 to 236
method.annotations.isEmpty() &&
!method.isConstructor &&
method.name != "toString" &&
!method.name.startsWith("get") &&
!method.name.startsWith("set") &&
!method.name.startsWith("is")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should other Java default methods be mentioned here as well?

  1. equals
  2. hashCode
  3. clone
  4. wait / notify / notifyAll / finalize

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point! I though they should have @Override, which would filter them out before, but indeed it is not mandatory, so I added them in the filter.

@dragoi75 dragoi75 merged commit ec60ff0 into main Feb 8, 2026
6 checks passed
@dragoi75 dragoi75 deleted the adragoi/feature/method-rename branch February 8, 2026 16:10
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.

2 participants