-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
Class{Literal,Reference}Cast
Refaster rules (#1269)
- Loading branch information
1 parent
366cdda
commit 3d9aab7
Showing
3 changed files
with
73 additions
and
12 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
18 changes: 13 additions & 5 deletions
18
...-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestInput.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 |
---|---|---|
@@ -1,26 +1,34 @@ | ||
package tech.picnic.errorprone.refasterrules; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import java.io.IOException; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; | ||
|
||
final class ClassRulesTest implements RefasterRuleCollectionTestCase { | ||
boolean testClassIsInstance() throws IOException { | ||
boolean testClassIsInstance() { | ||
return CharSequence.class.isAssignableFrom("foo".getClass()); | ||
} | ||
|
||
ImmutableSet<Boolean> testInstanceof() throws IOException { | ||
ImmutableSet<Boolean> testInstanceof() { | ||
Class<?> clazz = CharSequence.class; | ||
return ImmutableSet.of(CharSequence.class.isInstance("foo"), clazz.isInstance("bar")); | ||
} | ||
|
||
Predicate<String> testClassLiteralIsInstancePredicate() throws IOException { | ||
Predicate<String> testClassLiteralIsInstancePredicate() { | ||
return s -> s instanceof CharSequence; | ||
} | ||
|
||
Predicate<String> testClassReferenceIsInstancePredicate() throws IOException { | ||
Predicate<String> testClassReferenceIsInstancePredicate() { | ||
Class<?> clazz = CharSequence.class; | ||
return s -> clazz.isInstance(s); | ||
} | ||
|
||
Function<Number, Integer> testClassLiteralCast() { | ||
return i -> (Integer) i; | ||
} | ||
|
||
Function<Number, Integer> testClassReferenceCast() { | ||
return i -> Integer.class.cast(i); | ||
} | ||
} |
18 changes: 13 additions & 5 deletions
18
...contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestOutput.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 |
---|---|---|
@@ -1,26 +1,34 @@ | ||
package tech.picnic.errorprone.refasterrules; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import java.io.IOException; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; | ||
|
||
final class ClassRulesTest implements RefasterRuleCollectionTestCase { | ||
boolean testClassIsInstance() throws IOException { | ||
boolean testClassIsInstance() { | ||
return CharSequence.class.isInstance("foo"); | ||
} | ||
|
||
ImmutableSet<Boolean> testInstanceof() throws IOException { | ||
ImmutableSet<Boolean> testInstanceof() { | ||
Class<?> clazz = CharSequence.class; | ||
return ImmutableSet.of("foo" instanceof CharSequence, clazz.isInstance("bar")); | ||
} | ||
|
||
Predicate<String> testClassLiteralIsInstancePredicate() throws IOException { | ||
Predicate<String> testClassLiteralIsInstancePredicate() { | ||
return CharSequence.class::isInstance; | ||
} | ||
|
||
Predicate<String> testClassReferenceIsInstancePredicate() throws IOException { | ||
Predicate<String> testClassReferenceIsInstancePredicate() { | ||
Class<?> clazz = CharSequence.class; | ||
return clazz::isInstance; | ||
} | ||
|
||
Function<Number, Integer> testClassLiteralCast() { | ||
return Integer.class::cast; | ||
} | ||
|
||
Function<Number, Integer> testClassReferenceCast() { | ||
return Integer.class::cast; | ||
} | ||
} |