generator denies to run [message #1832370] |
Thu, 17 September 2020 08:36 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Hi
i have installed the newest xtext 2.23.0 from a bundle provided which includes also the java se 11.0. I tried to execute a simple hello world with success. My next step is to create a button in the index.html. On button click event i want to call the generator which will only log out a hello world to the console.log of the running server.
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="en-us">
<title>Example Web Editor</title>
<link rel="stylesheet" type="text/css" href="xtext/2.23.0/xtext-ace.css"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script src="webjars/requirejs/2.3.6/require.min.js"></script>
<script type="text/javascript">
var baseUrl = window.location.pathname;
var fileIndex = baseUrl.indexOf("index.html");
if (fileIndex > 0)
baseUrl = baseUrl.slice(0, fileIndex);
require.config({
baseUrl: baseUrl,
paths: {
"jquery": "webjars/jquery/3.4.1/jquery.min",
"ace/ext/language_tools": "webjars/ace/1.3.3/src/ext-language_tools",
"xtext/xtext-ace": "xtext/2.23.0/xtext-ace"
}
});
require(["webjars/ace/1.3.3/src/ace"], function() {
require(["xtext/xtext-ace"], function(xtext) {
xtext.createEditor({
baseUrl: baseUrl,
syntaxDefinition: "xtext-resources/generated/mode-mydsl"
});
$("#generate-button").click(function() {
//do smothing
alert("clicked ")
//editor.xtextServices.enableGeneratorService();
//editor.xtextServices.saveResource();
//var gen = editor.xtextServices.generate();
editor.xtextServices.generate();
});
});
});
</script>
</head>
<body>
<div ><button id='generate-button'>generate button </button></div>
<div class="container">
<div class="header">
<h1>Example MyDsl Web Editor</h1>
</div>
<div class="content">
<div id="xtext-editor" data-editor-xtext-lang="mydsl"></div>
</div>
</div>
</body>
</html>
MyDslGenerator.xtend
/*
* generated by Xtext 2.23.0
*/
package org.xtext.example.mydsl.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.xtext.example.mydsl.myDsl.Greeting
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class MyDslGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
fsa.generateFile('greetings.txt', 'People to greet: ' +
resource.allContents
.filter(Greeting)
.map[name]
.join(', '));
println("this is the generator.xtend");
var JsonGenerator jg = new JsonGenerator();
jg.generateJson()
}
}
JsonGenerator.java
package org.xtext.example.mydsl.generator;
public class JsonGenerator {
public void generateJson() {
System.out.println("Starting genetator");
throw new UnsupportedOperationException("TODO: auto-generated method stub");
}
}
I don't now there is something missing in this call process. The problem is that i don't see if the methods are executed or the problem comes to the console . Is there any other connection point missing ?
Best Regards
[Updated on: Thu, 20 May 2021 15:01] Report message to a moderator
|
|
|
|
Re: generator denies to run [message #1832379 is a reply to message #1832371] |
Thu, 17 September 2020 10:20 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Hi Christian,
thanks for your quick answer.
I have made these changes as you suggested
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="en-us">
<title>Example Web Editor</title>
<link rel="stylesheet" type="text/css" href="xtext/2.23.0/xtext-ace.css"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script src="webjars/requirejs/2.3.6/require.min.js"></script>
<script type="text/javascript">
var editor;
var baseUrl = window.location.pathname;
var fileIndex = baseUrl.indexOf("index.html");
if (fileIndex > 0)
baseUrl = baseUrl.slice(0, fileIndex);
require.config({
baseUrl: baseUrl,
paths: {
"jquery": "webjars/jquery/3.4.1/jquery.min",
"ace/ext/language_tools": "webjars/ace/1.3.3/src/ext-language_tools",
"xtext/xtext-ace": "xtext/2.23.0/xtext-ace"
}
});
require(["webjars/ace/1.3.3/src/ace"], function() {
require(["xtext/xtext-ace"], function(xtext) {
editor=xtext.createEditor({
baseUrl: baseUrl,
syntaxDefinition: "xtext-resources/generated/mode-mydsl"
});
jQuery('#generate-button').bind("click", function(e){
jQuery('#generator-result').html('<iframe style="width:1000px; height:200px;" src="http://' + location.host + '/xtext-service/generate?resource=example1.mydsl2"></iframe>');
alert(location.host + '/xtext-service/generate?resource')
e.preventDefault();
});
});
});
</script>
</head>
<body>
<div class="container">
<div class="header">
<h1>Example MyDsl Web Editor</h1>
</div>
<div class="content">
<div id="xtext-editor" data-editor-xtext-lang="mydsl" data-editor-resource-id="example1.mydsl2"></div>
</div>
<div class="button-wrapper">
<button id="generate-button" value="Generate" title="Generate">Generate</button>
<div id="generator-result">
Result
</div>
</div>
</div>
</body>
</html>
MyDslGenerator.xtend
/*
* generated by Xtext 2.23.0
*/
package org.xtext.example.mydsl.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.xtext.example.mydsl.myDsl.Greeting
/**
* Generates code from your model files on save.
*
* See [url]https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation[/url]
*/
class MyDslGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
fsa.generateFile('/DEFAULT_ARTIFACT', 'People to greet: ' +
resource.allContents
.filter(typeof(Greeting))
.map[name]
.join(', '))
println("this is the generator.xtend");
}
}
style.css
div.button-wrapper {
display: block;
position: absolute;
top: 90px;
bottom: 0;
left: 640px;
right: 0;
padding: 4px;
border: 1px solid #aaa;
}
Now i get this message inside the Iframe.
HTTP ERROR 400 Unable to identify the Xtext language for resource example1.mydsl2. URI: /xtext-service/generate STATUS: 400 MESSAGE: Unable to identify the Xtext language for resource example1.mydsl2. SERVLET: XtextServices Powered by Jetty:// 9.4.22.v20191022
Also in the console of the browser appears an error message
jquery.min.js:2
GET http://localhost:8082/xtext-service/generate?resource=example1.mydsl2 400 (Bad Request)
Failed to load resource: the server responded with a status of 400 (Bad Request)
The resource extension should be similar to the language being used in my dsl example ? In my case the xtext file is "MyDsl.xtext" . Also i can't get it work to display the message "this is the generator.xtend" in the console log of the sever.
Best regards
[Updated on: Thu, 20 May 2021 15:00] Report message to a moderator
|
|
|
|
Re: generator denies to run [message #1832383 is a reply to message #1832381] |
Thu, 17 September 2020 10:38 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Sorry but i am a little bit confused .
Christian you mean that in my case the resource should have at list the extension "xtext" (because of my dsl language named "MyDsl.xtext")
If i get it right, the name can be anything because of a file creation (for example resource name with extension can be " myresource.xtext").
If this is the case ,then the generated file should be created in the same folder, where the generator is laying also. Correct ?
Best Regards
[Updated on: Thu, 20 May 2021 15:00] Report message to a moderator
|
|
|
|
Re: generator denies to run [message #1832385 is a reply to message #1832384] |
Thu, 17 September 2020 10:42 |
|
and no the file name is the name the server knows the client side file under
<div id="xtext-editor" data-editor-xtext-lang="mydsl2" data-editor-resource-id="example1.mydsl2"></div>
vs
jQuery('#generator-result').html('<iframe src="http://' + location.host + '/xtext-service/generate?resource=example1.mydsl2"></iframe>');
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03526 seconds