refactor: avoid creation of JDT hacking TMP files #944
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am trying to unify compilation process of snippets, templates and sources. I have found these facts:
JDTBasedSpoonCompiler buildSources and buildTemplates
JDTBasedSpoonCompiler.createTmpJavaFile(folder)
always creates empty file. So nobody needs content of that file.JDTBasedSpoonCompiler
methodsbuildSources
andbuildTemplates
does the same - compiles java files and fills the model. Just the classpath and files are different. But all other things related to compilation are same!So there is no reason why
buildTemplates
is creating a temporary file next to zip or jar archives, whilebuildSources
does not need that.This TMP file creation code is anyway wrong, it actually might produce many empty tmp files and deletes only one of them!
There is no test case, which would fail, if creation of tmp files here is omitted.
The code is here since commit 39562eb (nearly 3 years old) and at this time there was used different version of JDT compiler. So there is high chance that JDT bug is already fixed.
So I suggest to get rid of the creation of these temporary files in
buildTemplates
. And if it really fails by somebody then we can get the stacktrace and can create a test case and can fix it correctly. But actually it looks like useless code, which just makes things more complicated.JDTSnippetCompiler buildSources
this method creates temporary file too. I have found that JDT compilation does not need existing file. It is enough to provide there some source path and it passes too.