Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 479291

Summary: [formatter] Code formatter adds extra whitespace with nested annotations
Product: [Eclipse Project] JDT Reporter: Phillip Webb <pwebb>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: mateusz.matela
Version: 4.5.1   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Phillip Webb CLA 2015-10-07 19:25:22 EDT
Given the code annotated as follows:


	@ComponentScan(excludeFilters=@ComponentScan.Filter(classes={Session.class}, type=FilterType.ASSIGNABLE_TYPE))


The code formatter in Mars will add an additional whitespace character between the two closing brackets:

	@ComponentScan(excludeFilters = @ComponentScan.Filter(classes = {
			Session.class }, type = FilterType.ASSIGNABLE_TYPE) )

This unfortunately means that it is impossible to use auto-formatted code in combination with checkstyles `MethodParamPad` rule.
Comment 1 Phillip Webb CLA 2015-10-07 19:33:14 EDT
That should read checkstyles `ParenPad` rule
Comment 2 Phillip Webb CLA 2015-10-08 18:29:03 EDT
I think changing the `handleAnnotation` method of `SpacePreparator` might fix the problem.

The lines:

		ASTNode parent = node.getParent();
		if (!(parent instanceof Annotation) && !(parent instanceof ArrayInitializer))
			this.tm.lastTokenIn(node, -1).spaceAfter();


To:

		ASTNode parent = node.getParent();
		if (!(parent instanceof Annotation) && !(parent instanceof MemberValuePair) && !(parent instanceof ArrayInitializer))
			this.tm.lastTokenIn(node, -1).spaceAfter();

I'd be happy to submit a pull request unfortunately I can't work out how to build jdt from source. I tried following https://wiki.eclipse.org/JDT_UI/How_to_Contribute but the Maven build fails due to a missing parent POM. I can't work out what I'm supposed to checkout to fix that.
Comment 3 Mateusz Matela CLA 2015-10-09 16:44:58 EDT
(In reply to Phillip Webb from comment #2)
> I'd be happy to submit a pull request unfortunately I can't work out how to
> build jdt from source. I tried following
> https://wiki.eclipse.org/JDT_UI/How_to_Contribute but the Maven build fails
> due to a missing parent POM. I can't work out what I'm supposed to checkout
> to fix that.

Just fixed an older bug that included this problem, but I appreciate the thought.

When I was starting with the formatter, I followed https://wiki.eclipse.org/JDT_Core_Committer_FAQ and there were no problems with Maven. Hope this helps.

*** This bug has been marked as a duplicate of bug 471203 ***