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

Bug 363071

Summary: [xtend2] illegal Java code for create-method with xtend factory method
Product: [Modeling] TMF Reporter: Hauke Fuhrmann <haf>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: unspecifiedFlags: sebastian.zarnekow: juno+
Target Milestone: M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Hauke Fuhrmann CLA 2011-11-07 12:25:27 EST
Build Identifier: 20110916-0149

Using an Xtend function as a factory method in a create-function fails with wrong Java code. The class used to call the factory method is not defined.

Xtend:

class Test {
  def create foo:bar.createTest transform(Test bar){
    foo
  }
  def createTest(Test blubb){
    new Test()
  }
}

Java:

@SuppressWarnings("all")
public class Test {
  public Test transform(final Test bar) {
    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(bar);
    final Test _result;
    synchronized (_createCache_transform) {
      if (_createCache_transform.containsKey(_cacheKey)) {
        return _createCache_transform.get(_cacheKey);
      }
      Test _Test = Test;  // <== This Test reference is unknown
      Test _createTest = _Test.createTest(bar);
      _result = _createTest;
      _createCache_transform.put(_cacheKey, _result);
    }
    _init_transform(_result, bar);
    return _result;
  }
  
  private final HashMap<ArrayList<?>,Test> _createCache_transform = CollectionLiterals.newHashMap();
  
  private void _init_transform(final Test foo, final Test bar) {
  }
  
  public Test createTest(final Test blubb) {
    Test _test = new Test();
    return _test;
  }
}


Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2011-11-07 12:27:53 EST

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