Skip to content

Commit

Permalink
Turn off the JavadocComment (#152)
Browse files Browse the repository at this point in the history
Turn off the javadoc formatter entirely.

We still indent the javadoc prefix to the corect column, but don't do any code reflowing or HTML tag correction anymore.
  • Loading branch information
dansanduleac authored and bulldozer-bot[bot] committed Jan 28, 2020
1 parent b194b37 commit 56c4824
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 361 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-152.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Turn off the javadoc formatter entirely.
links:
- https://github.com/palantir/palantir-java-format/pull/152
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,26 @@ public final class Formatter {

private final JavaFormatterOptions options;
private final boolean debugMode;
private final JavaFormatterInternalOptions internalOptions;

@VisibleForTesting
Formatter(JavaFormatterOptions options, boolean debugMode) {
Formatter(JavaFormatterOptions options, boolean debugMode, JavaFormatterInternalOptions internalOptions) {
this.options = options;
this.debugMode = debugMode;
this.internalOptions = internalOptions;
}

/** A new Formatter instance with default options. */
public static Formatter create() {
return new Formatter(JavaFormatterOptions.defaultOptions(), false);
return new Formatter(
JavaFormatterOptions.defaultOptions(),
false,
JavaFormatterInternalOptions.builder().build());
}

public static Formatter createFormatter(JavaFormatterOptions options) {
return new Formatter(options, false);
return new Formatter(
options, false, JavaFormatterInternalOptions.builder().build());
}

/**
Expand Down Expand Up @@ -273,7 +279,8 @@ public ImmutableList<Replacement> getFormatReplacements(String input, Collection
// 'de-linting' changes (e.g. import ordering).
javaInput = ModifierOrderer.reorderModifiers(javaInput, characterRanges);

JavaCommentsHelper commentsHelper = new JavaCommentsHelper(javaInput.getLineSeparator(), options);
JavaCommentsHelper commentsHelper =
new JavaCommentsHelper(javaInput.getLineSeparator(), options, internalOptions);
JavaOutput javaOutput;
try {
javaOutput = format(javaInput, options, commentsHelper, debugMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public final class JavaCommentsHelper implements CommentsHelper {
private final JavaFormatterOptions options;
private final JavadocFormatter javadocFormatter;

public JavaCommentsHelper(String lineSeparator, JavaFormatterOptions options) {
public JavaCommentsHelper(
String lineSeparator, JavaFormatterOptions options, JavaFormatterInternalOptions internalOptions) {
this.lineSeparator = lineSeparator;
this.options = options;
this.javadocFormatter = new JavadocFormatter(options.maxLineLength());
this.javadocFormatter =
internalOptions.reformatJavadoc() ? new JavadocFormatter(options.maxLineLength()) : null;
}

@Override
Expand All @@ -45,7 +47,7 @@ public String rewrite(Tok tok, int maxWidth, int column0) {
return tok.getOriginalText();
}
String text = tok.getOriginalText();
if (tok.isJavadocComment()) {
if (javadocFormatter != null && tok.isJavadocComment()) {
text = javadocFormatter.formatJavadoc(text, column0);
}
List<String> lines = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.palantir.javaformat.java;

import com.google.errorprone.annotations.Immutable;
import org.immutables.value.Value;

@Value.Immutable
@Immutable
interface JavaFormatterInternalOptions {

@Value.Default
default boolean reformatJavadoc() {
return false;
}

class Builder extends ImmutableJavaFormatterInternalOptions.Builder {}

static Builder builder() {
return new Builder();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ private static Formatter createFormatter() {
JavaFormatterOptions.builder()
.style(JavaFormatterOptions.Style.PALANTIR)
.build(),
isDebugMode());
isDebugMode(),
JavaFormatterInternalOptions.builder().build());
}

@TestTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
@Execution(ExecutionMode.CONCURRENT)
public final class JavadocFormattingTest {

private final Formatter formatter = Formatter.createFormatter(JavaFormatterOptions.builder()
.style(JavaFormatterOptions.Style.GOOGLE)
.build());
private final Formatter formatter = new Formatter(
JavaFormatterOptions.builder()
.style(JavaFormatterOptions.Style.GOOGLE)
.build(),
false,
JavaFormatterInternalOptions.builder().reformatJavadoc(true).build());

@Test
public void notJavadoc() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ public void javadoc() throws Exception {
"/**",
" * graph",
" *",
" * <p>graph",
" * graph",
" *",
" * @param foo lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do" + " eiusmod tempor",
" * incididunt ut labore et dolore magna aliqua",
" * @param foo lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
+ " eiusmod tempor incididunt ut labore et dolore magna aliqua",
" */",
"class Test {",
" /** creates entropy */",
" /**",
" * creates entropy",
" */",
" public static void main(String... args) {}",
"}",
"",
Expand Down
Loading

0 comments on commit 56c4824

Please sign in to comment.