Skip to content

Commit

Permalink
Ensure newlines are added before record/enum/annotation types
Browse files Browse the repository at this point in the history
Update `JavadocLineBreakPreparator` to ensure that two spaces are added
before `@param` tags on record, enum and annotation types.

Fixes gh-346
  • Loading branch information
philwebb committed Feb 17, 2023
1 parent 39f34a8 commit 745b0f2
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package simple;

/**
* Settings that can be applied when creating a {@link ClientHttpRequestFactory}.
*
* @param connectTimeout the connect timeout
* @param readTimeout the read timeout
* @param bufferRequestBody if request body buffering is used
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.0.0
* @see ClientHttpRequestFactories
*/
public record Simple(String name) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package simple;

/**
* Simple.
*
* @author Phillip Webb
* @since 1.0.0
*/
public class Simple {

public static void main(String[] args) throws Exception {
// FIXME
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package simple;

/**
* Settings that can be applied when creating a {@link ClientHttpRequestFactory}.
*
* @param connectTimeout the connect timeout
* @param readTimeout the read timeout
* @param bufferRequestBody if request body buffering is used
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.0.0
* @see ClientHttpRequestFactories
*/
public record Simple(String name) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package simple;

/**
* Settings that can be applied when creating a {@link ClientHttpRequestFactory}.
* @param connectTimeout the connect timeout
* @param readTimeout the read timeout
* @param bufferRequestBody if request body buffering is used
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.0.0
* @see ClientHttpRequestFactories
*/
public record Simple(String name) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package simple;

/**
* Simple.
*
* @author Phillip Webb
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.TokenManager;

/**
* {@link Preparator} to fine tune curly-brace line breaks.
* {@link Preparator} to finetune curly-brace line breaks.
*
* @author Phillip Webb
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,20 +22,20 @@

import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTNode;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTVisitor;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.AbstractTypeDeclaration;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.Comment;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.CompilationUnit;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.Javadoc;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TagElement;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TextElement;
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TypeDeclaration;
import io.spring.javaformat.eclipse.jdt.jdk11.core.formatter.CodeFormatter;
import io.spring.javaformat.eclipse.jdt.jdk11.internal.compiler.parser.TerminalTokens;
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.Preparator;
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.Token;
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.TokenManager;

/**
* {@link Preparator} to fine tune Javadoc whitespace.
* {@link Preparator} to finetune Javadoc whitespace.
*
* @author Phillip Webb
*/
Expand Down Expand Up @@ -112,15 +112,15 @@ public boolean visit(TagElement node) {
int startIndex = this.commentTokenManager.findIndex(node.getStartPosition(), -1, false);
Token token = this.commentTokenManager.get(startIndex);
token.clearLineBreaksBefore();
token.putLineBreaksBefore(
this.declaration instanceof TypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
boolean isTypeDeclaration = this.declaration instanceof AbstractTypeDeclaration;
token.putLineBreaksBefore(isTypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
this.firstTagElement = false;
}
return true;
}

private boolean isSquashRequired(TagElement node, ASTNode declaration) {
if (declaration instanceof TypeDeclaration) {
if (declaration instanceof AbstractTypeDeclaration) {
String tagName = node.getTagName();
return (!node.isNested() && tagName != null && tagName.startsWith("@"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.TokenManager;

/**
* {@link Preparator} to fine tune curly-brace line breaks.
* {@link Preparator} to finetune curly-brace line breaks.
*
* @author Phillip Webb
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,20 +22,20 @@

import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.ASTNode;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.ASTVisitor;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.AbstractTypeDeclaration;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.Comment;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.CompilationUnit;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.Javadoc;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.TagElement;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.TextElement;
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.TypeDeclaration;
import io.spring.javaformat.eclipse.jdt.jdk8.core.formatter.CodeFormatter;
import io.spring.javaformat.eclipse.jdt.jdk8.internal.compiler.parser.TerminalTokens;
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.Preparator;
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.Token;
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.TokenManager;

/**
* {@link Preparator} to fine tune Javadoc whitespace.
* {@link Preparator} to finetune Javadoc whitespace.
*
* @author Phillip Webb
*/
Expand Down Expand Up @@ -112,15 +112,15 @@ public boolean visit(TagElement node) {
int startIndex = this.commentTokenManager.findIndex(node.getStartPosition(), -1, false);
Token token = this.commentTokenManager.get(startIndex);
token.clearLineBreaksBefore();
token.putLineBreaksBefore(
this.declaration instanceof TypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
boolean isTypeDeclaration = this.declaration instanceof AbstractTypeDeclaration;
token.putLineBreaksBefore(isTypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
this.firstTagElement = false;
}
return true;
}

private boolean isSquashRequired(TagElement node, ASTNode declaration) {
if (declaration instanceof TypeDeclaration) {
if (declaration instanceof AbstractTypeDeclaration) {
String tagName = node.getTagName();
return (!node.isNested() && tagName != null && tagName.startsWith("@"));
}
Expand Down

0 comments on commit 745b0f2

Please sign in to comment.