Bug 559006 - [formatter] Wrong indentation in region after wrapped line
Summary: [formatter] Wrong indentation in region after wrapped line
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.15   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.15 M3   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard: To be verified for 4.15 M3
Keywords: regression
: 559128 559638 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-01-10 04:23 EST by Simeon Andreev CLA
Modified: 2020-01-29 06:38 EST (History)
5 users (show)

See Also:


Attachments
One example of wrong indentations added by the code formatter. (258.03 KB, video/mp4)
2020-01-10 04:23 EST, Simeon Andreev CLA
no flags Details
Example project to reproduce the problem with. Try to fix the indentation of line 9 in Test.java. (8.98 KB, application/zip)
2020-01-15 03:15 EST, Simeon Andreev CLA
no flags Details
Example project to reproduce the problem with. Try to fix the indentation of line 9 in Test.java. (9.72 KB, application/zip)
2020-01-15 03:20 EST, Simeon Andreev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simeon Andreev CLA 2020-01-10 04:23:39 EST
Created attachment 281437 [details]
One example of wrong indentations added by the code formatter.

I'm adjusting changes for bug 356832 and I've noticed very broken formatter behaviour. I don't know whether its a formatter problem or formatter settings problem, but I constantly have to undo the formatter changes because it keeps adding wrong indentations.

The attached video "formatter_indentations.mp4" is only one example. So far I notice it for methods that have "throws ..." in their signature, but it may be in other cases as well.
Comment 1 Simeon Andreev CLA 2020-01-10 04:42:15 EST
I think the formatter does some wrong assumptions when formatting only parts of a method in org.eclipse.jgit (e.g. some method in FS.java).

When I select the entire method and format the code with Ctrl+Shift+F, the indentations are fine. When I select only the body, the formatter adds wrong indentations.
Comment 2 Matthias Sohn CLA 2020-01-10 19:18:08 EST
Which package and version of Eclipse are you using ?
Comment 3 Simeon Andreev CLA 2020-01-11 10:00:15 EST
(In reply to Matthias Sohn from comment #2)
> Which package and version of Eclipse are you using ?

Eclipse SDK
Version: 2020-03 (4.15)
Build id: I20191228-1800
Comment 4 Simeon Andreev CLA 2020-01-13 06:43:06 EST
Another case, while I'm writing a test (with all the commits for bug 356832 and bug 552338):

/*
 * Copyright (C) 2020, Simeon Andreev <simeon.danailov.andreev@gmail.com>
 * Copyright (C) 2020, Andre Bossert <andre.bossert@siemens.com>
 * and other copyright owners as documented in the project's IP log.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.diffmergetool;

import java.io.File;

import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.Before;
import org.junit.Test;

/**
 * Testing external merge tool.
 */
public class ExternalMergeToolTest extends RepositoryTestCase {
	private MergeToolManager manager;


	@Before
	public void setup() throws Exception {
		super.setUp();
		manager = new MergeToolManager(db);
	}

	@Test
	public void testExternalToolXYZ() throws Exception {
		File localFile = writeTrashFile("localFile", " line");
		FileElement local = new FileElement(localFile.getAbsolutePath(),
				FileElement.Type.LOCAL);
				File remoteFile = writeTrashFile("remoteFile", "\tline");
		FileElement remote = new FileElement(remoteFile.getAbsolutePath(),
				FileElement.Type.REMOTE);
		File mergedFile = writeTrashFile("mergeFile", "");
		FileElement merged = new FileElement(mergedFile.getAbsolutePath(),
				FileElement.Type.MERGED);

				String mergeToolName = "kdiff3";
		ExternalMergeTool tool = manager.getTool(mergeToolName);
		manager.merge(local, remote, merged, null, null, tool);
	}
}

String mergeToolName = "kdiff3";

This gets indentations to match the line above. I think we should move this to the formatter area; it really looks like the formatter indents based on the line above.
Comment 5 Simeon Andreev CLA 2020-01-15 03:15:52 EST
Created attachment 281500 [details]
Example project to reproduce the problem with. Try to fix the indentation of line 9 in Test.java.

I can reproduce fairly easy with the .settings from JGit "org.eclipse.jgit.test". See the project in the attached "TestEclipseFormatter.zip".

Try to fix the indentation of line 9 in Test.java, observe that the formatter keeps pushing the line like this:

	public void veryLongMethodName(boolean b)
			throws IOException, IndexOutOfBoundsException {
				System.out.println("try to fix the indentation of THIS LINE"); // the indentation of this line is broken

Instead of:

	public void veryLongMethodName(boolean b)
			throws IOException, IndexOutOfBoundsException {
		System.out.println("try to fix the indentation of THIS LINE");

In the example above, manually formatting the file (Ctrl+A select all, Ctrl+Shift+F format) fixes the indentation, but formatting on saving breaks the indentation again.
Comment 6 Simeon Andreev CLA 2020-01-15 03:20:51 EST
Created attachment 281501 [details]
Example project to reproduce the problem with. Try to fix the indentation of line 9 in Test.java.
Comment 7 Andrey Loskutov CLA 2020-01-15 03:25:47 EST
@Mateusz, I've quickly checked the git history, could it be, that changes for bug 250656 (commit ba73b313fde63d8ccedec4bd1f0dfefd65dc4e33) is the reason?

Editing code in EGit / JGit is impossible with 4.15 M1.
Comment 8 Simeon Andreev CLA 2020-01-15 03:33:59 EST
(In reply to Andrey Loskutov from comment #7)
> @Mateusz, I've quickly checked the git history, could it be, that changes
> for bug 250656 (commit ba73b313fde63d8ccedec4bd1f0dfefd65dc4e33) is the
> reason?

Should be this one, yes. After I revert it, I no longer see the problem with the project in the attached "TestEclipseFormatter.zip".
Comment 9 Andrey Loskutov CLA 2020-01-15 03:41:57 EST
(In reply to Simeon Andreev from comment #8)
> (In reply to Andrey Loskutov from comment #7)
> > @Mateusz, I've quickly checked the git history, could it be, that changes
> > for bug 250656 (commit ba73b313fde63d8ccedec4bd1f0dfefd65dc4e33) is the
> > reason?
> 
> Should be this one, yes. After I revert it, I no longer see the problem with
> the project in the attached "TestEclipseFormatter.zip".

Thanks for validation!

@Mateusz: assigning to you, it would be really helpful to fix this ASAP.
Comment 10 Eclipse Genie CLA 2020-01-15 14:30:34 EST
New Gerrit change created: https://git.eclipse.org/r/155951
Comment 12 Mateusz Matela CLA 2020-01-16 04:34:10 EST
*** Bug 559128 has been marked as a duplicate of this bug. ***
Comment 13 Andrey Loskutov CLA 2020-01-16 04:39:13 EST
Verified with I20200115-1800. Thanks Mateusz for a fast fix!
Comment 14 Mateusz Matela CLA 2020-01-29 06:38:40 EST
*** Bug 559638 has been marked as a duplicate of this bug. ***