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

The sniper printer does not work as expected in a line break context (style issue) #3401

Closed
fermadeiral opened this issue Jun 8, 2020 · 2 comments

Comments

@fermadeiral
Copy link
Contributor

Hi all,

I have the following code:

        void foo(int x) {
		new IllegalArgumentException("x must be nonnegative");
	}

I want to add a throw in the constructor call new IllegalArgumentException. The transformation works just fine (no exception, the printed code is correct), but a line break is missing, so I get:

        void foo(int x) {throw new java.lang.IllegalArgumentException("x must be nonnegative");
	}

Instead of:

        void foo(int x) {
		throw new java.lang.IllegalArgumentException("x must be nonnegative");
	}

I am opening a PR with a failing test case to reproduce the issue.

@nharrand
Copy link
Collaborator

nharrand commented Jun 9, 2020

After investigation, it seems that the problem appears for any modified statment in position 0 of a CtBlock.

@monperrus
Copy link
Collaborator

closed per #3400

monperrus pushed a commit to monperrus/spoon that referenced this issue Jun 12, 2020
monperrus pushed a commit to monperrus/spoon that referenced this issue Jun 13, 2020
nharrand added a commit that referenced this issue Jun 14, 2020
* test(SniperPrettyPrinter): test replacement of invocation (#3399) (#3400)

* test(SniperPrettyPrinter): modification on first statement of a block should not remove new line (#3401) (#3402)

* up

* up

* @monperrus at work

* Update src/main/java/spoon/support/DefaultCoreFactory.java

* @monperrus at work

* up

* @monperrus at work

* @monperrus at work

* @monperrus at work

* up

* up

* @monperrus at work

* @monperrus at work

* @monperrus at work

Co-authored-by: Fernanda Madeiral <fer.madeiral@gmail.com>
Co-authored-by: Nicolas Harrand <nicolas.harrand@gmail.com>
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

No branches or pull requests

3 participants