Skip to content

Commit

Permalink
fixup! address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
peihe committed Nov 1, 2016
1 parent 75ccba8 commit 3514a89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ public Iterable<String> apply(final @Nonnull Method method) {
public String apply(@Nonnull Annotation annotation) {
return String.format(
"[%s on %s]",
ReflectHelpers.toStringForPrint(annotation),
ReflectHelpers.ANNOTATION_CONCISE_STRING.apply(annotation),
ReflectHelpers.CLASS_AND_METHOD_FORMATTER.apply(method));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public String apply(@Nonnull Class<?> input) {
}
};

/**
* A {@link Function} that returns a concise string for a {@link Annotation}.
*/
public static final Function<Annotation, String> ANNOTATION_CONCISE_STRING =
new Function<Annotation, String>() {
@Override
public String apply(@Nonnull Annotation annotation) {
String annotationName = annotation.annotationType().getName();
String annotationNameWithoutPackage =
annotationName.substring(annotationName.lastIndexOf('.') + 1).replace('$', '.');
String annotationToString = annotation.toString();
String values = annotationToString.substring(annotationToString.indexOf('('));
return String.format("%s%s", annotationNameWithoutPackage, values);
}
};

/** A {@link Function} that formats types. */
public static final Function<Type, String> TYPE_SIMPLE_DESCRIPTION =
new Function<Type, String>() {
Expand Down Expand Up @@ -187,19 +203,4 @@ public static Iterable<Method> getClosureOfMethodsOnInterface(Class<?> iface) {
}
return builder.build();
}

/**
* Returns a concise string for printing a {@link Annotation}.
*
* @param annotation The {@link Annotation} to print.
* @return a concise string representation that doesn't contain the package name.
*/
public static String toStringForPrint(Annotation annotation) {
String annotationName = annotation.annotationType().getName();
String annotationNameWithoutPackage =
annotationName.substring(annotationName.lastIndexOf('.') + 1).replace('$', '.');
String annotationToString = annotation.toString();
String values = annotationToString.substring(annotationToString.indexOf('('));
return String.format("%s%s", annotationNameWithoutPackage, values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ private interface Options extends PipelineOptions {
public void testToStringForPrint() throws Exception {
assertEquals(
"Default.Integer(value=1)",
ReflectHelpers.toStringForPrint(
ReflectHelpers.ANNOTATION_CONCISE_STRING.apply(
Options.class.getMethod("getInteger").getAnnotations()[0]));

assertEquals(
"JsonIgnore(value=true)",
ReflectHelpers.toStringForPrint(
ReflectHelpers.ANNOTATION_CONCISE_STRING.apply(
Options.class.getMethod("getObject").getAnnotations()[0]));
}

Expand Down

0 comments on commit 3514a89

Please sign in to comment.