ClassRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!ClassRules\$).* as compiler argument.

Table of contents
  1. ClassIsInstance
  2. Instanceof
  3. ClassLiteralIsInstancePredicate
  4. ClassReferenceIsInstancePredicate

ClassIsInstance

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ClassIsInstance") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ClassRules\$ClassIsInstance).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 boolean testClassIsInstance() throws IOException {
-    return CharSequence.class.isAssignableFrom("foo".getClass());
+    return CharSequence.class.isInstance("foo");
   }

Instanceof

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("Instanceof") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ClassRules\$Instanceof).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Boolean> testInstanceof() throws IOException {
     Class<?> clazz = CharSequence.class;
-    return ImmutableSet.of(CharSequence.class.isInstance("foo"), clazz.isInstance("bar"));
+    return ImmutableSet.of("foo" instanceof CharSequence, clazz.isInstance("bar"));
   }

ClassLiteralIsInstancePredicate

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ClassLiteralIsInstancePredicate") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ClassRules\$ClassLiteralIsInstancePredicate).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Predicate<String> testClassLiteralIsInstancePredicate() throws IOException {
-    return s -> s instanceof CharSequence;
+    return CharSequence.class::isInstance;
   }

ClassReferenceIsInstancePredicate

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ClassReferenceIsInstancePredicate") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ClassRules\$ClassReferenceIsInstancePredicate).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Predicate<String> testClassReferenceIsInstancePredicate() throws IOException {
     Class<?> clazz = CharSequence.class;
-    return s -> clazz.isInstance(s);
+    return clazz::isInstance;
   }

Copyright © 2017-2024 Picnic Technologies BV