Skip to main content Link Search Menu Expand Document (external link)

MissingRefasterAnnotation

WARNING

LikelyError

View source code on GitHub

Summary

The Refaster rule contains a method without any Refaster annotations

Suppression

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

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

Samples

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.AfterTemplate;
import com.google.errorprone.refaster.annotation.AlsoNegation;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import java.util.Map;

class A {
  // BUG: Diagnostic matches: X
  static final class MethodLacksBeforeTemplateAnnotation {
    @BeforeTemplate
    boolean before1(String string) {
      return string.equals("");
    }

    // @BeforeTemplate is missing
    boolean before2(String string) {
      return string.length() == 0;
    }

    @AfterTemplate
    @AlsoNegation
    boolean after(String string) {
      return string.isEmpty();
    }
  }

  // BUG: Diagnostic matches: X
  static final class MethodLacksAfterTemplateAnnotation {
    @BeforeTemplate
    boolean before(String string) {
      return string.equals("");
    }

    // @AfterTemplate is missing
    boolean after(String string) {
      return string.isEmpty();
    }
  }

  // BUG: Diagnostic matches: X
  abstract class MethodLacksPlaceholderAnnotation<K, V> {
    // @Placeholder is missing
    abstract V function(K key);

    @BeforeTemplate
    void before(Map<K, V> map, K key) {
      if (!map.containsKey(key)) {
        map.put(key, function(key));
      }
    }

    @AfterTemplate
    void after(Map<K, V> map, K key) {
      map.computeIfAbsent(key, k -> function(k));
    }
  }

  static final class ValidRefasterRule {
    @BeforeTemplate
    void unusedPureFunctionCall(Object o) {
      o.toString();
    }
  }

  static final class NotARefasterRule {
    @Override
    public String toString() {
      return "This is not a Refaster rule";
    }
  }
}

Copyright © 2017-2023 Picnic Technologies BV