Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior 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 #1836801 is a reply to message #1836800] Thu, 14 January 2021 10:12 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
this is a feature of eclipse: a builder wont get notified about files it creates itself. if you want to generate modelb files from modela files then you need
to provide another builder that touches the files the modelagenerator creates
then Xtext will be called for modelb files again


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 #1836810 is a reply to message #1836801] Thu, 14 January 2021 12:44 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior 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 #1836815 is a reply to message #1836810] Thu, 14 January 2021 13:13 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
https://www.eclipse.org/forums/index.php/m/1753519/?srch=incrementalprojectbuilder+touch#msg_1753519

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 #1836817 is a reply to message #1836815] Thu, 14 January 2021 13:27 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior Member
i will start with that then. Thank you for the suggestions :)
Re: Eclipse does not recognize dsl file after generation [message #1838216 is a reply to message #1836817] Thu, 18 February 2021 16:21 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior 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 #1838221 is a reply to message #1838216] Thu, 18 February 2021 18:10 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
sory i have no idea about the maven part.

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 #1838410 is a reply to message #1838221] Wed, 24 February 2021 13:16 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior 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 #1838442 is a reply to message #1838410] Thu, 25 February 2021 05:10 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
Hi I still don't understand. The non maven use case = second builder that touches works fine for me

So does it work for you if you don't use maven?
If not can you please provide the code
For two hello world dsls
And your toucher-builder

Maybe you can also change the approach
Of physical transformation

And use an iderivedstatecomputer and do a model 2 model Trafo
In this case the generator of a would need to know how to index (and maybe also how to generate java of the in memory b instances


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

[Updated on: Thu, 25 February 2021 05:19]

Report message to a moderator

Re: Eclipse does not recognize dsl file after generation [message #1838674 is a reply to message #1838442] Wed, 03 March 2021 12:49 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior Member
Hello, i have managed to create a smaller project on which i reproduce the error, i created 2 languages, datamodel and model
datamodel is
context contextName-version extends anotherContext-version{}

and the model one is :
model { 
      name modelName
      extends another model
      version Version
} 

the model generates java like :
class Name-version{
	        public String name ="name";
		public String version ="version";
		public ExtendedClassName extendedClass = new ExtendedClassName(); }

after the creation of a new datamodel file, the model and the java files get generated, but the model file can not be referenced as an extension in another model file, only after i go to the file and do a space and save.

The zip with the XtextLanguageExample.zip contains the code and the newProj.zip is a project which is configured for the testing of the languages and the generation.
I tried on this example the things which i tried on the bigger project, but still no luck.
Re: Eclipse does not recognize dsl file after generation [message #1838675 is a reply to message #1838674] Wed, 03 March 2021 13:07 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
hi, you code does not contain the touher builder you used

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 #1838677 is a reply to message #1838675] Wed, 03 March 2021 13:21 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 27
Registered: January 2019
Junior 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

Re: Eclipse does not recognize dsl file after generation [message #1838728 is a reply to message #1838723] Thu, 04 March 2021 08:29 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
did you restrict the touch logic as the TODO lndicates?

did you look into the alternative derivedstatecomputer i proposed?
see also http://xtextcasts.org/episodes/18-model-optimization for further reading on that.


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
Previous Topic:Xtext 2.25.0 released
Next Topic:Referenced DSL-Files are not recognized on clean
Goto Forum:
  


Current Time: Mon Apr 12 16:01:52 GMT 2021

Powered by FUDForum. Page generated in 0.03015 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top