Bug 530122 - Add new Clean Up profile which is more helpful and modern
Summary: Add new Clean Up profile which is more helpful and modern
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.20 M3   Edit
Assignee: Fabrice Tiercelin CLA
QA Contact: Lars Vogel CLA
URL:
Whiteboard:
Keywords: noteworthy, ui
Depends on: 573629 573669
Blocks: 571203
  Show dependency tree
 
Reported: 2018-01-22 06:43 EST by Lars Vogel CLA
Modified: 2021-05-28 06:00 EDT (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2018-01-22 06:43:20 EST
I suggest to update the default clean-up profile.

I think we should add:

Organize imports
Use always blocks
Convert to lambdas
Remove redundant type arguments
Comment 1 Lars Vogel CLA 2018-01-22 06:54:31 EST
Setting the milestone so that this is not forgotten. I'm happy to contribute a patch if the JDT agrees to a set of changes.
Comment 2 Andrey Loskutov CLA 2018-01-23 03:45:02 EST
Also:

Remove trailing whitespace (o) all lines
Convert for loops to enhanced
Convert modifier final where possible [x] private fields
Comment 3 Lars Vogel CLA 2018-01-23 03:53:41 EST
(In reply to Andrey Loskutov from comment #2)

> Remove trailing whitespace (o) all lines
> Convert for loops to enhanced

+1 

> Convert modifier final where possible [x] private fields

-1 for enabling "Use modifier "final" where possible for private fields. With
 Java 8 (effective final) this is even less important and IMHO using "final" unnecessary clutters the code. Also the default Eclipse cleanup profile should reflectd the Eclipse programming standards in which we also do not use final if not necessary.
Comment 4 Jay Arthanareeswaran CLA 2018-01-23 09:06:34 EST
I think this has been mentioned in the past. I am not in favor of this kind of changes that will introduce unrelated changes to the commit. Not just that, it will affects the history and in some cases, makes the blame annotations almost useless.
Comment 5 Andrey Loskutov CLA 2018-01-23 09:12:24 EST
(In reply to Jay Arthanareeswaran from comment #4)
> I think this has been mentioned in the past. I am not in favor of this kind
> of changes that will introduce unrelated changes to the commit. Not just
> that, it will affects the history and in some cases, makes the blame
> annotations almost useless.

I guess you misunderstood the request. This is not about "automated fix" on save, this is about Source -> Cleanup defaults, which is not applied automatically.
Comment 6 Stephan Herrmann CLA 2018-01-23 10:16:39 EST
(In reply to Andrey Loskutov from comment #5)
> (In reply to Jay Arthanareeswaran from comment #4)
> > I think this has been mentioned in the past. I am not in favor of this kind
> > of changes that will introduce unrelated changes to the commit. Not just
> > that, it will affects the history and in some cases, makes the blame
> > annotations almost useless.
> 
> I guess you misunderstood the request. This is not about "automated fix" on
> save, this is about Source -> Cleanup defaults, which is not applied
> automatically.

I was wondering exactly this question. I'm relieved to see that this is not about Save Actions, but then: when will those cleanups be performed? Only for new files? That's the only viable strategy that I could imagine.
Comment 7 Jay Arthanareeswaran CLA 2018-01-23 10:41:20 EST
(In reply to Stephan Herrmann from comment #6)
> but then: when will those cleanups be performed? Only
> for new files? That's the only viable strategy that I could imagine.

I am not sure if that works only on new files. If it touches even existing files, then, for e.g., removing trailing whitespace might land us in trouble.
Comment 8 Lars Vogel CLA 2018-01-23 10:45:15 EST
Jay/Stephan, this bug is about adjusting the default profile, not about applying it to JDT core.

Please check yourself via the context menu, Source-> Cleanup
Comment 9 Stephan Herrmann CLA 2018-01-23 11:46:14 EST
(In reply to Lars Vogel from comment #8)
> Jay/Stephan, this bug is about adjusting the default profile, not about
> applying it to JDT core.
> 
> Please check yourself via the context menu, Source-> Cleanup

In that case the bug is only placed in the wrong bucket. Moving to where default cleanup profiles are *implemented*. JDT/Core has nothing to do with that.

See org.eclipse.jdt.internal.corext.fix.CleanUpConstants.setEclipseDefaultSettings(CleanUpOptions)
Comment 10 Sarika Sinha CLA 2018-02-27 06:47:40 EST
Moving to M7.
Comment 11 Eclipse Genie CLA 2019-05-21 04:36:51 EDT
New Gerrit change created: https://git.eclipse.org/r/142480
Comment 12 Lars Vogel CLA 2019-05-21 04:39:17 EDT
I suggest to also add the "Remove redundant Semicolons"
Comment 13 Dani Megert CLA 2019-05-30 10:14:43 EDT
Like with formatter defaults we can't change them under the feet of our developers and customers, especially because that affects their code. When we modernized the Formatter profile we introduced a new one. This is what we can do here too.

We can either come up with a new name for the new profile or reuse the existing name and rename the old one, e.g. "Eclipse < 4.13 [built-in]". For the formatter we did the latter.


As for the suggested changes, I agree with them except with
    Use always blocks
This has nothing to do with "modern", it's just a pure style issue. Lars, I happily saw that you did not include this in your suggested Gerrit change. We should not enable anything on the 'Code Style' tab.
Comment 14 Noopur Gupta CLA 2019-08-27 11:27:38 EDT
Moving out of 4.13. Target can be reassigned when updated patch is available.
Comment 15 Lars Vogel CLA 2020-03-17 14:06:20 EDT
(In reply to Dani Megert from comment #13)
> Like with formatter defaults we can't change them under the feet of our
> developers and customers, especially because that affects their code. When
> we modernized the Formatter profile we introduced a new one. This is what we
> can do here too.

Actually we did not. We changed the default formatter and the agreement was that this is OK. IIRC if we change the defaults and the customer used the default profile as save action nothing will change automatically, he has to manually reselect the profile. 

> We can either come up with a new name for the new profile or reuse the
> existing name and rename the old one, e.g. "Eclipse < 4.13 [built-in]". For
> the formatter we did the latter.


> As for the suggested changes, I agree with them except with
>     Use always blocks
> This has nothing to do with "modern", it's just a pure style issue. 

+1

Lars, I
> happily saw that you did not include this in your suggested Gerrit change.
> We should not enable anything on the 'Code Style' tab.
Comment 16 Lars Vogel CLA 2020-03-27 05:42:01 EDT
Dani, please response or remove your -1 in the change.
Comment 17 Dani Megert CLA 2020-04-06 07:46:18 EDT
(In reply to Lars Vogel from comment #15)
> (In reply to Dani Megert from comment #13)
> > Like with formatter defaults we can't change them under the feet of our
> > developers and customers, especially because that affects their code. When
> > we modernized the Formatter profile we introduced a new one. This is what we
> > can do here too.
> 
> Actually we did not. We changed the default formatter and the agreement was
> that this is OK. IIRC if we change the defaults and the customer used the
> default profile as save action nothing will change automatically, he has to
> manually reselect the profile.
If the Clean Up settings are not stored in the project and we change the default, then running the Clean Up will change the code. I can be convinced to accept that as long as we document this in the N&N and give the advice to store the Clean Up settings in the project. WDYT?
Comment 18 Lars Vogel CLA 2021-04-01 05:21:48 EDT
Fabrice, which cleanups would you recommend to have enabled by default?
Comment 19 Fabrice Tiercelin CLA 2021-04-01 11:02:45 EDT
Here is my list and then my arguments:

As "Save action":
ELSE_IF
NUMBER_SUFFIX

As "Cleanup":
USE_SWITCH
PULL_UP_ASSIGNMENT
ELSE_IF
REDUCE_INDENTATION
INSTANCEOF
NUMBER_SUFFIX
SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF
PRECOMPILE_REGEX
NO_STRING_CREATION
PREFER_BOOLEAN_LITERAL
SINGLE_USED_FIELD
BREAK_LOOP
STATIC_INNER_CLASS
STRINGBUILDER
PLAIN_REPLACEMENT
USE_LAZY_LOGICAL_OPERATOR
VALUEOF_RATHER_THAN_INSTANTIATION
PRIMITIVE_COMPARISON
PRIMITIVE_PARSING
PRIMITIVE_SERIALIZATION
INSERT_INFERRED_TYPE_ARGUMENTS
SUBSTRING
ARRAYS_FILL
EVALUATE_NULLABLE
PUSH_DOWN_NEGATION
DOUBLE_NEGATION
REMOVE_REDUNDANT_COMPARISON_STATEMENT
REDUNDANT_SUPER_CALL
UNREACHABLE_BLOCK
REDUNDANT_FALLING_THROUGH_BLOCK_END
COLLECTION_CLONING
MAP_CLONING
OVERRIDDEN_ASSIGNMENT
REMOVE_REDUNDANT_MODIFIERS
RAISE_EMBEDDED_IF
REMOVE_REDUNDANT_SEMICOLONS
REDUNDANT_COMPARATOR
REMOVE_UNNECESSARY_ARRAY_CREATION
ARRAY_WITH_CURLY
REMOVE_USELESS_RETURN
REMOVE_USELESS_CONTINUE
UNLOOPED_WHILE
FORMAT_SOURCE_CODE
ORGANIZE_IMPORTS
SORT_MEMBERS
MODERNIZE_HASH
USE_OBJECTS_EQUALS
OPERAND_FACTORIZATION
TERNARY_OPERATOR
STRICTLY_EQUAL_OR_DIFFERENT
MERGE_CONDITIONAL_BLOCKS
CONTROLFLOW_MERGE
USE_PATTERN_MATCHING_FOR_INSTANCEOF
CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS
USE_VAR
USE_LAMBDA
COMPARING_ON_CRITERIA
JOIN
TRY_WITH_RESOURCE
MULTI_CATCH
REMOVE_REDUNDANT_TYPE_ARGUMENTS
USE_AUTOBOXING
USE_UNBOXING
CONTROL_STATEMENTS_CONVERT_FOR_LOOP_TO_ENHANCED
CONTROL_STATEMENTS_CONVERT_FOR_LOOP_ONLY_IF_LOOP_VAR_USED
CONTROL_STATEMENTS_USE_ADD_ALL

Firstly, I exclude all the "Source fixing" cleanups as it may alter the code. For the same reason, I exclude the cleanups that are based on methods as a custom implementation may behave in an unexpected way. I include and exclude some "Code style" cleanups as someones are common conventions and others are just suggestion but not a common convention. For the rest, we should include as many cleanups as possible. Only few developers use the cleanups because you need to discover the feature. The more you have to click, the less a person discover it.

I include very few things in "Save action" as it apply on unfinished code and cleanups need to run on valid code. The ones I added are almost formatting.
Comment 20 Eclipse Genie CLA 2021-04-01 11:07:11 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/178732
Comment 21 Noopur Gupta CLA 2021-04-05 04:24:09 EDT
Please enable only those clean ups that were discussed before comment #17 in this bug. If you want to include any other clean ups then provide an explanation/justification for each of them.

Also, make sure to document the effect and guidelines as mentioned in comment #17.
Comment 22 Noopur Gupta CLA 2021-04-05 04:31:27 EDT
(In reply to Fabrice Tiercelin from comment #19)
If you plan to enable all these clean ups then please add a new experimental profile for that in a separate bug report. I do not recommend enabling all these by default as many of them are still incomplete with follow up bugs being discovered or worked upon. Since clean ups are applied as bulk operation and can potentially cause semantic bugs in the code that can go unnoticed, they should be enabled only after they are more stable than the current state.
Comment 23 Fabrice Tiercelin CLA 2021-04-05 04:56:25 EDT
OK so I have restored all the cleanups that are new in Eclipse 2021-03 and the ones that have or had recently open bugs. For the ones added after comment #17, I will add comment after this message.
Comment 24 Fabrice Tiercelin CLA 2021-04-05 05:21:32 EDT
NUMBER_SUFFIX
An old cleanup without bug since. A simple cleanup close to a format rule.

PRECOMPILE_REGEX
From Eclipse 4.17 without bug since.

NO_STRING_CREATION
From Eclipse 4.18 without bug since. Very local changes.

PREFER_BOOLEAN_LITERAL
From Eclipse 4.18 without bug since. Very local changes.

SINGLE_USED_FIELD
From Eclipse 4.18 without bug since.

USE_LAZY_LOGICAL_OPERATOR
An old cleanup without bug since. A simple cleanup close to a format rule.

PRIMITIVE_COMPARISON
From Eclipse 4.19 without bug since. Very local changes.

PRIMITIVE_PARSING
From Eclipse 4.19 without bug since. Very local changes.

PRIMITIVE_SERIALIZATION
From Eclipse 4.19 without bug since. Very local changes.

INSERT_INFERRED_TYPE_ARGUMENTS
An old cleanup without bug since. A simple cleanup close to a format rule.

EVALUATE_NULLABLE
From Eclipse 4.18 without bug since. Very local changes.

PUSH_DOWN_NEGATION
An old cleanup without bug since.

DOUBLE_NEGATION
From Eclipse 4.18 without bug since. Very local changes.

REMOVE_REDUNDANT_COMPARISON_STATEMENT
From Eclipse 4.18 without bug since. Local changes.

REDUNDANT_SUPER_CALL
From Eclipse 4.18 without bug since. Very local changes.

REDUNDANT_FALLING_THROUGH_BLOCK_END
From Eclipse 4.18 without bug since. It demonstrates the power of Eclipse.

COLLECTION_CLONING
From Eclipse 4.18 without bug since. Local changes.

MAP_CLONING
From Eclipse 4.18 without bug since. Local changes.

REMOVE_REDUNDANT_MODIFIERS
From Eclipse 4.16 and before without bug since. Very local changes.

RAISE_EMBEDDED_IF
From Eclipse 4.18 without bug since. Local changes.

REMOVE_REDUNDANT_SEMICOLONS
An old cleanup without bug since. A simple cleanup close to a format rule.

REMOVE_UNNECESSARY_ARRAY_CREATION
An old cleanup without bug since.

REMOVE_USELESS_RETURN
From Eclipse 4.18 without bug since. Local changes.

REMOVE_USELESS_CONTINUE
From Eclipse 4.18 without bug since. Local changes.

FORMAT_SOURCE_CODE
An old cleanup without bug since. A simple cleanup close to a format rule.

ORGANIZE_IMPORTS
An old cleanup without bug since. A simple cleanup close to a format rule.

SORT_MEMBERS
An old cleanup without bug since. A simple cleanup close to a format rule.

MODERNIZE_HASH
From Eclipse 4.18 without bug since. It demonstrates the power of Eclipse.

USE_OBJECTS_EQUALS
From Eclipse 4.18 without bug since. It demonstrates the power of Eclipse.

TERNARY_OPERATOR
From Eclipse 4.18 without bug since.

STRICTLY_EQUAL_OR_DIFFERENT
From Eclipse 4.18 without bug since.

MERGE_CONDITIONAL_BLOCKS
From Eclipse 4.18 without bug since.

USE_PATTERN_MATCHING_FOR_INSTANCEOF
From Eclipse 4.18 without bug since. It demonstrates that Eclipse is modern.

CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS
From Eclipse 4.18 without bug since. It demonstrates that Eclipse is modern.

USE_VAR
It demonstrates that Eclipse is modern.

USE_LAMBDA
It demonstrates that Eclipse is modern.

COMPARING_ON_CRITERIA
It demonstrates that Eclipse is modern.

JOIN
It demonstrates that Eclipse is modern.

TRY_WITH_RESOURCE
It demonstrates that Eclipse is modern.

MULTI_CATCH
It demonstrates that Eclipse is modern.

REMOVE_REDUNDANT_TYPE_ARGUMENTS
An old cleanup without bug since. A simple cleanup close to a format rule.

USE_AUTOBOXING
An old cleanup without bug since. A simple cleanup close to a format rule.

USE_UNBOXING
An old cleanup without bug since. A simple cleanup close to a format rule.

CONTROL_STATEMENTS_CONVERT_FOR_LOOP_TO_ENHANCED
An old cleanup without bug since. A simple cleanup close to a format rule.

CONTROL_STATEMENTS_CONVERT_FOR_LOOP_ONLY_IF_LOOP_VAR_USED
An old cleanup without bug since. A simple cleanup close to a format rule.

CONTROL_STATEMENTS_USE_ADD_ALL
An old cleanup without bug since. A simple cleanup close to a format rule.
Comment 25 Noopur Gupta CLA 2021-04-15 07:41:41 EDT
This was discussed during JDT call and the following two options were proposed:

1) Enable only those clean ups that were discussed until comment #17 in the default profile. Create a new clean up profile "experimental" (or another name) for clean ups in comment #24 via a separate bug.

Or,

2) Enable only the most relevant and useful new clean up options (approx. 4-5) in the default profile. For that, filter the list of proposed clean ups (comment #24):
- Remove any non-relevant options (e.g. Code style clean ups as these are just personal style preferences not to be enforced in the defaults).
- Apply each clean up option to the Eclipse SDK (Platform+JDT+PDE) codebase and check if there are any issues and the whether the test cases pass.
- Vote for the most useful clean up options out of the remaining ones to be included in the defaults. Jeff can help with evaluating them.
Comment 27 Carsten Hammer CLA 2021-05-08 07:44:10 EDT
I'm not sure how this works but I guess we have to implement something in 

public class CleanUpProfileVersioner implements IProfileVersioner {

	public static final String PROFILE_KIND= "CleanUpProfile"; //$NON-NLS-1$

	private static final int VERSION_1= 1; // 3.3M2
	private static final int VERSION_2= 2; // 3.3M3 Added ORGANIZE_IMPORTS

	public static final int CURRENT_VERSION= VERSION_2;

	@Override
	public int getFirstVersion() {
	    return VERSION_1;
    }

	@Override
	public int getCurrentVersion() {
	    return CURRENT_VERSION;
    }

	@Override
	public void update(CustomProfile profile) {
		final Map<String, String> oldSettings= profile.getSettings();
		Map<String, String> newSettings= updateAndComplete(oldSettings, profile.getVersion());
		profile.setVersion(CURRENT_VERSION);
		profile.setSettings(newSettings);
	}

This is in org.eclipse.jdt.internal.ui.preferences.cleanup of org.eclipse.jdt.ui and seems to be responsible to adjust cleanup profiles.
Comment 28 Noopur Gupta CLA 2021-05-17 04:13:31 EDT
@Fabrice, please add the N&N and close any pending issues here for M3 by EOD.
Comment 29 Eclipse Genie CLA 2021-05-19 11:06:11 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/179637
Comment 30 Eclipse Genie CLA 2021-05-19 11:13:25 EDT
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/180781
Comment 32 Lars Vogel CLA 2021-05-19 11:15:19 EDT
(In reply to Noopur Gupta from comment #28)
> @Fabrice, please add the N&N and close any pending issues here for M3 by EOD.

Done on behave of Fabrice.

Thanks Fabrice for the work.
Comment 33 Fabrice Tiercelin CLA 2021-05-19 13:51:48 EDT
(In reply to Lars Vogel from comment #32)
> (In reply to Noopur Gupta from comment #28)
> > @Fabrice, please add the N&N and close any pending issues here for M3 by EOD.
> 
> Done on behave of Fabrice.
> 
> Thanks Fabrice for the work.

Thank you, I have forgotten this N&N.