How to add custom import statements in the generated java file in xtext using jvmmodelInferrer?How to add multiple outlets for generated XText DSLDisable “Add Xtext nature” dialog in EclipseIs there a java grammar file for Xtext?Xtext multiple generatorsAlways add a specific 'import static extension' to an XText DSLGenerate DSL file with XText from Java modelHow to split Xtext grammar file into multiple ones?Validate xtext editor content which is generated by Grammar fileValidation error if Import is not present in xtextHow to generate a parser generator using Xtext?

"Literally" Vs "In the true sense of the word"

Is there a real-world mythological counterpart to WoW's "kill your gods for power" theme?

How to stabilise the bicycle seatpost and saddle when it is all the way up?

Why don't Wizards use wrist straps to protect against disarming charms?

What hard drive connector is this?

I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?

Why is my fire extinguisher emptied after one use?

Should you only use colons and periods in dialogues?

Why is template constructor preferred to copy constructor?

Are space camera sensors usually round, or square?

Why do sellers care about down payments?

How to publish superseding results without creating enemies

Do ibuprofen or paracetamol cause hearing loss?

How are aircraft depainted?

Bash, import output from command as command

Make 2019 with single digits

Why did they ever make smaller than full-frame sensors?

Some Prime Peerage

Can I tap all my opponent's lands while they're casting a spell to negate it?

What are uses of the byte after BRK instruction on 6502?

Why is the T-1000 humanoid?

why car dealer is insisting on loan v/s cash

Real mode flat model

Is the Dodge action perceptible to other characters?



How to add custom import statements in the generated java file in xtext using jvmmodelInferrer?


How to add multiple outlets for generated XText DSLDisable “Add Xtext nature” dialog in EclipseIs there a java grammar file for Xtext?Xtext multiple generatorsAlways add a specific 'import static extension' to an XText DSLGenerate DSL file with XText from Java modelHow to split Xtext grammar file into multiple ones?Validate xtext editor content which is generated by Grammar fileValidation error if Import is not present in xtextHow to generate a parser generator using Xtext?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have written a grammar for my domain specific language in xtext and I am using jvmmodelInferrer to generate java code. I can generate fields and custom methods but how can I add custom import statements like 'import java.util.*' in the generated java file without the user having to explicitly write the import statement?










share|improve this question
























  • there should be no need for that. can you give more context about what you do in the inferrer

    – Christian Dietrich
    Mar 28 at 17:34











  • I have to execute SQL queries. So I have generated code for execution of SQL queries but I need to generate an import statement 'import java.sql.*'. So how can i generate the import statement?

    – Kartik Raut
    Mar 28 at 18:06

















1















I have written a grammar for my domain specific language in xtext and I am using jvmmodelInferrer to generate java code. I can generate fields and custom methods but how can I add custom import statements like 'import java.util.*' in the generated java file without the user having to explicitly write the import statement?










share|improve this question
























  • there should be no need for that. can you give more context about what you do in the inferrer

    – Christian Dietrich
    Mar 28 at 17:34











  • I have to execute SQL queries. So I have generated code for execution of SQL queries but I need to generate an import statement 'import java.sql.*'. So how can i generate the import statement?

    – Kartik Raut
    Mar 28 at 18:06













1












1








1








I have written a grammar for my domain specific language in xtext and I am using jvmmodelInferrer to generate java code. I can generate fields and custom methods but how can I add custom import statements like 'import java.util.*' in the generated java file without the user having to explicitly write the import statement?










share|improve this question














I have written a grammar for my domain specific language in xtext and I am using jvmmodelInferrer to generate java code. I can generate fields and custom methods but how can I add custom import statements like 'import java.util.*' in the generated java file without the user having to explicitly write the import statement?







dsl xtext xtend xbase






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 10:25









Kartik RautKartik Raut

61 bronze badge




61 bronze badge















  • there should be no need for that. can you give more context about what you do in the inferrer

    – Christian Dietrich
    Mar 28 at 17:34











  • I have to execute SQL queries. So I have generated code for execution of SQL queries but I need to generate an import statement 'import java.sql.*'. So how can i generate the import statement?

    – Kartik Raut
    Mar 28 at 18:06

















  • there should be no need for that. can you give more context about what you do in the inferrer

    – Christian Dietrich
    Mar 28 at 17:34











  • I have to execute SQL queries. So I have generated code for execution of SQL queries but I need to generate an import statement 'import java.sql.*'. So how can i generate the import statement?

    – Kartik Raut
    Mar 28 at 18:06
















