redhat-developer / redhat-developer/vscode-java

Organize Imports should be smarter about single-letter types

Open
#1,438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code action
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

When there's an unresolved single-letter type usage in the code, doing Organize Imports should not blindly import a type it finds

Environment
  • Operating System: Windows 10
  • JDK version: 14
  • Visual Studio Code version: 1.45.0
  • Java extension version: 0.61.0
Steps To Reproduce
  1. do Organize Imports on the code below, while there's a single type T available for import (in my case it was inside Apache POI, but you could just create a trivial T.java file
import java.util.Map;

//import org.apache.poi.ss.formula.functions.T;

public class Bar {

    public void print(Comparable<T> bar, Map<Integer, T> whatever) {

    }

}
Current Result

the type T is imported

Expected Result

the actual issue here is that I forgot to specify the type variable T. Ideally, the extension would give a single error saying exactly that. If that's not feasible, it should at least ask confirmation before importing single-letter types, even if there's only a single one available: the chances that the user actually wants to import such a type are much smaller than the chance that there's an error w.r.t. type variables

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Organize Imports entry point and reproduce the behavior with the Java snippet in this issue, using a single-letter type such as T available for import. The work is done when the extension avoids blindly importing the single-letter type and instead reports the missing type-variable problem or asks for confirmation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.