Embedding DSL in Java / Creating Xtext model based on Java [message #1385445] |
Fri, 06 June 2014 13:30 |
Martin Pain 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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01884 seconds