expandWildcardImports: necessary imports in method call expressions removed
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 52/100
Direzione di ricerca
Inizia in lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java intorno alle righe 181-188 e riproduci l'esempio Java mostrato. Controlla la gestione dell'espansione dei wildcard per gli scope delle chiamate di metodo, quindi verifica che sia JSONObject sia JSON siano ancora importati e che il codice formattato venga compilato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Issue
The new expandWildcardImports step removes necessary imports in method call expressions, e.g.:
import com.alibaba.fastjson.*;
public class Demo {
public static void main() {
final JSONObject jsonObject = new JSONObject();
final Script inlineScript = JSON.toJSONString(jsonObject);
}
}
becomes
import com.alibaba.fastjson.JSONObject;
public class Demo {
public static void main() {
final JSONObject jsonObject = new JSONObject();
final Script inlineScript = JSON.toJSONString(jsonObject);
}
}
The import import com.alibaba.fastjson.JSON is missing and the code fails to compile.
Java version
openjdk 25.0.1 2025-10-21
OpenJDK Runtime Environment (build 25.0.1+8-Ubuntu-125.10)
OpenJDK 64-Bit Server VM (build 25.0.1+8-Ubuntu-125.10, mixed mode, sharing)
Solution
Code like JSON.toJSONString(jsonObject) seems to be a method call expression:
The current code above only checks the method (toJSONString), but not the scope of the method. Adding this resolved the issue for me:
n.getScope().ifPresent(s -> {
ResolvedType type = n.getSymbolResolver().calculateType(n.getScope().get());
if (type != null && type.isReference()) {
matchTypeName(importMap, type.asReferenceType().getQualifiedName(), false);
}
});
- Lingua principale
- Java
- Stelle
- 5.7k
- Fork
- 560
- Merge medio
- 1g 13h
- PR unite (30g)
- 43
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di diffplug/spotless
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Tutte le issue di diffplug/spotless
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100