Java to Xtend converter?

1,007 views
Skip to first unread message

Krzysztof Rzymkowski

unread,
May 8, 2013, 4:26:47 AM5/8/13
to xtend...@googlegroups.com
Hi

It there any tool that aids converting pure Java source code to Xtend?
I'm thinking about writing one myself using eclipse's ASTParser, but maybe there's no need.

Cheers
Rzymek

Sven Efftinge

unread,
May 8, 2013, 4:31:14 AM5/8/13
to xtend...@googlegroups.com
That idea has come up a couple of times.
If you start building something like that it would be very cool if you could make that open-source :-)

--
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/groups/opt_out.
 
 

Krzysztof Rzymkowski

unread,
May 8, 2013, 12:19:30 PM5/8/13
to xtend...@googlegroups.com
Ok, so no existing project.

Of course I'll do it open-source. I've already started:
https://github.com/rzymek/java2xtend

I would like not to bother with formatting. Could I call the existing xtend formatter passing only a String containing xtend source code?

Ben Ritchie

unread,
May 9, 2013, 12:10:18 PM5/9/13
to xtend...@googlegroups.com
good man!

Krzysztof Rzymkowski

unread,
May 9, 2013, 12:36:34 PM5/9/13
to xtend...@googlegroups.com

W

> --
> You received this message because you are subscribed to a topic in the Google Groups "Xtend Programming Language" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/xtend-lang/6BRrZRVkq6s/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to xtend-lang+...@googlegroups.com.

Krzysztof Rzymkowski

unread,
May 9, 2013, 4:13:41 PM5/9/13
to xtend...@googlegroups.com
Sorry about that last empty message (forgot to lock my phone before putting it in my pocket)

Also forget about the question about the formatter for now. I've tried a different approach.
Instead of generating xtend sources from the java AST tree, I'm now modifing the java AST tree nodes to make them compatible with xtend.
We'll see how far I can go with this approach, but at least I have the guarantee that I'll not lose any code.
For now I've been able to generate:

package com.example;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Test implements Serializable {
  static val serialVersionUID=1L;
  List<String> list=null;
  var otherList=new ArrayList<String>();
  new(  List<String> list){
    this.list=list;
  }
  def foo(){
    var x="abc";
    var list=Arrays.asList(1,2,3,4,5);
    int i;
    for (    Integer integer : list) {
      println(integer);
    }
  }
  def toString(){
    return "the test";
  }
} 

From  this:

package com.example;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> list = null;
private List<String> otherList = new ArrayList<String>();

public Test(List<String> list) {
this.list = list;
}

public void foo() {
String x = "abc";
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
int i;
for (Integer integer : list) {
System.out.println(integer);
}
}

public String toString() {
return "the test";
}
}

Krzysztof Rzymkowski

unread,
May 15, 2013, 6:06:12 PM5/15/13
to xtend...@googlegroups.com
I've setup an online Java to Xtend converter at http://www.j2x.cloudbees.net/
It's still in early stages but the results are already useful.

Please submit convertion issues at https://github.com/rzymek/java2xtend/issues
Problems with the webapp itself here: https://github.com/rzymek/java2xtend.webapp/issues

Sven Efftinge

unread,
May 16, 2013, 2:26:22 AM5/16/13
to xtend...@googlegroups.com
nice!

--
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.

Moritz Eysholdt

unread,
May 16, 2013, 12:40:02 PM5/16/13
to xtend...@googlegroups.com
hi Krzysztof,


On May 8, 2013, at 9:19 AM, Krzysztof Rzymkowski <rzy...@gmail.com> wrote:

> I would like not to bother with formatting. Could I call the existing xtend formatter passing only a String containing xtend source code?


yes, you can do so. You'd need to parse the string using the Xtend parser to obtain the EMF-AST. You can then pass this to the formatter implementation which will create a list of TextEdits for you (a TextEdit describes an range via offset and length and a replacement string for it). Applying these TextEdits to the string will produce a formatted version of the Xtend code.

regards,
Moritz

Jan Köhnlein

unread,
May 20, 2013, 5:02:20 PM5/20/13
to xtend...@googlegroups.com
Hi Krzysztof

I successfully used your converter and blogged about it:
http://koehnlein.blogspot.de/2013/05/another-xtend-and-javafx-story.html

Thanks a lot
Jan
> --
> 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/groups/opt_out.
>
>

--
Dr. Jan Köhnlein
Senior Software Architekt

Mobile: +49 (0) 151 / 17396687
Telefon: +49 (0) 431 / 99026870
Fax: +49 (0) 431 / 99026872

