@Nullable private static String createLinkUrl(BugPattern pattern) { switch (pattern.linkType()) { case AUTOGENERATED: return String.format(URL_FORMAT, pattern.name()); case CUSTOM: // annotation.link() must be provided. if (pattern.link().isEmpty()) { throw new IllegalStateException( "If linkType element of @BugPattern is CUSTOM, " + "a link element must also be provided."); } return pattern.link(); case NONE: return null; } throw new AssertionError( "Unexpected value for linkType element of @BugPattern: " + pattern.linkType()); }
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; } } }
private static String createLinkUrl(BugPattern pattern) { switch (pattern.linkType()) { case AUTOGENERATED: return String.format(URL_FORMAT, pattern.name()); case CUSTOM: // annotation.link() must be provided. if (pattern.link().isEmpty()) { throw new IllegalStateException( "If linkType element of @BugPattern is CUSTOM, " + "a link element must also be provided."); } return pattern.link(); case NONE: return null; } throw new AssertionError( "Unexpected value for linkType element of @BugPattern: " + pattern.linkType()); }