static operator_doubleArrow

31 views
Skip to first unread message

Micael Pedrosa

unread,
Jul 21, 2016, 3:06:07 PM7/21/16
to Xtend Programming Language
Is it possible to add the operator => as a static method, so I can do something like:
TestData => [
  x = 'x'
]

I'm searching for a way to add a build constructor:
  public static TestData operator_doubleArrow(final Procedure1<TestDataBuilder> block) {
 final TestDataBuilder builder = new TestDataBuilder();
 block.apply(builder);
 return new TestData(builder);
  }


Sven Efftinge (sven@efftinge.de)

unread,
Jul 21, 2016, 3:27:05 PM7/21/16
to xtend...@googlegroups.com
TestData is a class literal so the you need to define the left operand as a Class<? extends TestData>:

  public static TestData operator_doubleArrow(Class<? extends TestData> left, final Procedure1<TestDataBuilder> block) {

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Micael Pedrosa

unread,
Jul 21, 2016, 3:56:22 PM7/21/16
to Xtend Programming Language
That doesn't seems to work. It will resolve to:
<Class<TestData>> Class<TestData> ObjectExtensions.operator_doubleArrow(Class<TestData> object, Procedure1<? super Class<TestData>> block)

Micael Pedrosa

unread,
Jul 21, 2016, 4:49:26 PM7/21/16
to Xtend Programming Language
Update:
Strangely enough, it partially works.
It works if I use the operator inside the generated class.
It's not working outside, in my case in the test suits.

Sven Efftinge (sven@efftinge.de)

unread,
Jul 22, 2016, 2:01:55 AM7/22/16
to xtend...@googlegroups.com
Are you sure you have put the extension on the scope in the tests?
i.e, "import static extension ..."

--

Micael Pedrosa

unread,
Jul 22, 2016, 4:41:44 AM7/22/16
to Xtend Programming Language
Yes that works, thanks.
Reply all
Reply to author
Forward
0 new messages