Skip to content
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: add support for malformed files through inheritance #3668

Merged
merged 4 commits into from
Nov 4, 2020

Conversation

darius-sas
Copy link
Contributor

A common issue that I get while analysing big projects is that the analysis fails just because a few files contain issues, or special characters that are not allowed by the Java compiler: like for example archetype resource files:

#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )

import ${package}.path.to.Clazz;

This very simple modification ensures that Spoon provides a best-effort attempt at parsing a certain project without failing just because of one malformed file. In case an error occurs, a message is printed on the console, so the user is notified.

I am not very practical of Spoon's internals, so there might be better solutions to this. If that's the case, pointers on how to implement a better one are welcome :)

@monperrus
Copy link
Collaborator

Not sure we want to silence so many errors.

What we can do instead is wrapping this call in a method that can be overridden, such that you create your own SilencingJDTCompiler (see extension point in Launcher).

@darius-sas
Copy link
Contributor Author

That sounds like a good option. I tried to look on how to provide to a Launcher your own SpoonModelBuilder but it seems to always instantiate a JDTBasedSpoonCompiler. It's very likely ofc that I am wrong :P

Another one would be to add an option (e.g. "silenceParseErrors", or something like that) that silences the error only if the user explicitly asks for it:

try {
    consumer.accept(unit);
} catch (Exception e) {
   if(!silenceParseErrors){
       throw e;
   }
   // log the error and continue parsing files.
}

Thanks for the help.

@monperrus
Copy link
Collaborator

Another one would be to add an option (e.g. "silenceParseErrors", or something like that) that silences the error only if the user explicitly asks for it:

In Spoon, for rare use cases, we avoid binary switches, because they are are hard to test and maintain.

@darius-sas
Copy link
Contributor Author

Ok thanks for the info. I'll try to implement the solution you mentioned.

@darius-sas
Copy link
Contributor Author

I made the modifications we discussed and also added an overridable method in Launcher that creates the compiler object which should allow users to instatiate their own compiler that overrides the visiting the of CUDs.

@monperrus monperrus changed the title Robustness to malformed files, archetype resources and other edge cases. refactor: supports for malformed files Nov 3, 2020
@monperrus
Copy link
Collaborator

Thanks a lot, this refactoring is good, will merge.

@monperrus monperrus changed the title refactor: supports for malformed files refactor: support for malformed files Nov 3, 2020
@monperrus monperrus changed the title refactor: support for malformed files refactor: add support for malformed files through inheritance Nov 4, 2020
@monperrus monperrus merged commit 1e63e28 into INRIA:master Nov 4, 2020
@monperrus
Copy link
Collaborator

Thanks a lot @darius-sas

@darius-sas
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants