Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [recommenders-dev] [snipmatch] headless API for generating code snippets?

Hi Marcel,
 
I’ve managed to figure out how this could be done 😊 (I hope it’s a correct way).
Using the SnipDSLFactory, we can create objects from the ecore model. For example, the following snippet would create a new attribute declaration:
 

SnipDSLFactory factory=SnipDSLFactory.eINSTANCE;

attributeDeclaration var=factory.createattributeDeclaration();

var.setName("myAttr");

jFaceDeclarationType type= factory.createjFaceDeclarationType();

type.setType("${array_type}");

var.setJfaceType(type);

System.out.println(var.getVisible().getLiteral()+" "+var.getJfaceType().getType()+" "+var.getName());

 

The output would look like this:

protected ${array_type} myAttr

This is just a simple example. More complex things can be easily done using these Factories.
And I don’t think it is too hard to build an API over this.
This is something similar to what you described before, right? Correct me if I am wrong.
 
 
Best Regards,
Stefan.
 
From: Marcel Bruch
Sent: ‎Friday‎, ‎August‎ ‎30‎, ‎2013 ‎5‎:‎32‎ ‎PM
To: Recommenders developer discussions
 
Hi,

I spent some time on creating a string based interface here. The interesting parts are those that are yet commented out (e.g., appendMethodCall) but I think you see where this is going. There is no such concept like a "variable" or "type" in the string based template API. In the long run I'd also like to create more complex snippets with it containing e.g. for loops, if statements etc.

If we would get your "runtime" api to this level (not during this gsoc) this would be brilliant. What I'm thinking about, basically, is an API to build Java ASTs with JFace language constructs.

HTH to understand even better what I'm currently thinking of. Stop me if this is non-sense. Andreas? Fabian?

Best,
Marcel

[1] https://git.eclipse.org/r/#/c/16003/1/plugins/org.eclipse.recommenders.calls.rcp/src/org/eclipse/recommenders/internal/calls/rcp/templates/TemplateBuilder.java

On Aug 30, 2013, at 1:41 PM, stefan.prisca@xxxxxxxxx wrote:

I understand, thanks for the explanation. It’s an interesting idea. It should be possible, but at the moment I don’t know how. Fabian, what do you think about this? 


Back to the top