Bug 484015 - [quick assist][quick fix] Allow for auto-declaring a resource assignment
Summary: [quick assist][quick fix] Allow for auto-declaring a resource assignment
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-09 08:55 EST by Lukas Eder CLA
Modified: 2021-02-13 14:47 EST (History)
1 user (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 2015-12-09 08:55:08 EST
When working with "ordinary" local variables, quick fix / quick assist helps declaring those variables without explicitly needing to type the target type. For example:

--------------------------------------------------------
import java.sql.Connection;

public class Test {
    public static void main(String[] args) {
        Connection c = (Connection) new Object();

        s = c.prepareStatement("statement");
    }
}
--------------------------------------------------------

I can turn s into:

- a local variable
- a field
- a parameter

Choosing the local variable is most sensible here, producing

--------------------------------------------------------
import java.sql.Connection;
import java.sql.PreparedStatement;

public class Test {
    public static void main(String[] args) {
        Connection c = (Connection) new Object();

        PreparedStatement s = c.prepareStatement("statement");
    }
}
--------------------------------------------------------

However, I cannot do the same thing when I start typing the try-with-resources statement:

--------------------------------------------------------
import java.sql.Connection;

public class Test {
    public static void main(String[] args) {
        Connection c = (Connection) new Object();

        try (s = c.prepareStatement("statement")) {
            
        }
    }
}
--------------------------------------------------------

There's a whole list of suggested fixes that are all useless. From the user perspective, it's "obvious" that the only thing missing is the type "PreparedStatement".
Comment 1 Kenneth Styrberg CLA 2021-02-13 14:47:52 EST
Still a problem, tested with git-master from 2021-02-13.

The error reported is "ParsingErrorInsertTokenAfter" which seems odd, "UnresolvedVariable" seems like a better error instead?