palantir / palantir/palantir-java-format
Add formatter step to shorten unnecessary fully qualified class names
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
Motivation
With LLM generated Java code becoming common, I am seeing one pattern a lot: generated code often uses fully qualified class names instead of normal imports.
The code compiles fine, but it becomes unnecessarily noisy.
For example:
package com.example.service;
public class UserService {
private final java.util.Map<String, java.util.List<String>> cache = new java.util.HashMap<>();
public java.util.List<String> getUsers(java.util.function.Predicate<String> filter) throws java.io.IOException {
java.util.List<String> result = new java.util.ArrayList<>();
return java.util.Collections.unmodifiableList(result);
}
}
Running the formatter on this today leaves it unchanged.
Proposed behavior
Add a formatter step that shortens safe fully qualified names and adds the required imports:
package com.example.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
public class UserService {
private final Map<String, List<String>> cache = new HashMap<>();
public List<String> getUsers(Predicate<String> filter) throws IOException {
List<String> result = new ArrayList<>();
return Collections.unmodifiableList(result);
}
}
This can run before RemoveUnusedImports and ImportOrderer, so the existing formatter steps can clean up and order imports after this step.
Why this belongs in the formatter
This is a mechanical cleanup and the formatter already handles import cleanup. This fills the other side of that flow: unnecessary fully qualified names can become normal imports.
This is showing up more often with AI generated code, and formatter runs in CI / pre-commit hooks where IDE cleanup actions are not always available.
I am ready to create a PR if the feature is acceptable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the formatter pipeline and the existing RemoveUnusedImports and ImportOrderer steps to determine where this behavior would fit. Define how safe fully qualified names become imports, including the example in the issue, and verify that existing import cleanup and ordering still produce the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100