public static void validate(BugPattern pattern) throws ValidationException {
    if (pattern == null) {
      throw new ValidationException("No @BugPattern provided");
    }

    // name must not contain spaces
    if (CharMatcher.whitespace().matchesAnyOf(pattern.name())) {
      throw new ValidationException("Name must not contain whitespace: " + pattern.name());
    }

    // linkType must be consistent with link element.
    switch (pattern.linkType()) {
      case CUSTOM:
        if (pattern.link().isEmpty()) {
          throw new ValidationException("Expected a custom link but none was provided");
        }
        break;
      case AUTOGENERATED:
      case NONE:
        if (!pattern.link().isEmpty()) {
          throw new ValidationException("Expected no custom link but found: " + pattern.link());
        }
        break;
    }
  }
@Test
  public void linkTypeCustomAndIncludesLink() throws Exception {
    @BugPattern(
        name = "LinkTypeCustomAndIncludesLink",
        summary = "linkType custom and includes link",
        explanation = "linkType custom and includes link",
        severity = SeverityLevel.ERROR,
        linkType = LinkType.CUSTOM,
        link = "http://foo")
    final class BugPatternTestClass {}

    BugPattern annotation = BugPatternTestClass.class.getAnnotation(BugPattern.class);
    BugPatternValidator.validate(annotation);
  }