RefasterRuleModifiers

SUGGESTION

Style

View source code on GitHub

Summary

Refaster class and method definitions should specify a canonical set of modifiers

Suppression

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

Disable this pattern completely by adding -Xep:RefasterRuleModifiers:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

 import com.google.errorprone.refaster.annotation.BeforeTemplate;
 
-class A {
+final class A {
   @BeforeTemplate
-  private static String before(String str) {
+  String before(String str) {
     return str;
   }
 }
 
 import com.google.errorprone.refaster.annotation.BeforeTemplate;
 import com.google.errorprone.refaster.annotation.Placeholder;
 
 final class B {
-  abstract class WithoutPlaceholder {
+  static final class WithoutPlaceholder {
     @BeforeTemplate
-    protected synchronized String before(String str) {
+    String before(String str) {
       return str;
     }
   }
 
-  abstract class WithPlaceholder<I, O> {
+  abstract static class WithPlaceholder<I, O> {
     @Placeholder
-    public abstract O someFunction(I input);
+    abstract O someFunction(I input);
 
     @BeforeTemplate
-    public final String before(I input) {
+    String before(I input) {
       return String.valueOf(someFunction(input));
     }
   }
 }
 

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

import com.google.errorprone.refaster.annotation.BeforeTemplate;

// BUG: Diagnostic contains:
class C {
  @BeforeTemplate
  // BUG: Diagnostic contains:
  final String beforeFinal(String str) {
    return str;
  }

  @BeforeTemplate
  // BUG: Diagnostic contains:
  private String beforePrivate(String str) {
    return str;
  }

  @BeforeTemplate
  // BUG: Diagnostic contains:
  public String beforePublic(String str) {
    return str;
  }

  @BeforeTemplate
  // BUG: Diagnostic contains:
  static String beforeStatic(String str) {
    return str;
  }

  @BeforeTemplate
  // BUG: Diagnostic contains:
  synchronized String beforeSynchronized(String str) {
    return str;
  }

  // BUG: Diagnostic contains:
  abstract static class AbstractInner {
    @BeforeTemplate
    String before(String str) {
      return str;
    }
  }

  // BUG: Diagnostic contains:
  static class NonFinalInner {
    @BeforeTemplate
    String before(String str) {
      return str;
    }
  }

  // BUG: Diagnostic contains:
  final class NonStaticInner {
    @BeforeTemplate
    String before(String str) {
      return str;
    }
  }
}
import com.google.errorprone.refaster.annotation.BeforeTemplate;

// BUG: Diagnostic contains:
abstract class D {
  @BeforeTemplate
  // BUG: Diagnostic contains:
  protected String beforeProtected(String str) {
    return str;
  }
}

Copyright © 2017-2024 Picnic Technologies BV