-
Notifications
You must be signed in to change notification settings - Fork 473
Remove fully qualified JavaDoc references from TypesInUse for RemoveUnusedImports
#5738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
82b9270
d59a974
a13540e
8d68bb3
f5c2f75
a305054
6b62f86
cdbaf0b
48ea627
05c0e29
8062449
afb97af
3bb2b97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import org.openrewrite.java.tree.J; | ||
| import org.openrewrite.java.tree.JavaSourceFile; | ||
| import org.openrewrite.java.tree.JavaType; | ||
| import org.openrewrite.java.tree.Javadoc; | ||
|
|
||
| import java.util.IdentityHashMap; | ||
| import java.util.Objects; | ||
|
|
@@ -100,12 +101,20 @@ public J.Lambda.Parameters visitLambdaParameters(J.Lambda.Parameters parameters, | |
| } else { | ||
| usedMethods.add((JavaType.Method) javaType); | ||
| } | ||
| } else if (!(cursor.getValue() instanceof J.ClassDeclaration) && !(cursor.getValue() instanceof J.Lambda)) { | ||
| // ignore type representing class declaration itself and inferred lambda types | ||
| } else if (!(cursor.getValue() instanceof J.ClassDeclaration) && | ||
| !(cursor.getValue() instanceof J.Lambda) && | ||
| !isFullyQualifiedJavaDocReference(cursor)) { | ||
| types.add(javaType); | ||
| } | ||
| } | ||
| return javaType; | ||
| } | ||
|
|
||
| private boolean isFullyQualifiedJavaDocReference(Cursor cursor) { | ||
| // Fully qualified Javadoc references are _using_ those types as much as they are just references; | ||
| // TypesInUse also determines what imports are retained, and for fully qualified these can be dropped | ||
| return cursor.getValue() instanceof J.FieldAccess && | ||
| cursor.getPathAsStream().anyMatch(o -> o instanceof Javadoc.Reference); | ||
|
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.