Bug 484015

Summary: [quick assist][quick fix] Allow for auto-declaring a resource assignment
Product: [Eclipse Project] JDT Reporter: Lukas Eder <lukas.eder>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: kenneth
Version: 4.5.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

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?