http://www.itemis.de
jan.ko...@itemis.de
https://www.xing.com/profile/Jan_Koehnlein

itemis AG
Niederlassung Kiel
Am Germaniahafen 1
24143 Kiel
http://www.itemis.de/

Rechtlicher Hinweis:

Amtsgericht Dortmund, HRB 20621

Vorstand: Jens Wagener (Vors.), Wolfgang Neuhaus, Dr. Georg Pietrek, Jens Trompeter, Sebastian Neus

Aufsichtsrat: Dr. Burkhard Igel (Vors.), Stephan Grollmann, Michael Neuhaus

Krzysztof Rzymkowski

unread,
May 21, 2013, 4:16:18 PM5/21/13
to xtend...@googlegroups.com
Thank you very much for these kind words.
And thank you all for tweeting and sharing.

Now, back in the subject: 
1) @Moritz Eysholdt: Could you point me to the class names of Xtend parser and formatter?

2) What is the complete list of automatically imported extension methods (like CollectionLiterals.*)? 

Cheers 
Rzymek

Moritz Eysholdt

unread,
May 21, 2013, 4:37:24 PM5/21/13
to xtend...@googlegroups.com
Hi Krzysztof,

On May 21, 2013, at 1:16 PM, Krzysztof Rzymkowski <rzy...@gmail.com> wrote:

> Now, back in the subject:
> 1) @Moritz Eysholdt: Could you point me to the class names of Xtend parser and formatter?

To parse an Xtend file you best use the EMF resource API:

val resource = resourceSet.getResource(URI.createURI("myfile.xtend"))

The formatter implementation is here:
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/formatting/XtendFormatter.xtend

regards,
Moritz

Sven Efftinge

unread,
May 22, 2013, 2:40:25 AM5/22/13
to xtend...@googlegroups.com

2) What is the complete list of automatically imported extension methods (like CollectionLiterals.*)? 

The implicitly imported static methods are located in the following classes:
ArrayLiterals.class,
CollectionLiterals.class,
InputOutput.class

Extension methods for classes from the JDK are coming from 
ArrayExtensions.class,
BigDecimalExtensions.class,
BigIntegerExtensions.class,
BooleanExtensions.class,
ByteExtensions.class,
CharacterExtensions.class,
CollectionExtensions.class,
ComparableExtensions.class,
DoubleExtensions.class,
FloatExtensions.class,
FunctionExtensions.class,
IntegerExtensions.class,
IterableExtensions.class,
IteratorExtensions.class,
ListExtensions.class,
LongExtensions.class,
MapExtensions.class,
ObjectExtensions.class,
ProcedureExtensions.class,
ShortExtensions.class,
StringExtensions.class

Jan Köhnlein

unread,
May 22, 2013, 2:48:49 AM5/22/13
to xtend...@googlegroups.com
Hi Krzysztof,

the implicit imports are defined in org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedTypes

Regards
Jan

madhuna...@gmail.com

unread,
Aug 25, 2015, 5:57:06 AM8/25/15
to Xtend Programming Language
Hi,

The online converter url http://www.j2x.cloudbees.net/ is not up. Please let me know if this has been removed or if the url is changed.

Thanks

Vlad Dumitrescu

unread,
Aug 25, 2015, 5:59:50 AM8/25/15
to xtend...@googlegroups.com
Hi!

You do know that nowadays you can convert java files to Xtend in Eclipse? Right-click on file in the explorer and choose "Convert to Xtend".

regards,
Vlad


--
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.

Dennis Hübner

unread,
Aug 25, 2015, 6:05:37 AM8/25/15
to Xtend Programming Language
You can also paste Java code snippets in Xtend Editor when holding 'shift' during paste.

In Xtend >= 2.9 "Paste Java Code" action is also in editor's context menu.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+unsubscribe@googlegroups.com.

atao

unread,
Aug 26, 2015, 3:36:02 AM8/26/15
to Xtend Programming Language, madhuna...@gmail.com
The online converter  http://www.j2x.cloudbees.net/ is not working anymore. It is bound to the  Krzysztof Rzymkowski project https://github.com/rzymek/java2xtend.webapp. This project is no more maintened as since version 2.8 Xtend embeds its own java to xtend converter.

However you can find a working online converter here http://j2xconverter-atao60.rhcloud.com/. It's bound to the project https://github.com/atao60/java2xtend whose purpose is to work with the Xtend converter outside any Eclipse context. In fact it just hides details of the Eclipse "plumbing".

Regards
Reply all
Reply to author
Forward
0 new messages