Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363299 - [Xtend2] problem with type inference
Summary: [Xtend2] problem with type inference
Status: CLOSED WONTFIX
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 07:57 EST by Lieven Lemiengre CLA
Modified: 2011-11-09 08:03 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lieven Lemiengre CLA 2011-11-09 07:57:00 EST
problem:

class SomeSemanticHighlightingCalculator implements ISemanticHighlightingCalculator {
	
  override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
    if(resource == null) return;
    val Iterator<EObject> iter = EcoreUtil2::getAllContents(resource, true)
    while(iter.hasNext) {
      highlight(iter.next, acceptor)
    }
  }
}

I have to explicitly type iter as 'Iterator<EObject>' otherwise the type 'Iterator<?>' is inferred.
Comment 1 Sebastian Zarnekow CLA 2011-11-09 08:02:05 EST
This works as expected.

The signature of EcoreUtil.getAllContents looks like this:

<T> TreeIterator<T> getAllContents(Resource, boolean)

thus you'd have to use

Iterator<EObject> iter = EcoreUtil.<EObject>getAllContents(..) 

in Java where Xtend allows to use

val iter = EcoreUtil::<EObject>getAllContents(..)

or

val Iterator<EObject> iter = EcoreUtil::getAllContents(..)
Comment 2 Sebastian Zarnekow CLA 2011-11-09 08:03:49 EST
(In reply to comment #1)
> you'd have to use
> 
> Iterator<EObject> iter = EcoreUtil.<EObject>getAllContents(..) 
> 
> in Java 

That was too fast. Java has inference for the type argument, too. E.g. the following is valid in Java and in Xtend:

Iterator<EObject> iter = EcoreUtil.getAllContents(..)