-
Notifications
You must be signed in to change notification settings - Fork 515
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
Changes from all commits
82b9270
d59a974
a13540e
8d68bb3
f5c2f75
a305054
6b62f86
cdbaf0b
48ea627
05c0e29
8062449
afb97af
3bb2b97
ed7c6df
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,8 +24,10 @@ | |
| 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.Iterator; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -100,12 +102,31 @@ 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 entries determines what imports are retained, and for fully qualified these can be dropped | ||
| if (cursor.getValue() instanceof J.FieldAccess) { | ||
| Iterator<Object> path = cursor.getPath(); | ||
| while (path.hasNext()) { | ||
|
Comment on lines
+118
to
+119
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capturing a note from Slack: some performance concerns here due to the use of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed again; consensus was it looks ok now with the early return for blocks. |
||
| Object o = path.next(); | ||
| if (o instanceof Javadoc.Reference) { | ||
| return true; | ||
| } | ||
| if (o instanceof J.Block) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.