@@ -27,6 +27,7 @@ public class PalantirJavaFormatStep {
2727// prevent direct instantiation
2828private PalantirJavaFormatStep () {}
2929
30+ private static final boolean DEFAULT_FORMAT_JAVADOC = false ;
3031private static final String DEFAULT_STYLE = "PALANTIR" ;
3132private static final String NAME = "palantir-java-format" ;
3233public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:" ;
@@ -42,14 +43,25 @@ public static FormatterStep create(String version, Provisioner provisioner) {
4243return create (version , defaultStyle (), provisioner );
4344}
4445
45- /** Creates a step which formats everything - code, import order, and unused imports. And with the style input. */
46+ /**
47+ * Creates a step which formats code, import order, and unused imports, but not Java docs. And with the given format
48+ * style.
49+ */
4650public static FormatterStep create (String version , String style , Provisioner provisioner ) {
51+ return create (version , style , DEFAULT_FORMAT_JAVADOC , provisioner );
52+ }
53+
54+ /**
55+ * Creates a step which formats everything - code, import order, unused imports, and Java docs. And with the given
56+ * format style.
57+ */
58+ public static FormatterStep create (String version , String style , boolean formatJavadoc , Provisioner provisioner ) {
4759Objects .requireNonNull (version , "version" );
4860Objects .requireNonNull (style , "style" );
4961Objects .requireNonNull (provisioner , "provisioner" );
5062
5163return FormatterStep .createLazy (NAME ,
52- () -> new State (JarState .from (MAVEN_COORDINATE + version , provisioner ), version , style ),
64+ () -> new State (JarState .from (MAVEN_COORDINATE + version , provisioner ), version , style , formatJavadoc ),
5365State ::createFormat );
5466}
5567
@@ -63,6 +75,11 @@ public static String defaultStyle() {
6375return DEFAULT_STYLE ;
6476}
6577
78+ /** Get default for whether Java docs should be formatted */
79+ public static boolean defaultFormatJavadoc () {
80+ return DEFAULT_FORMAT_JAVADOC ;
81+ }
82+
6683private static final class State implements Serializable {
6784private static final long serialVersionUID = 1L ;
6885
@@ -71,23 +88,23 @@ private static final class State implements Serializable {
7188/** Version of the formatter jar. */
7289private final String formatterVersion ;
7390private final String style ;
91+ /** Whether to format Java docs. */
92+ private final boolean formatJavadoc ;
7493
75- State (JarState jarState , String formatterVersion ) {
76- this (jarState , formatterVersion , DEFAULT_STYLE );
77- }
78-
79- State (JarState jarState , String formatterVersion , String style ) {
94+ State (JarState jarState , String formatterVersion , String style , boolean formatJavadoc ) {
8095ModuleHelper .doOpenInternalPackagesIfRequired ();
8196this .jarState = jarState ;
8297this .formatterVersion = formatterVersion ;
8398this .style = style ;
99+ this .formatJavadoc = formatJavadoc ;
84100}
85101
86102FormatterFunc createFormat () throws Exception {
87103final ClassLoader classLoader = jarState .getClassLoader ();
88104final Class <?> formatterFunc = classLoader .loadClass ("com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc" );
89- final Constructor <?> constructor = formatterFunc .getConstructor (String .class ); // style
90- return JVM_SUPPORT .suggestLaterVersionOnError (formatterVersion , (FormatterFunc ) constructor .newInstance (style ));
105+ // 1st arg is "style", 2nd arg is "formatJavadoc"
106+ final Constructor <?> constructor = formatterFunc .getConstructor (String .class , boolean .class );
107+ return JVM_SUPPORT .suggestLaterVersionOnError (formatterVersion , (FormatterFunc ) constructor .newInstance (style , formatJavadoc ));
91108}
92109}
93110}
0 commit comments