Skip to content

Commit 4c9bb12

Browse files
committed
Change "qualified Invocations" wrapping option
Improve fluent API formatting by tweaking the "qualified Invocations" wrapping option. This commit also changes the fix for gh-332 by porting `align_selector_in_method_invocation_on_expression_first_line` to the Java 8 formatter. Closes gh-124
1 parent 4fdd565 commit 4c9bb12

File tree

8 files changed

+1706
-13
lines changed

8 files changed

+1706
-13
lines changed

.eclipse/org.eclipse.jdt.core.prefs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
127127
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
128128
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
129129
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
130-
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
130+
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=84
131131
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
132132
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
133133
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
@@ -136,7 +136,7 @@ org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration
136136
org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
137137
org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
138138
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
139-
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
139+
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=true
140140
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
141141
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
142142
org.eclipse.jdt.core.formatter.blank_lines_before_field=0

spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk8/src/main/java/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java

Lines changed: 1687 additions & 0 deletions
Large diffs are not rendered by default.

spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/src/main/java/io/spring/javaformat/formatter/eclipse/rewrite/EclipseRewriter.java

Lines changed: 7 additions & 1 deletion
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.
@@ -77,6 +77,7 @@ private void rewrite(JdkVersion jdkVersion, FileSystem zip) throws IOException {
7777
DefaultCodeFormatterManipulator::new);
7878
if (jdkVersion == JdkVersion.V8) {
7979
rewrite(zip, "org/eclipse/osgi/util/NLS$1.class", NlsJdk8Manipulator::new);
80+
deleteWrapPreparator(zip);
8081
}
8182
else {
8283
rewrite(zip, "org/eclipse/osgi/util/NLS.class", NlsJdk11Manipulator::new);
@@ -94,6 +95,11 @@ private void rewrite(FileSystem zip, String name, Function<ClassWriter, ClassVis
9495
Files.copy(new ByteArrayInputStream(classWriter.toByteArray()), path, StandardCopyOption.REPLACE_EXISTING);
9596
}
9697

98+
private void deleteWrapPreparator(FileSystem zip) throws IOException {
99+
Path path = zip.getPath("org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.class");
100+
Files.delete(path);
101+
}
102+
97103
public static void main(String[] args) throws Exception {
98104
new EclipseRewriter().rewrite(JdkVersion.valueOf("V" + args[0]), args[1]);
99105
}

spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/FormatterTests.java

Lines changed: 2 additions & 2 deletions
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.
@@ -43,7 +43,7 @@ public void format(Item item) throws Exception {
4343
print("Expected +" + item.getExpected(), expectedContent);
4444
print("Got", formattedContent);
4545
System.out.println("========================================");
46-
assertThat(expectedContent).isEqualTo(formattedContent)
46+
assertThat(formattedContent).isEqualTo(expectedContent)
4747
.describedAs("Formatted content does not match for " + item.getSource());
4848
}
4949
}

spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/complex.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -557,8 +557,8 @@ public class SpringApplication {
557557
*/
558558
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
559559
if (this.beanNameGenerator != null) {
560-
context.getBeanFactory().registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
561-
this.beanNameGenerator);
560+
context.getBeanFactory()
561+
.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, this.beanNameGenerator);
562562
}
563563
if (this.resourceLoader != null) {
564564
if (context instanceof GenericApplicationContext) {

spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/multi-line-statement-indentation.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ public class Simple {
1212
public String someMethod() throws MalformedURLException, IOException {
1313
String settingsXml = new String(Files.readAllBytes(Paths.get("src", "intTest", "projects", "settings.xml")),
1414
StandardCharsets.UTF_8)
15-
.replace("@localCentralUrl@",
16-
new File("build/int-test-maven-repository").toURI().toURL().toString())
17-
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
15+
.replace("@localCentralUrl@", new File("build/int-test-maven-repository").toURI().toURL().toString())
16+
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
1817
return settingsXml;
1918
}
2019

spring-javaformat/spring-javaformat-formatter/src/main/resources/io/spring/javaformat/formatter/eclipse/formatter.prefs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ core.formatter.alignment_for_parameters_in_constructor_declaration=16
3030
core.formatter.alignment_for_parameters_in_method_declaration=16
3131
core.formatter.alignment_for_relational_operator=0
3232
core.formatter.alignment_for_resources_in_try=80
33-
core.formatter.alignment_for_selector_in_method_invocation=16
33+
core.formatter.alignment_for_selector_in_method_invocation=84
3434
core.formatter.alignment_for_shift_operator=0
3535
core.formatter.alignment_for_string_concatenation=16
3636
core.formatter.alignment_for_superclass_in_type_declaration=16
@@ -41,7 +41,7 @@ core.formatter.alignment_for_throws_clause_in_method_declaration=16
4141
core.formatter.alignment_for_type_arguments=0
4242
core.formatter.alignment_for_type_parameters=0
4343
core.formatter.alignment_for_union_type_in_multicatch=16
44-
core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
44+
core.formatter.align_selector_in_method_invocation_on_expression_first_line=true
4545
core.formatter.blank_lines_after_imports=1
4646
core.formatter.blank_lines_after_package=1
4747
core.formatter.blank_lines_before_field=0

src/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="Javadoc*" />
77
<suppress files=".*Tests\.java" checks="Javadoc*" />
88
<suppress files="generated-sources" checks="[a-zA-Z0-9]*" />
9+
<suppress files="org[\\/]eclipse[\\/]jdt[\\/]internal[\\/]formatter[\\/]linewrap[\\/]WrapPreparator\.java" checks="[a-zA-Z0-9]*" />
910
</suppressions>

0 commit comments

Comments
 (0)