How to understand which are the auto-generated files in a huge Java project developed in Eclipse?
I am a newbie. For example, little by little, I am discovering that many files are generated by using xcore
plug-in. Other with xtend
. Just going through the code and trying I am learning and that's ok. The question is: is there a way to understand which files to modify to automatically regenerate the others? My error was to start modifying all the files manually.
Usually you set up different source directories for your code and generated code.
For example, a project using Xtend and EMF would have following source directories in its build path:
src
contains all Java and Xtend files that you writextend-gen
contains generated Java files created by Xtendsrc-gen
contains generated Java files created by EMFIn this setup you should only edit files in
src
. Files inxtend-gen
will be updated automatically if you edit Xtend files insrc
. Files insrc-gen
will be updated if you regenerate the model.I'm not that familiar with Xcore, but since it is based on EMF I think you just have to set the "model directory" property of the genmodel.
This should make the distinction between your code and generated code more clear. You may still feel the need to modify generated code sometimes. EMF actually supports this by adding special annotations in the generated file but I would not recommend this, because it's very hard to see if a file has been modified this way. If you really need to change the generated behavior, the first approach described in this article about properly overriding generated EMF code is better. Basically you extend and override methods of some generated classes and the factory and then use Eclipse extension points to replace the generated factory with your extended one.
If you are looking at a project of someone else and don't know which code generating tools are used:
You should try to ask the authors if possible or check if there is any documentation about building the project. Otherwise I guess you'll need to analyze the project structure to see which plugins are used to generate code. This might be a bit hard if you don't already know which plugins actually can generate code though.
@Generated
annotations is used in the code, which is used to mark generated filesIf you have Identified all tools, then try to change the model destination directory and regenerate the code. Then compare the generated files with your original code - all duplicated files are likely generated.