Home » Modeling » TMF (Xtext) » Eclipse does not recognize dsl file after generation
Eclipse does not recognize dsl file after generation [message #1836800] |
Thu, 14 January 2021 10:08  |
Loredana Hozan Messages: 32 Registered: January 2019 |
Member |
|
|
Hello,
I have multiple dsl languages, from one language i generate another dsl file (datamodel > model) using a fileSystemAcces.generateFile(fileName, contents). The model file gets generated, however, it seems that it is not registered as a dsl file, and when i want to use it as an import in other dsl files, i can't get the reference towards the file. For the file to be recognized, i have to go to the generated file, do a edit it by adding a space and save it. Inside the code, after the generation, i have tried to load again the resource, save it, validate it, i also set the modelFile.setDerived(false) to make sure it is not blocked, but it's still not recognized as a dsl file.
Any suggestions as to what exactlly is the "space and save" doing and how can i reproduce it programmatically ?
Thank you!
|
|
| |
Re: Eclipse does not recognize dsl file after generation [message #1836810 is a reply to message #1836801] |
Thu, 14 January 2021 12:44   |
Loredana Hozan Messages: 32 Registered: January 2019 |
Member |
|
|
hi, thank you for the suggestion, to enrich my example i will add that i observed the issue because i had dependecies between the models, so datamodel B extends datamodel A , and i need to generate from both, model A, and model B, from which model B needs to extend model A. Even if the model A file is not recognized by the Xtext Builder, do you think is there a way for model B to recognize model A? And for the builder, i started by implementing the IncrementalProjectBuilder class, is the right path to follow?
|
|
| | |
Re: Eclipse does not recognize dsl file after generation [message #1838216 is a reply to message #1836817] |
Thu, 18 February 2021 16:21   |
Loredana Hozan Messages: 32 Registered: January 2019 |
Member |
|
|
Hello, i have tried the method above, with the costum builder the files get registered, the issues that i am facing with this approach are:
1. I need to generate the model files from the datamodel into the src/main/resources and datamodel are located in src/main/java/package, and when i do, since the files do not get recognized as xtext they throw an error in the datamodel, the builder gets triggered only for the files from the target and i am not able to perform the file.touch() in the actual file unless i specify the path, which for the datamodel is not possible because of the package, also the builder takes quite long, since the files which will be "touched" are large and produce a lot of java classes
2. The issue of not having the files registered as xtext occurs when i do maven update, then the maven builder calls the doGenerate(), and at maven update the maven builder will get executed lastly, hence the xtext builder will not know about the files generated by the maven builder, do you know the reason why the maven builder will go through the doGenerate and how i can stop it?
Also, i managed to have the file.touch() call inside the doGenerate() , while the file.setAsDerived() works, the touch() somehow does not work as expected (like from the builder, even though i used the same classes), and i haven't found out why.
|
|
| |
Re: Eclipse does not recognize dsl file after generation [message #1838410 is a reply to message #1838221] |
Wed, 24 February 2021 13:16   |
Loredana Hozan Messages: 32 Registered: January 2019 |
Member |
|
|
Hello, as i have tried the above parts and i am out of ideas, i'll just provide again the scenario and what i have tried in a more structured manner, maybe it will be more helpful:
>Just one DSL ( this works fine )
create new file.
build project or build automatically is set
import new file into another older DSL file of the same type. It works.
>Multiple DSLs
A->B->Java ( A generates B and B generates Java)
(A located in src/main/java , B generated in src/main/resources)
build project or build automatically is set
create new file of type A
A generates B
B generates Java
An old file of type B import/extends does not see the new B file that was generated.
Once the B type file was generated from A, it looks like its not included in the scope from which the import instruction is searching
What we already tried:
-Make the builder (using https://www.eclipse.org/forums/index.php/m/1753519/?srch=incrementalprojectbuilder+touch#msg_1753519 as example) but it read only when it was called, it was only for the files from the target and not src folders.It also takes a long time to process the fiels.
-run external maven outside of eclipse - > this works We could configure maven and run an external build that compiles ok.
-We tried to add the resource in the xtext Scope, but the import still did not saw the new file.
-in doGenerate(_) we used .touch() on the B file when it was generated, and it still does not work ( not visible in the imports ), we used the setDerived() from the same API and that works.
What are we missing to make the generated file part of the scope ? Can you please advise ?
also
setDerived() is supposed to be false for B type of file if its still used to generated another file ?
|
|
| | | |
Re: Eclipse does not recognize dsl file after generation [message #1838677 is a reply to message #1838675] |
Wed, 03 March 2021 13:21   |
|
adapting https://www.eclipse.org/forums/index.php?t=msg&th=1084225&goto=1753519&#msg_1753519 to your code works perfectly fine to me
package org.xtext.example.datamodel.ui;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
public class DummyBuilder extends IncrementalProjectBuilder {
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
IResourceDelta delta = getDelta(getProject());
if (delta != null) {
delta.accept(new IResourceDeltaVisitor() {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
if (delta.getResource() instanceof IFile) {
System.out.println(delta);
// TODO file extensiion check
if (delta.getResource().getFullPath().toString().contains("src/main/resources")) {
System.err.println(delta.getResource());
delta.getResource().touch(null);
}
}
}
return true;
}
});
}
return null;
}
}
<extension
id="DummyBuilder" name="DummyBuilder"
point="org.eclipse.core.resources.builders">
<builder >
<run
class="org.xtext.example.datamodel.ui.DummyBuilder">
</run>
</builder>
</extension>
and in the sample project
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>newProj</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.xtext.example.datamodel.ui.DummyBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Eclipse does not recognize dsl file after generation [message #1838723 is a reply to message #1838677] |
Thu, 04 March 2021 07:27   |
Loredana Hozan Messages: 32 Registered: January 2019 |
Member |
|
|
Hello, thank you for answering, i have managed to make the builder work on the bigger project, however, the issue with the builder is that it takes a lot of time for small changes, when i used to do a change in the datamodel (on the more complex grammar), without the builder, the change was reflected in the model and java files in less than 5 seconds, with the builder it takes around 2 minutes and sometimes eclipse froze, i also tried to call the touch method on the file from the doGenerate, but it does not work :(
var resourceURI = resource.URI
var modelFileName = resourceURI.toString.substring(resourceURI.toString.lastIndexOf('/')+1).replace("datamodel","model");
var projectName = resource.URI.segment(1);
var project = ResourcesPlugin.workspace.root.getProject(projectName);
var modelFile = project.getFolder("src/main/resources").getFile(modelFileName)
print(modelFile.name);
modelFile.setDerived(false, null);
modelFile.touch(null)
[Updated on: Thu, 04 March 2021 07:33] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Tue Jun 06 17:44:01 GMT 2023
Powered by FUDForum. Page generated in 0.04855 seconds
|