Remove unused imports recipe is removing an used class #3903
-
Hi, I am running a single recipe (https://docs.openrewrite.org/recipes/java/removeunusedimports) and is removing some imports of a couple of Java classes which they are already in use, hence it is failing when it tries to compile. My question: which criteria is used to know if an import is used? I don't understand the explanation in your official documentation:
For example, one of the imports which is removed is this one: org.springframework.security.web.SecurityFilterChain Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @sergiogp98 ; did you already look at the implementation of the recipe? Roughly speaking we look at the types in use on Lossless Semantic Tree elements in the compilation unit; if such types are missing, then we are at risk of misidentifying a used type as unused. If you have any suggestions for improvement we're more than open to those! |
Beta Was this translation helpful? Give feedback.
Hi @sergiogp98 ; did you already look at the implementation of the recipe?
rewrite/rewrite-java/src/main/java/org/openrewrite/java/RemoveUnusedImports.java
Lines 55 to 57 in c625f30
Roughly speaking we look at the types in use on Lossless Semantic Tree elements in the compilation unit; if such types are missing, then we are at risk of misidentifying a use…