-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to use the Spoon library #109
Conversation
Apparently the order in which placeholders are added to the mapping is not guaranteed, causing the smoke tests to fail sometimes because the mapping.json has a different order. Having ordered keys in an org.json.JSONObject is apparently not possible, so this switches the project to using com.google.gson instead.
a61393c
to
687a763
Compare
…tch expressions Note that support for Java 20 and 21 is not yet added to Spoon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sanderploegsma Am I correct in seeing that the same code might get a different representation in this version?
Yes, that is correct. The most notable changes are:
Note however that a lot of changes are for the better. It also seems to fix a few bugs, like the I get that under normal circumstances we would like to prevent the same code generating a different representation, but in this case we may want to accept that consequence. Or are there reasons to prevent this that I may not be aware of? |
The main downside is that we have to re-run the representer on all existing solutions, which is a time-consuming and somewhat costly operation. Are you planning on doing more work on the representer? E.g. if you want to implement more representation changes it is best for us to wait for those to not having to re-run multiple times. |
In that case we may want to hold off until a new version of Spoon is released that includes my fix for the Enum formatting: INRIA/spoon#5649. After that, I don't expect too many new changes.
Oof, yeah I see. And is that something that happens automatically when updates to a representer are pushed? Or is it a manual trigger invoked by an admin in situations like these? |
We manually invoke it, but once we merge, new solutions will start getting the new representation. |
@ErikSchierboom the enum formatting has been fixed, so IMO this PR is finished! |
- No fully qualified types when printing - Use AOSP style for formatting
@ErikSchierboom could you also review this one? |
Before I approve, this means that this is the definitive version of the new representation, correct? |
Yes, no more breaking changes 👍 |
We'll re-run the representations shortly (it'll take a while). |
This refactors the implementation of the Java representer, mainly by replacing the JavaParser library with the Spoon library. Main reason for doing so is that JavaParser makes it pretty hard to accurately track usage of methods, variables etc when renaming, while Spoon gives us this for free.
It also seems to clean up a little bit of complexity which is nice. I also added/updated
CONTRIBUTING.md
andREADME.md
to contain information similar to their counterparts in the Java analyzer.Next to that, this PR adds the following fixes/improvements:
Fix recursion in placeholder generation
The previous implementation apparently contained a bug where it would create new placeholders for existing ones, probably because the normalizer makes changes to the representation in-place while walking the AST. This causes an interesting side-effect to say the least; and solving it brings us one step closer to the normalized representation still being valid Java.
The bug was easily spotted in
tests/multiple-solution-files/expected_mapping.json
, as the mapping contains entries mapping one placeholder to another.Write output to given output folder instead of solution folder
For some reason this tool was still writing the output to the solution folder instead of to the output folder passed as CLI argument. This is now fixed.
I also removed the validation logic used to check whether the CLI arguments for the input and output folders end with a
/
, as the implementation no longer relies on that being the case.Fix error in logging output
Previously the representer output contained a large error on startup:
This was being caused by the
log4j
library trying to determine the system host name in an environment without a network (Docker). I tried to see if I could suppress it by changing the logger output format, but they insist on resolving the host name even if it's not used in the log output. To that end, I replacedlog4j
withslf4j
+logback
and now the error is gone.Ordered keys in
mapping.json
While testing locally, it turned out that sometimes the order of the keys in
mapping.json
changes, causing the smoke tests to fail. So, now themapping.json
has keys ordered alphabetically. They are now also keyed by placeholder instead of by identifier, following the example in the docs.Fixes #18
Fixes #19