Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 402819 - [1.8][formatter] No effect with formatting when cast operator contains intersection of types.
Summary: [1.8][formatter] No effect with formatting when cast operator contains inters...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Jesper Moller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 400830
  Show dependency tree
 
Reported: 2013-03-09 14:28 EST by Srikanth Sankaran CLA
Modified: 2013-03-20 23:53 EDT (History)
0 users

See Also:


Attachments
Test and patch for this (6.78 KB, patch)
2013-03-20 20:22 EDT, Jesper Moller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2013-03-09 14:28:13 EST
BETA_JAVA8:

The following program fails to get formatted properly. If you change
the intersection type cast to a normal cast, all is well:

// ----
import java.io.Serializable;
interface I {
	void doit();
}
class X {
	void foo(   int x   ,     int   y ) {}
	I i = (I       &       Serializable   ) () -> {};
}
Comment 1 Srikanth Sankaran CLA 2013-03-09 14:28:42 EST
Jesper, Thanks for following up.
Comment 2 Jesper Moller CLA 2013-03-20 20:22:09 EDT
Created attachment 228752 [details]
Test and patch for this

Note that I don't really like to continue the pattern of inserting 2 lexically identical method implementations for BlockScope and MethodScope, but I guess that's a case for a different bug.
Since the scopes are going to be null for formatting anyway, we could just delegate to one from the other, couldn't we?
Comment 3 Srikanth Sankaran CLA 2013-03-20 23:53:23 EDT
(In reply to comment #2)
> Created attachment 228752 [details]
> Test and patch for this
> 
> Note that I don't really like to continue the pattern of inserting 2
> lexically identical method implementations for BlockScope and MethodScope,
> but I guess that's a case for a different bug.

I think you meant BlockScope and ClassScope. I got rid of the latter format visit
method for IntersectionCastTypeReference since it will never be entered.
IntersectionTypeReference can only in a occur in a cast and a cast can
only occur in a MethodScope (which is a BlockScope). See that CastExpression
defines a single traverse method that traverses only in BlockScope.

(we create MethodScopes for field initialization, static blocks and initializer
blocks)

(I also replaced the implementation of ClassScope travese method in IntersectionCastTypeReference with a throw of UOE.)

(In future, please also throw in a few 308 style annotations here and
there in formatter tests - it doesn't hurt to test them in various contexts)

Patch is good. Fix and tests released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=79363a0cf2877d51c36b4085a9d2b719b103bf6c

Thanks Jesper.