Skip to content

JBRes-7660: Add transformation for renaming variables.#37

Draft
dragoi75 wants to merge 11 commits intomainfrom
adragoi/feature/variable-rename
Draft

JBRes-7660: Add transformation for renaming variables.#37
dragoi75 wants to merge 11 commits intomainfrom
adragoi/feature/variable-rename

Conversation

@dragoi75
Copy link
Collaborator

Note: Since this is branched out of #35, some commits are repeated. The changes related to the current PR are in this commit.

Changes

Add a transformation for renaming class fields, method parameters, and local variables.

@github-actions
Copy link

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/qodana-action@v2025.1.1
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

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.

briefly went through the code

Comment on lines +45 to +57
val suggestedName = getNewClassName(psiClass)

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

Choose a reason for hiding this comment

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

The same suggestion from the comment

Copy link
Collaborator

Choose a reason for hiding this comment

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

also logging instead of printing

}

val newNames = eligibleVariables.mapIndexedNotNull { index, psiVar ->
print("\r ⏲ LLM renaming request ${index + 1}/${eligibleVariables.size} in progress...")
Copy link
Collaborator

Choose a reason for hiding this comment

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

logging

Comment on lines +42 to +54
val suggestedName = getNewVariableName(psiVar)

// Validation check
if (isNameAvailable(psiVar, suggestedName)) {
psiVar to suggestedName
} else {
// Fallback: try adding a generic suffix
val fallbackName = "${suggestedName}Val"
if (isNameAvailable(psiVar, fallbackName)) {
psiVar to fallbackName
} else {
null // Skip to avoid errors
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

here also

Comment on lines +58 to +59
println()

Copy link
Collaborator

Choose a reason for hiding this comment

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

accidental?

Comment on lines +81 to +82
@Serializable
data class VariableName(val name: String)
Copy link
Collaborator

Choose a reason for hiding this comment

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

private

Comment on lines +90 to +95
val assignedType = if (psiVariable is PsiLocalVariable) {
psiVariable.initializer?.let { init ->
if (init is PsiNewExpression) init.classOrAnonymousClassReference?.referenceName
else null
}
} else null
Copy link
Collaborator

Choose a reason for hiding this comment

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

hot about one of these refactorings?

Comment on lines +127 to +130
+"Current Variable Name: ${psiVariable.name}"
+"Declared Type: $typeName"
+"Structural Context: $context"

Copy link
Collaborator

Choose a reason for hiding this comment

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

are all of these lines added with a newline separator? or will the prompt be rendered as a single line with no newlines?

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