Skip to content

Commit

Permalink
Change "qualified Invocations" wrapping option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
philwebb committed Feb 7, 2023
1 parent 4fdd565 commit 4c9bb12
Show file tree
Hide file tree
Showing 8 changed files with 1,706 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .eclipse/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=84
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
Expand All @@ -136,7 +136,7 @@ org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration
org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=true
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
Expand Down

Large diffs are not rendered by default.

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 @@ -77,6 +77,7 @@ private void rewrite(JdkVersion jdkVersion, FileSystem zip) throws IOException {
DefaultCodeFormatterManipulator::new);
if (jdkVersion == JdkVersion.V8) {
rewrite(zip, "org/eclipse/osgi/util/NLS$1.class", NlsJdk8Manipulator::new);
deleteWrapPreparator(zip);
}
else {
rewrite(zip, "org/eclipse/osgi/util/NLS.class", NlsJdk11Manipulator::new);
Expand All @@ -94,6 +95,11 @@ private void rewrite(FileSystem zip, String name, Function<ClassWriter, ClassVis
Files.copy(new ByteArrayInputStream(classWriter.toByteArray()), path, StandardCopyOption.REPLACE_EXISTING);
}

private void deleteWrapPreparator(FileSystem zip) throws IOException {
Path path = zip.getPath("org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.class");
Files.delete(path);
}

public static void main(String[] args) throws Exception {
new EclipseRewriter().rewrite(JdkVersion.valueOf("V" + args[0]), args[1]);
}
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 @@ -43,7 +43,7 @@ public void format(Item item) throws Exception {
print("Expected +" + item.getExpected(), expectedContent);
print("Got", formattedContent);
System.out.println("========================================");
assertThat(expectedContent).isEqualTo(formattedContent)
assertThat(formattedContent).isEqualTo(expectedContent)
.describedAs("Formatted content does not match for " + item.getSource());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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 @@ -557,8 +557,8 @@ public class SpringApplication {
*/
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
if (this.beanNameGenerator != null) {
context.getBeanFactory().registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
this.beanNameGenerator);
context.getBeanFactory()
.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, this.beanNameGenerator);
}
if (this.resourceLoader != null) {
if (context instanceof GenericApplicationContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ public class Simple {
public String someMethod() throws MalformedURLException, IOException {
String settingsXml = new String(Files.readAllBytes(Paths.get("src", "intTest", "projects", "settings.xml")),
StandardCharsets.UTF_8)
.replace("@localCentralUrl@",
new File("build/int-test-maven-repository").toURI().toURL().toString())
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
.replace("@localCentralUrl@", new File("build/int-test-maven-repository").toURI().toURL().toString())
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
return settingsXml;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ core.formatter.alignment_for_parameters_in_constructor_declaration=16
core.formatter.alignment_for_parameters_in_method_declaration=16
core.formatter.alignment_for_relational_operator=0
core.formatter.alignment_for_resources_in_try=80
core.formatter.alignment_for_selector_in_method_invocation=16
core.formatter.alignment_for_selector_in_method_invocation=84
core.formatter.alignment_for_shift_operator=0
core.formatter.alignment_for_string_concatenation=16
core.formatter.alignment_for_superclass_in_type_declaration=16
Expand All @@ -41,7 +41,7 @@ core.formatter.alignment_for_throws_clause_in_method_declaration=16
core.formatter.alignment_for_type_arguments=0
core.formatter.alignment_for_type_parameters=0
core.formatter.alignment_for_union_type_in_multicatch=16
core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
core.formatter.align_selector_in_method_invocation_on_expression_first_line=true
core.formatter.blank_lines_after_imports=1
core.formatter.blank_lines_after_package=1
core.formatter.blank_lines_before_field=0
Expand Down
1 change: 1 addition & 0 deletions src/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="Javadoc*" />
<suppress files=".*Tests\.java" checks="Javadoc*" />
<suppress files="generated-sources" checks="[a-zA-Z0-9]*" />
<suppress files="org[\\/]eclipse[\\/]jdt[\\/]internal[\\/]formatter[\\/]linewrap[\\/]WrapPreparator\.java" checks="[a-zA-Z0-9]*" />
</suppressions>

0 comments on commit 4c9bb12

Please sign in to comment.