diff options
author | Mateusz Matela | 2022-01-08 12:28:09 +0000 |
---|---|---|
committer | Mateusz Matela | 2022-01-11 20:49:44 +0000 |
commit | e9f5f8f4d8a7e020e5570f083500c9f9f2ae8c22 (patch) | |
tree | 2d1a2b21ee56bb73b9a394f2c99a116e39136c92 | |
parent | 1eefdf9848ac4eadb73bc65f7be652ad1940f2cd (diff) | |
download | eclipse.jdt.ui-e9f5f8f4d8a7e020e5570f083500c9f9f2ae8c22.tar.gz eclipse.jdt.ui-e9f5f8f4d8a7e020e5570f083500c9f9f2ae8c22.tar.xz eclipse.jdt.ui-e9f5f8f4d8a7e020e5570f083500c9f9f2ae8c22.zip |
Bug 578115 - [formatter] Wrong indentation for method invocation on
multi-line expression - UI
Change-Id: I2d3808bd4f2616524bf6679434c6cd6e4b9d783e
Signed-off-by: Mateusz Matela <mateusz.matela@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/189411
Tested-by: JDT Bot <jdt-bot@eclipse.org>
5 files changed, 29 insertions, 11 deletions
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/preferences/formatter/ProfileVersionerCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/preferences/formatter/ProfileVersionerCore.java index d17bd716df..279c5e0308 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/preferences/formatter/ProfileVersionerCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/preferences/formatter/ProfileVersionerCore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,7 +23,7 @@ import org.eclipse.jdt.internal.ui.PreferenceConstantsCore; public class ProfileVersionerCore { - private static final int CURRENT_VERSION= 21; + private static final int CURRENT_VERSION= 22; public static int getFirstVersion() { return 1; @@ -94,6 +94,9 @@ public class ProfileVersionerCore { case 20: version20to21(oldSettings); //$FALL-THROUGH$ + case 21: + version21to22(oldSettings); + //$FALL-THROUGH$ default: for (Map.Entry<String, String> entry : oldSettings.entrySet()) { final String key= entry.getKey(); @@ -733,6 +736,10 @@ public class ProfileVersionerCore { } } + private static void version21to22(Map<String, String> oldSettings) { + oldSettings.put(DefaultCodeFormatterConstants.FORMATTER_ALIGN_SELECTOR_IN_METHOD_INVOCATION_ON_EXPRESSION_FIRST_LINE, DefaultCodeFormatterConstants.FALSE); + } + /* old format constant values */ private static final String FORMATTER_METHOD_DECLARATION_ARGUMENTS_ALIGNMENT = JavaCore.PLUGIN_ID + ".formatter.method_declaration_arguments_alignment"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/preview/formatter.java b/org.eclipse.jdt.ui/preview/formatter.java index d8df2311e5..37adab741d 100644 --- a/org.eclipse.jdt.ui/preview/formatter.java +++ b/org.eclipse.jdt.ui/preview/formatter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2021 Mateusz Matela and others. + * Copyright (c) 2018, 2022 Mateusz Matela and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -884,7 +884,11 @@ nested(200, //--PREVIEW--END--org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation //--PREVIEW--START--org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation -class Example {int foo(Some a) {return a.getFirst();}} +class Example { + String foo() { + return new StringBuilder(Arrays.asList(11111111, 22222222, 3333333, 44444444)).append("TextTextText").append(11111111 + 2222222 + 33333333).toStrinig(); + } +} //--PREVIEW--END--org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation //--PREVIEW--START--org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.java index fc145b09ff..f0c5bc5df0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -179,6 +179,7 @@ final class FormatterMessages extends NLS { public static String FormatterModifyDialog_lineWrap_pref_param_type_ref; public static String FormatterModifyDialog_lineWrap_pref_parameters; public static String FormatterModifyDialog_lineWrap_pref_qualified_invocations; + public static String FormatterModifyDialog_lineWrap_pref_qualified_invocations_indent_from_base_expression_first_line; public static String FormatterModifyDialog_lineWrap_pref_qualified_object_allocation_arguments; public static String FormatterModifyDialog_lineWrap_pref_record_components; public static String FormatterModifyDialog_lineWrap_pref_relational_operators; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.properties index 3acb951574..3eefe5c184 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2021 IBM Corporation and others. +# Copyright (c) 2000, 2022 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -219,6 +219,7 @@ FormatterModifyDialog_lineWrap_pref_parameters=Parameters FormatterModifyDialog_lineWrap_pref_additive_operators=Additive operators (+, -) FormatterModifyDialog_lineWrap_pref_arguments=Arguments FormatterModifyDialog_lineWrap_pref_qualified_invocations=Qualified invocations +FormatterModifyDialog_lineWrap_pref_qualified_invocations_indent_from_base_expression_first_line=Indent from the base expression's first line FormatterModifyDialog_lineWrap_pref_for='for' FormatterModifyDialog_lineWrap_pref_throws_clause='throws' clause FormatterModifyDialog_lineWrap_pref_try='try-with-resources' diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterModifyDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterModifyDialog.java index 9c5ff346ae..9a12f2802d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterModifyDialog.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterModifyDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -521,7 +521,7 @@ public class FormatterModifyDialog extends ModifyDialog { } public static ModifyAll<Spinner> addModifyAll(Section section, final Images images) { - return new ModifyAll<Spinner>(section, images) { + return new ModifyAll<>(section, images) { private Label fLabel; private ToolItem fRemoveLinesItem; @@ -1425,7 +1425,7 @@ public class FormatterModifyDialog extends ModifyDialog { .pref(FormatterMessages.FormatterModifyDialog_newLines_pref_keep_record_constructor_declaration_on_one_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_RECORD_CONSTRUCTOR_ON_ONE_LINE) .pref(FormatterMessages.FormatterModifyDialog_newLines_pref_keep_annotation_declaration_on_one_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_ANNOTATION_DECLARATION_ON_ONE_LINE); - return fTree.new SimpleTreeBuilder<PreferenceTreeNode<?>>(null, null, null) { + return fTree.new SimpleTreeBuilder<>(null, null, null) { @Override protected PreferenceTreeNode<?> build(Section parent, PreferenceBuilder ignored) { return sectionBuilder.build(parent, prefBuilder); @@ -1467,7 +1467,12 @@ public class FormatterModifyDialog extends ModifyDialog { .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_superinterfaces, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SUPERINTERFACES_IN_RECORD_DECLARATION)) .node(fTree.builder(FormatterMessages.FormatterModifyDialog_lineWrap_tree_function_calls, null, modAll) .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_arguments, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION) - .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_qualified_invocations, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SELECTOR_IN_METHOD_INVOCATION) + .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_qualified_invocations, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SELECTOR_IN_METHOD_INVOCATION, p -> { + CheckboxPreference child= fTree.addCheckbox(p, FormatterMessages.FormatterModifyDialog_lineWrap_pref_qualified_invocations_indent_from_base_expression_first_line, + DefaultCodeFormatterConstants.FORMATTER_ALIGN_SELECTOR_IN_METHOD_INVOCATION_ON_EXPRESSION_FIRST_LINE, CheckboxPreference.FALSE_TRUE); + p.addDependant(child, v -> DefaultCodeFormatterConstants.getWrappingStyle(v) != DefaultCodeFormatterConstants.WRAP_NO_SPLIT + && DefaultCodeFormatterConstants.getIndentStyle(v) != DefaultCodeFormatterConstants.INDENT_ON_COLUMN); + }) .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_explicit_constructor_invocations, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL) .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_object_allocation_arguments, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION) .pref(FormatterMessages.FormatterModifyDialog_lineWrap_pref_qualified_object_allocation_arguments, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION)) @@ -1672,7 +1677,7 @@ public class FormatterModifyDialog extends ModifyDialog { } } - return fTree.new SimpleTreeBuilder<PreferenceTreeNode<?>>(null, null, null) { + return fTree.new SimpleTreeBuilder<>(null, null, null) { @Override protected PreferenceTreeNode<?> build(Section parent, PreferenceBuilder prefBuilder) { |