rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Static import is removed and leaves ambiguous reference behind

Open Laurens-W opened this issue 1 year ago • 3 comments

What's changed?

RemoveUnusedImports recipe should not remove static import when this leaves an ambiguous reference behind

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

@timtebeek

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • [x] I've added unit tests to cover both positive and negative cases
  • [x] I've read and applied the recipe conventions and best practices
  • [x] I've used the IntelliJ IDEA auto-formatter on affected files

Laurens-W avatar Aug 27 '24 12:08 Laurens-W

Capturing the failure here:

expected:

  package org.test;	
  	
  import static org.a.ABC.*;	
  import static org.b.DEF.*;	
  import static org.a.ABC.ALL;	
  	
  public class Test {	
    private String abc = ALL;	
    private String a = A;	
    private String b = B;	
    private String c = C;	
    private String d = D;	
    private String e = E;	
    private String f = F;	
  }

but was:

  package org.test;	
  	
  import static org.a.ABC.*;	
  import static org.b.DEF.*;	
  	
  public class Test {	
    private String abc = ALL;	
    private String a = A;	
    private String b = B;	
    private String c = C;	
    private String d = D;	
    private String e = E;	
    private String f = F;	
  }

timtebeek avatar Aug 27 '24 13:08 timtebeek

This indeed seems to match the case reported, thanks! Lets look at what we can do to fix the issue.

timtebeek avatar Aug 27 '24 13:08 timtebeek

Perhaps good to briefly evaluate if we can fold in a fix for this issue as well

  • https://github.com/openrewrite/rewrite/issues/4452

timtebeek avatar Aug 27 '24 22:08 timtebeek