Skip to content

Allowing refactorings for java files not part of any project.#8442

Merged
mbien merged 1 commit intoapache:masterfrom
shivam71:single_file_refactoring_fix
May 22, 2025
Merged

Allowing refactorings for java files not part of any project.#8442
mbien merged 1 commit intoapache:masterfrom
shivam71:single_file_refactoring_fix

Conversation

@shivam71
Copy link
Contributor

Issue
Consider a java file not part of any project . Code Refactorings are not available currently as the file is marked as not refactorable by the isRefactorable method when it checks for the condition of isOnSourceClasspath. The method isOnSourceClasspath marks the file as not refactorable as the file is not part of any project.
Fix Done
If a file is not found to be part of any project then using the SourceLauncher.isSourceLauncherFile function we can check if it is a single source file similar to what is already being done in the isFileInOpenProject method .

@Achal1607 Achal1607 added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension labels Apr 23, 2025
@Achal1607 Achal1607 requested review from dbalek and lahodaj April 23, 2025 08:50
@neilcsmith-net
Copy link
Member

In principle this seems a good idea. I would still like to see the reversal of dependency as discussed with @lahodaj in #7776 (comment) though. That might impact how this is implemented.

Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

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

I am not completely sure SourceLauncher.isSourceLauncherFile does the correct thing anymore (after the many changes in MultiSourceRootProvider), but this change is in a reasonable direction.

Regarding direction of dependencies, this file already uses calls the isSourceLauncher method, only a few lines above the new use, so it seems OK to add a new call, and possibly revise the two calls together.

@mbien mbien added this to the NB27 milestone May 22, 2025
@apache apache locked and limited conversation to collaborators May 22, 2025
@apache apache unlocked this conversation May 22, 2025
@mbien
Copy link
Member

mbien commented May 22, 2025

this is probably fine but we have to refactor more often. Those methods were deprecated even though they aren't public API (could have been replaced right away).

isSourceLauncher has currently also side effects, e.g it builds class paths and puts it into a cache etc.

@mbien mbien merged commit db72992 into apache:master May 22, 2025
66 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants