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

Spoon generate duplicate brackets in invocations. #2330

Closed
nemo9cby opened this issue Aug 2, 2018 · 5 comments
Closed

Spoon generate duplicate brackets in invocations. #2330

nemo9cby opened this issue Aug 2, 2018 · 5 comments
Labels

Comments

@nemo9cby
Copy link

nemo9cby commented Aug 2, 2018

After applying processing, there will be duplicate brackets inside invocations if they contain "+".

For example, if the original line is like:
logger.info("Value declared in if:" + c);

After parsing in Spoon, it would become:
logger.info(("Value declared in if:" + c));

Another example:
before:
LOG.warn("AuthenticationToken ignored: " + ex.getMessage());
after:
LOG.warn(("AuthenticationToken ignored: " + (ex.getMessage())));

The processor looks like:

public class CusProcessor extends AbstractProcessor<CtStatement> {
    public void process(CtStatement element) {
        if (element instanceof CtInvocationImpl) {
            CtInvocationImpl invoke = (CtInvocationImpl) element;
            System.out.println(invoke);
        }
    }
}

Launcher code:

        Launcher launcher = new Launcher();
        launcher.addInputResource(filePath);
        launcher.getEnvironment().setNoClasspath(true); 
        launcher.getEnvironment().setAutoImports(true);
        launcher.getEnvironment().setOutputType(OutputType.NO_OUTPUT);
        launcher.getEnvironment().setCommentEnabled(false);
        launcher.addProcessor(new CusProcessor());
        launcher.run();

My guess is that it is because of the internal compiler, is there a way to fix this?

@surli
Copy link
Collaborator

surli commented Aug 2, 2018

Hi @nemo9cby thanks for reporting this one!
It was already reported by @pvojtechovsky and it should have been fixed with #2113. So you might want to try the latest snapshot of Spoon to check if it solve your problem: it will be integrated in the next release.

@nemo9cby
Copy link
Author

nemo9cby commented Aug 2, 2018

Hi @surli , thanks for the reply!
I am currently using 7.0.0 and it shows in the change log that the bug #2113 has been fixed in this snapshot. So by saying "next release" do you mean that 7.0.0 is not able to deal with this issue and we need to build the snapshot using the latest commit?

@nemo9cby
Copy link
Author

nemo9cby commented Aug 2, 2018

Actually I just checked version 7.0.0, it already contains the code changes of #2113. This issue still exists. #2113 seems to solve the issue with CastExpression, yet this is an issue about StringLiteralConcatenation (or InfixExpression, i am not sure). For example, whenever there is one, e.g.System.out.println("a" + "b"), after traversing the visitors, it will become System.out.println(("a" + "b")).

@surli
Copy link
Collaborator

surli commented Aug 3, 2018

My bad then: I though #2113 was not yet integrated in a Spoon release. So yeah it's a new bug.

@Egor18
Copy link
Contributor

Egor18 commented Jun 23, 2019

Resolved by #3024

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

No branches or pull requests

4 participants