Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Embedding DSL in Java / Creating Xtext model based on Java
Embedding DSL in Java / Creating Xtext model based on Java [message #1385445] Fri, 06 June 2014 13:30 Go to next message
Martin Pain is currently offline Martin PainFriend
Messages: 3
Registered: March 2013
Junior Member
Rather than trying to create a DSL from scratch that can be compiled to Java source, I'm looking to create a DSL that can be embedded in Java source code.

For example, be able to use the full features of Java in my source files, but then add in extra custom keywords (my "DSL"):

public class MyBean {
    public int id;
    public String name;

    generate-hash-code-and-equals(all fields);
}


The important points to me are as follows:

1. The entire syntax of and tooling for Java is available, including standard re-factoring and auto-complete, etc.
2. The implementation of those custom key words (e.g. generate-hash-code-and-equals in example above) can be in plain Java, rather than Xtend (I need regular Java developers to be able to look at them to check what they're doing), and in the source of the project, not in the definition of the DSL. This also needs to have the regular Java error checking & code completion.
3. Ctrl+Click on the keyword in Eclipse takes users to the implementation of them (that should work fine in an Xtext editor by the sound of it).
4. Something equivalent to the "inline method call" refactoring step available on Eclipse should be available to run the code generation in the Eclipse IDE and replace the instance of the keyword, for cases where we need to tweak or customise it for a single class.

As an example of point 2, this could be the definition for the code example above (in a sibling file to that example):

keyword generate-hash-code-and-equals(ClassBuilder builder, FieldSelection arg) {
   MethodBuilder equals = builder.addMethod("equals", Boolean.class);
   MethodBuilder hashCode = builder.addMethod("hashCode", Boolean.class);
   /* Use whatever interface to generate the code based on the fields in the class */
]


Is there a different tool that would be better suited for that?
Can that be done with Xtext & Xtend? (Does XBase include a model that contains all and only the Java syntax? And can that be augmented?)

I've had a quick Google, but couldn't find anything.

Thanks in advance

(EDIT: Yes, I basically want a preprocessor/macros for Java, but a solution with full IDE support including code completion, static type checking & automated refactoring.)

[Updated on: Fri, 06 June 2014 14:09]

Report message to a moderator

Re: Embedding DSL in Java / Creating Xtext model based on Java [message #1385454 is a reply to message #1385445] Fri, 06 June 2014 14:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
Hi what about using xtend with active annotations instead of java?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Embedding DSL in Java / Creating Xtext model based on Java [message #1385455 is a reply to message #1385445] Fri, 06 June 2014 14:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
P.s. besides this xtext is not very good with embedding. Maybe using
Jetbrains MPS fits better for that usecase ( if you can live with
projectional editors )


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Embedding DSL in Java / Creating Xtext model based on Java [message #1385459 is a reply to message #1385455] Fri, 06 June 2014 14:59 Go to previous messageGo to next message
Martin Pain is currently offline Martin PainFriend
Messages: 3
Registered: March 2013
Junior Member
Active Annotations looks like it's heading in the right direction, but doesn't look like it supports #2 or #4 in my list. I might give it a try though.
Unfortunately with Jetbrains MPS having to have a different program to edit the files would be just as large an obstacle for the people maintaining it as having to learn Xtend.

Thanks for the pointers, I wasn't aware of either of them before Smile
Re: Embedding DSL in Java / Creating Xtext model based on Java [message #1385469 is a reply to message #1385459] Fri, 06 June 2014 15:46 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13313
Registered: July 2009
Senior Member
everything is possible. it is just a matter of time.
so if you need that with java you have to do everthing yourself which will never ever pay out http://xkcd.com/1205/


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Xbase] How to append left operand of XAssignment to XMemberFeatureCall
Next Topic:Access to Java Fields at DSL
Goto Forum:
  


Current Time: Tue Jan 21 23:41:39 GMT 2020

Powered by FUDForum. Page generated in 0.02012 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top