Bug 530208 - [quick fix] Split composite try-with-resources into two nested ones
Summary: [quick fix] Split composite try-with-resources into two nested ones
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7.2   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2018-01-23 15:29 EST by Lukas Eder CLA
Modified: 2024-02-21 10:19 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Eder CLA 2018-01-23 15:29:36 EST
When working with JDBC, I often have this situation:

------------------------------------------
try (Connection c = getConnection();
    Statement s = c.createStatement()) {
    // ...
}
------------------------------------------

Now, sometimes, I want to reuse the connection for several statements. Ideally, I'd love to have a quick fix that is active on the semi-colon (or on any whitespace between the two statements) allowing to split the single try-with-resources statement into two nested ones:

------------------------------------------
try (Connection c = getConnection()) {
    try (Statement s = c.createStatement()) {
        // ...
    }
}
------------------------------------------

This should work with any number of statements in the resources block. E.g. this:

------------------------------------------
try (X x1 = getX();
    X x2 = getX(); // Quick fix here
    X x3 = getX();
    X x4 = getX()) {
    // ...
}
------------------------------------------

would result in:

------------------------------------------
try (X x1 = getX();
    X x2 = getX()) {
    try (X x3 = getX();
        X x4 = getX()) {
        // ...
    }
}
------------------------------------------

And of course, the individual new try-with-resources statements could be further split if desired.

The inverse would be really cool, too, but I imagine it is a bit more tricky to define the rules when it is applicable.
Comment 1 Eclipse Genie CLA 2020-02-25 13:56:55 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Stephan Herrmann CLA 2020-02-25 14:25:53 EST
I think this makes sense, though nobody currently has plans to work on this.
Comment 3 Eclipse Genie CLA 2022-02-15 17:36:26 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2024-02-06 13:22:46 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Jeff Johnston CLA 2024-02-21 10:19:09 EST
Have created: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1220