there should be no need for that. can you give more context about what you do in the inferrer

– Christian Dietrich
Mar 28 at 17:34





there should be no need for that. can you give more context about what you do in the inferrer

– Christian Dietrich
Mar 28 at 17:34













I have to execute SQL queries. So I have generated code for execution of SQL queries but I need to generate an import statement 'import java.sql.*'. So how can i generate the import statement?

– Kartik Raut
Mar 28 at 18:06





I have to execute SQL queries. So I have generated code for execution of SQL queries but I need to generate an import statement 'import java.sql.*'. So how can i generate the import statement?

– Kartik Raut
Mar 28 at 18:06












1 Answer
1






active

oldest

votes


















3
















you dont generate import strings. you just use rich strings in a proper way and everything happens automatically



def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) 
for (greeting : element.greetings)
acceptor.accept(greeting.toClass("demo." + greeting.name)) [
members += greeting.toMethod("demo", Void.TYPE.typeRef) [
body = '''
«JFrame» f = null;
«"java.util.List".typeRef("java.lang.String".typeRef)» l = null;
return;
'''
]
]







share|improve this answer

























  • Thanks, I never thought of it.

    – Kartik Raut
    Mar 28 at 18:51










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395272%2fhow-to-add-custom-import-statements-in-the-generated-java-file-in-xtext-using-jv%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3
















you dont generate import strings. you just use rich strings in a proper way and everything happens automatically



def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) 
for (greeting : element.greetings)
acceptor.accept(greeting.toClass("demo." + greeting.name)) [
members += greeting.toMethod("demo", Void.TYPE.typeRef) [
body = '''
«JFrame» f = null;
«"java.util.List".typeRef("java.lang.String".typeRef)» l = null;
return;
'''
]
]







share|improve this answer

























  • Thanks, I never thought of it.

    – Kartik Raut
    Mar 28 at 18:51















3
















you dont generate import strings. you just use rich strings in a proper way and everything happens automatically



def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) 
for (greeting : element.greetings)
acceptor.accept(greeting.toClass("demo." + greeting.name)) [
members += greeting.toMethod("demo", Void.TYPE.typeRef) [
body = '''
«JFrame» f = null;
«"java.util.List".typeRef("java.lang.String".typeRef)» l = null;
return;
'''
]
]







share|improve this answer

























  • Thanks, I never thought of it.

    – Kartik Raut
    Mar 28 at 18:51













3














3










3









you dont generate import strings. you just use rich strings in a proper way and everything happens automatically



def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) 
for (greeting : element.greetings)
acceptor.accept(greeting.toClass("demo." + greeting.name)) [
members += greeting.toMethod("demo", Void.TYPE.typeRef) [
body = '''
«JFrame» f = null;
«"java.util.List".typeRef("java.lang.String".typeRef)» l = null;
return;
'''
]
]







share|improve this answer













you dont generate import strings. you just use rich strings in a proper way and everything happens automatically



def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) 
for (greeting : element.greetings)
acceptor.accept(greeting.toClass("demo." + greeting.name)) [
members += greeting.toMethod("demo", Void.TYPE.typeRef) [
body = '''
«JFrame» f = null;
«"java.util.List".typeRef("java.lang.String".typeRef)» l = null;
return;
'''
]
]








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 18:31









Christian DietrichChristian Dietrich

8,9694 gold badges18 silver badges29 bronze badges




8,9694 gold badges18 silver badges29 bronze badges















  • Thanks, I never thought of it.

    – Kartik Raut
    Mar 28 at 18:51

















  • Thanks, I never thought of it.

    – Kartik Raut
    Mar 28 at 18:51
















Thanks, I never thought of it.

– Kartik Raut
Mar 28 at 18:51





Thanks, I never thought of it.

– Kartik Raut
Mar 28 at 18:51








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395272%2fhow-to-add-custom-import-statements-in-the-generated-java-file-in-xtext-using-jv%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?