Skip to content

Commit

Permalink
Pass null for urlLink to Description.Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Badbond committed Sep 30, 2022
1 parent dfbc784 commit 60c8c3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private Description augmentDescription(
return Description.builder(
description.position,
shortCheckName,
getLinkPattern(delegate, shortCheckName),
getLinkPattern(delegate, shortCheckName).orElse(null),
overrideSeverity(getSeverity(delegate), context),
getDescription(delegate))
.addAllFixes(description.fixes)
Expand All @@ -89,14 +89,16 @@ private String getShortCheckName(String fullCheckName) {
return fullCheckName.substring(prefix.length());
}

private String getLinkPattern(CodeTransformer delegate, String checkName) {
String urlPattern =
getAnnotationValue(OnlineDocumentation.class, OnlineDocumentation::value, delegate, "");

private Optional<String> getLinkPattern(CodeTransformer delegate, String checkName) {
Iterator<String> nameComponents = CLASS_NAME_SPLITTER.splitToStream(checkName).iterator();
return urlPattern
.replace(TOP_LEVEL_CLASS_URL_PLACEHOLDER, nameComponents.next())
.replace(NESTED_CLASS_URL_PLACEHOLDER, Iterators.getNext(nameComponents, ""));
return getAnnotationValue(OnlineDocumentation.class, OnlineDocumentation::value, delegate)
.map(
urlPattern ->
urlPattern.replace(TOP_LEVEL_CLASS_URL_PLACEHOLDER, nameComponents.next()))
.map(
urlPattern ->
urlPattern.replace(
NESTED_CLASS_URL_PLACEHOLDER, Iterators.getNext(nameComponents, "")));
}

private SeverityLevel getSeverity(CodeTransformer delegate) {
Expand All @@ -105,23 +107,22 @@ private SeverityLevel getSeverity(CodeTransformer delegate) {
* `tech.picnic.errorprone.refaster.runner.Refaster` bug checker. (The associated
* `RefasterTest#severityAssignment` test verifies this invariant.)
*/
return getAnnotationValue(Severity.class, Severity::value, delegate, SUGGESTION);
return getAnnotationValue(Severity.class, Severity::value, delegate).orElse(SUGGESTION);
}

private String getDescription(CodeTransformer delegate) {
return getAnnotationValue(
tech.picnic.errorprone.refaster.annotation.Description.class,
tech.picnic.errorprone.refaster.annotation.Description::value,
delegate,
"Refactoring opportunity");
tech.picnic.errorprone.refaster.annotation.Description.class,
tech.picnic.errorprone.refaster.annotation.Description::value,
delegate)
.orElse("Refactoring opportunity");
}

private <A extends Annotation, T> T getAnnotationValue(
Class<A> annotation, Function<A, T> extractor, CodeTransformer delegate, T defaultValue) {
private <A extends Annotation, T> Optional<T> getAnnotationValue(
Class<A> annotation, Function<A, T> extractor, CodeTransformer delegate) {
return getAnnotationValue(delegate, annotation)
.or(() -> getAnnotationValue(this, annotation))
.map(extractor)
.orElse(defaultValue);
.map(extractor);
}

private static <A extends Annotation> Optional<A> getAnnotationValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class RefasterTest {
.expectErrorMessage(
"StringOfSizeZeroTemplate",
containsPattern(
"\\[Refaster Rule\\] FooTemplates\\.StringOfSizeZeroTemplate: Refactoring opportunity\\s+.+\\s+null"))
"\\[Refaster Rule\\] FooTemplates\\.StringOfSizeZeroTemplate: Refactoring opportunity\\s+.+\\s+"))
.expectErrorMessage(
"StringOfSizeOneTemplate",
containsPattern(
Expand Down

0 comments on commit 60c8c3f

Please sign in to comment.