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

Code action to surround with try-with-resources #2128

Closed
dwb5013 opened this issue Sep 24, 2021 · 4 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#1911
Closed

Code action to surround with try-with-resources #2128

dwb5013 opened this issue Sep 24, 2021 · 4 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#1911

Comments

@dwb5013
Copy link

dwb5013 commented Sep 24, 2021

try with resources feature looks like absent in vscode.

Environment
  • Operating System: Windows 10 Pro 19043.1237
  • JDK version: OpenJDK 11
  • Visual Studio Code version: 1.60.2
  • Java extension version: Extension Pack for Java v0.18.5
Steps To Reproduce
  1. [step 1]
    image

  2. [step 2]
    image

Current Result

image

Expected Result

image

Additional Informations
@rgrunber
Copy link
Member

I think this is possible. SurroundWithTryWithResourcesAction is of course a UI class (relies on Action which is tied to SWT), but it's just using SurroundWithTryWithResourcesRefactoring. Doing a few quick changes, most things should resolve correctly :

  • Move AbstractExceptionAnalyzer, ExceptionAnalyzer, SurroundWithTryWithResourcesAnalyzer, SurroundWithTryWithResourcesRefactoring from jdt.ui to jdt.core.manipulation.
  • Use LinkedProposalModelCore instead of LinkedProposalModel in SurroundWithTryWithResourcesRefactoring and make sure clients can continue to work with the core version
  • There's some calls to QuickAssistProcessor static methods but they all deal with ASTNode so I suspect these are utility methods that don't need to be in UI
  • SurroundWithTryWithResourcesRefactoring does have a single constructor meant to take an ITextSelection. We can't move that so we'll need to split the class into a core and create a smaller class that just extends it and has the unsupportable constructor

@rgrunber rgrunber self-assigned this Sep 24, 2021
@rgrunber
Copy link
Member

rgrunber commented Oct 6, 2021

Jeff has proposed some refactoring of the necessary classes in https://bugs.eclipse.org/bugs/show_bug.cgi?id=576431 which is expected to make 2021-12 M2 (end of Oct.) . I will have a look to see how we can integrate this.

@rgrunber
Copy link
Member

I have a draft that is working, but I'm seeing a bunch of odd behaviour in some other cases, so I may have to file some new bugs. Also there's some copied code that can be avoided by migrating some things.

surround-with-try-with

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

Successfully merging a pull request may close this issue.

3 participants