Skip to content

Conversation

@vsantele
Copy link
Contributor

@vsantele vsantele commented Jul 29, 2025

Description of changes made

Implemented equals and hashCode methods in JavaPsiClassWrapper and KotlinPsiClassWrapper to ensure proper comparison and hashing based on the qualified name.

Why is merge request needed

When the PromptManager gets interestingPsiClasses (here) using psiHelper.getInterestingPsiClassesWithQualifiedNames, PsiMethodWrapper.getInterestingPsiClassesWithQualifiedNames is called.
The JavaPsiMethodWrapper and KotlinPsiMethodWrapper create a new instance of the corresponding PsiClassWrapper for each interesting PSI class.

If the same class is added to the MutableSet, two items will be present because they will be two distinct instances of the PsiClassWrapper.

Other notes

Fixes #501
I can't think of any particular case where two distinct classes can have the same qualified name.

Potential improvements

Based on data of a TGA-Pipeline run with the current version of TestSpark, duplicate class signatures has been removed from the prompt, resulting in a potentially significant improvement in performance.

image

What is missing?

Please mention if anything is missing for this merge request, e.g you have decided to move something to the next merge request

  • I have checked that I am merging into correct branch

Implemented `equals` and `hashCode` methods in `JavaPsiClassWrapper` and `KotlinPsiClassWrapper` to ensure proper comparison and hashing based on the qualified name.
@github-actions
Copy link

🚨 PR Title Needs Formatting

Please specify the modified module and, preferrably, include a GitHub or YouTrack issue that this PR closes in the title. By module, we mean any logical part of the project — it doesn’t have to be a Gradle module or anything like that.
Use the following format: [<Module(s)>] and(or) [<ISSUE-ID>] brief title. Examples:

  • [LLM] Add support for Google AI as an LLM
  • [Build] Update IntelliJ Platform version
  • [#290] Fix bug with LLM response parsing`
  • [PromptBuilder] [JBRes-2860] Refactor the PromptBuilder component

@vsantele vsantele changed the title Add equals and hashCode implementations to PSI class wrappers [LLM] Add equals and hashCode implementations to PSI class wrappers Jul 29, 2025
@vsantele vsantele changed the title [LLM] Add equals and hashCode implementations to PSI class wrappers [501] Add equals and hashCode implementations to PSI class wrappers Jul 31, 2025
@vsantele vsantele changed the title [501] Add equals and hashCode implementations to PSI class wrappers [#501] Add equals and hashCode implementations to PSI class wrappers Jul 31, 2025
@vsantele vsantele requested a review from arksap2002 August 25, 2025 15:25
@vsantele vsantele requested a review from Copilot October 4, 2025 08:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements proper equals and hashCode methods in PSI class wrappers to fix duplicate entries in sets when collecting interesting classes for prompt generation. The fix ensures that classes are compared and hashed based on their qualified names rather than object identity.

  • Added equals and hashCode implementations to both Java and Kotlin PSI class wrappers
  • Both implementations use qualifiedName as the basis for equality and hashing
  • Includes validation that qualifiedName is not empty to ensure meaningful comparisons

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
KotlinPsiClassWrapper.kt Added equals and hashCode methods using qualified name comparison
JavaPsiClassWrapper.kt Added equals and hashCode methods using qualified name comparison

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

vsantele and others added 2 commits October 4, 2025 10:32
…aPsiClassWrapper.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…/KotlinPsiClassWrapper.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

Duplication of interesting classes in context sent to the LLM

1 participant