-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid ambiguous imports with
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
These changes prevent Refaster rules from introducing a static import that conflicts with an existing static import. Without these changes the new test case fails with the following error: ``` com/google/errorprone/refaster/testdata/StaticImportClashTemplate.java:27: error: reference to reverseOrder is ambiguous return reverseOrder(); ^ both method <T>reverseOrder() in java.util.Comparator and method <T>reverseOrder() in java.util.Collections match ```
- Loading branch information
1 parent
6ddbaa4
commit d548298
Showing
5 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../java/com/google/errorprone/refaster/testdata/input/StaticImportClashTemplateExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2022 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.errorprone.refaster.testdata; | ||
|
||
import static java.util.Collections.reverseOrder; | ||
|
||
import java.util.Comparator; | ||
|
||
/** Test data for {@code StaticImportClashTemplate}. */ | ||
public class StaticImportClashTemplate { | ||
Comparator<Integer> example() { | ||
return reverseOrder(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...java/com/google/errorprone/refaster/testdata/output/StaticImportClashTemplateExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2022 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.errorprone.refaster.testdata; | ||
|
||
import static java.util.Collections.reverseOrder; | ||
|
||
import java.util.Comparator; | ||
|
||
/** Test data for {@code StaticImportClashTemplate}. */ | ||
public class StaticImportClashTemplate { | ||
Comparator<Integer> example() { | ||
return Comparator.reverseOrder(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...test/java/com/google/errorprone/refaster/testdata/template/StaticImportClashTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2022 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.errorprone.refaster.testdata.template; | ||
|
||
import static java.util.Comparator.reverseOrder; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
|
||
/** Example template that may cause a static import clash. */ | ||
final class StaticImportClashTemplate<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
Comparator<T> before() { | ||
return Collections.reverseOrder(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
Comparator<T> after() { | ||
return reverseOrder(); | ||
} | ||
} |