Synchronization Before Generation

Hello everyone,

I have a question that seems a little hard to explain, yet seems easy to answer.

Here, JavaSource.zip (95KB), you can find a sample project I created for making it easy to explain the question I intend to ask.

Following are the steps to make the project work:

1. Copy the project to a write permitted directory. For example in C:\MpsProject\JavaSource\
2. From the MPS Settings, Path Variables (Settings -> Build, Execution, Deployment -> Path Variables) add java_src_project and reference the base directory of the project.
3. Open the project and go to the Module Properties of the SavaSrcLang.sandbox and open the Java tab. If the Source Path defined is colored with red, remove it and add the [project_location]/solutions/CopiedJavaSources/copied directory.

Explanation:

This small project is created to demonstrate an issue I am facing in a larger version of the project.
The project is composed of a language JavaSrcLang that has one root concept SourceTest and its editor and a sandbox solution JavaSrcLang.sandbox. I have created a simple logger to trace the operations that gives the output to [project_location]/logs/mylogs.log.

The most important part of this project is the CopiedJavaSources solution. When you look its Module Properties you will notice in the Common tab that the model root added is java_source_stubs that shows the \copied folder as its root and the generator of the language is using the sources that are located in this directory. If you open the SourceTestGeneratedContent class in the main@generator you will notice that there are reference macros assigned to the Objects that show the TestClassOne and TestClassTwo that can be viewed in the Inspector.

What I want to do is to copy the TestClassOne.java and TestClassTwo.java from the [project_location]/src/com/mypackage/mysubpackage/ to the [project_location]/solutions/CopiedJavaSources/copied/com/mypackage/mysubpackage/ directory when the user rebuilds the sandbox solution. Actually what is being done in the larger version of this project is that these classes (TestClassOne and TestClassTwo in our example) are generated automatically by a mapping script in the main@generator and placed in the [project_location]/solutions/CopiedJavaSources/copied/com/mypackage/mysubpackage/. To simulate this behaviour I created a mapping script called CopySourceScript which just copies these test classes to the solution's intended directory, and this script is called from the main mapping configuration in the pre-processing scripts part.

Now, from the file explorer of your operating system, when you remove the java source files located in the [project_location]/solutions/CopiedJavaSources/copied/com/mypackage/mysubpackage/ and head back to the MPS editor you will notice that the CopiedJavaSources solution will be shown as an empty solution which is quite normal. However, if you rebuild the sandbox solution you will notice that some errors are generated stating that a reference to 'classifier' could not be resolved. Well actually, even at this point there is no problem with the generation of the java source code which can be seen by right clicking the MySourceTest root node in the sandbox solution and selecting Preview Generated Text option. Then if you synchronize the project (from File -> Synchronize) you will see that the Test classes are visible again in the CopiedJavaSources soulution and when you rebuild the sandbox solution no errors are shown as expected.

Question:

Here is my question, is it possible to completely remove these errors by synchronizing the CopiedJavaSources solution beforehand and making the Test classes appear just before the mapping operations take place in the generation step?

What I've tried so far:

  • I tried creating another mapping configuration and placing this CopySourceScript in the pre-processing scripts part of this configuration, and from the Generator Priorities option of the language generator I have arranged their priorities (I tried every possible combination, unfortunitalley there is no hope there).
  • I tried creating another generator with another mapping configuration and placing this CopySourceScript in the pre-processing scripts part of this configuration, and set the generator priorities but no luck there either.
  • I tried to sleep the code with Thread.sleep to make it wait for the project to refresh itself but this did not work either.

Sorry for this long question, I tried to clarify the points in a broad sense to make it more understandable. I am open to opinions and questions and I hope we can find a solution for this issue.

Please sign in to leave a comment.