Skip to content

Commit 745b0f2

Browse files
committed
Ensure newlines are added before record/enum/annotation types
Update `JavadocLineBreakPreparator` to ensure that two spaces are added before `@param` tags on record, enum and annotation types. Fixes gh-346
1 parent 39f34a8 commit 745b0f2

File tree

9 files changed

+78
-17
lines changed

9 files changed

+78
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package simple;
2+
3+
/**
4+
* Settings that can be applied when creating a {@link ClientHttpRequestFactory}.
5+
*
6+
* @param connectTimeout the connect timeout
7+
* @param readTimeout the read timeout
8+
* @param bufferRequestBody if request body buffering is used
9+
* @author Andy Wilkinson
10+
* @author Phillip Webb
11+
* @since 3.0.0
12+
* @see ClientHttpRequestFactories
13+
*/
14+
public record Simple(String name) {
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package simple;
2+
3+
/**
4+
* Simple.
5+
*
6+
* @author Phillip Webb
7+
* @since 1.0.0
8+
*/
9+
public class Simple {
10+
11+
public static void main(String[] args) throws Exception {
12+
// FIXME
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package simple;
2+
3+
/**
4+
* Settings that can be applied when creating a {@link ClientHttpRequestFactory}.
5+
*
6+
* @param connectTimeout the connect timeout
7+
* @param readTimeout the read timeout
8+
* @param bufferRequestBody if request body buffering is used
9+
* @author Andy Wilkinson
10+
* @author Phillip Webb
11+
* @since 3.0.0
12+
* @see ClientHttpRequestFactories
13+
*/
14+
public record Simple(String name) {
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package simple;
2+
3+
/**
4+
* Settings that can be applied when creating a {@link ClientHttpRequestFactory}.
5+
* @param connectTimeout the connect timeout
6+
* @param readTimeout the read timeout
7+
* @param bufferRequestBody if request body buffering is used
8+
* @author Andy Wilkinson
9+
* @author Phillip Webb
10+
* @since 3.0.0
11+
* @see ClientHttpRequestFactories
12+
*/
13+
public record Simple(String name) {
14+
15+
}

Diff for: spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/simple.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package simple;
22

33
/**
44
* Simple.
5-
*
65
* @author Phillip Webb
76
* @since 1.0.0
87
*/

Diff for: spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk11/eclipse/CodeLineBreakPreparator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
3131
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.TokenManager;
3232

3333
/**
34-
* {@link Preparator} to fine tune curly-brace line breaks.
34+
* {@link Preparator} to finetune curly-brace line breaks.
3535
*
3636
* @author Phillip Webb
3737
*/

Diff for: spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk11/eclipse/JavadocLineBreakPreparator.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,20 +22,20 @@
2222

2323
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTNode;
2424
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTVisitor;
25+
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.AbstractTypeDeclaration;
2526
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.Comment;
2627
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.CompilationUnit;
2728
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.Javadoc;
2829
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TagElement;
2930
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TextElement;
30-
import io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TypeDeclaration;
3131
import io.spring.javaformat.eclipse.jdt.jdk11.core.formatter.CodeFormatter;
3232
import io.spring.javaformat.eclipse.jdt.jdk11.internal.compiler.parser.TerminalTokens;
3333
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.Preparator;
3434
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.Token;
3535
import io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.TokenManager;
3636

3737
/**
38-
* {@link Preparator} to fine tune Javadoc whitespace.
38+
* {@link Preparator} to finetune Javadoc whitespace.
3939
*
4040
* @author Phillip Webb
4141
*/
@@ -112,15 +112,15 @@ public boolean visit(TagElement node) {
112112
int startIndex = this.commentTokenManager.findIndex(node.getStartPosition(), -1, false);
113113
Token token = this.commentTokenManager.get(startIndex);
114114
token.clearLineBreaksBefore();
115-
token.putLineBreaksBefore(
116-
this.declaration instanceof TypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
115+
boolean isTypeDeclaration = this.declaration instanceof AbstractTypeDeclaration;
116+
token.putLineBreaksBefore(isTypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
117117
this.firstTagElement = false;
118118
}
119119
return true;
120120
}
121121

122122
private boolean isSquashRequired(TagElement node, ASTNode declaration) {
123-
if (declaration instanceof TypeDeclaration) {
123+
if (declaration instanceof AbstractTypeDeclaration) {
124124
String tagName = node.getTagName();
125125
return (!node.isNested() && tagName != null && tagName.startsWith("@"));
126126
}

Diff for: spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/CodeLineBreakPreparator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
3131
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.TokenManager;
3232

3333
/**
34-
* {@link Preparator} to fine tune curly-brace line breaks.
34+
* {@link Preparator} to finetune curly-brace line breaks.
3535
*
3636
* @author Phillip Webb
3737
*/

Diff for: spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/JavadocLineBreakPreparator.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,20 +22,20 @@
2222

2323
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.ASTNode;
2424
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.ASTVisitor;
25+
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.AbstractTypeDeclaration;
2526
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.Comment;
2627
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.CompilationUnit;
2728
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.Javadoc;
2829
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.TagElement;
2930
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.TextElement;
30-
import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.TypeDeclaration;
3131
import io.spring.javaformat.eclipse.jdt.jdk8.core.formatter.CodeFormatter;
3232
import io.spring.javaformat.eclipse.jdt.jdk8.internal.compiler.parser.TerminalTokens;
3333
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.Preparator;
3434
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.Token;
3535
import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.TokenManager;
3636

3737
/**
38-
* {@link Preparator} to fine tune Javadoc whitespace.
38+
* {@link Preparator} to finetune Javadoc whitespace.
3939
*
4040
* @author Phillip Webb
4141
*/
@@ -112,15 +112,15 @@ public boolean visit(TagElement node) {
112112
int startIndex = this.commentTokenManager.findIndex(node.getStartPosition(), -1, false);
113113
Token token = this.commentTokenManager.get(startIndex);
114114
token.clearLineBreaksBefore();
115-
token.putLineBreaksBefore(
116-
this.declaration instanceof TypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
115+
boolean isTypeDeclaration = this.declaration instanceof AbstractTypeDeclaration;
116+
token.putLineBreaksBefore(isTypeDeclaration && this.firstTagElement && this.hasText ? 2 : 1);
117117
this.firstTagElement = false;
118118
}
119119
return true;
120120
}
121121

122122
private boolean isSquashRequired(TagElement node, ASTNode declaration) {
123-
if (declaration instanceof TypeDeclaration) {
123+
if (declaration instanceof AbstractTypeDeclaration) {
124124
String tagName = node.getTagName();
125125
return (!node.isNested() && tagName != null && tagName.startsWith("@"));
126126
}

0 commit comments

Comments
 (0)