INRIA / INRIA/spoon

usability issue: Custom pretty-printer creator silently overrides setAutoImports

Open
#3,690 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

Hi!

When you set a custom pretty-printer creator (i.e. with `Environment.setPrettyPrinterCreator`), this silently overrides the effect of `Environment.setAutoImports` in the `StandardEnvironment`. https://github.com/INRIA/spoon/blob/8a2cce96f45d74d6cc6b3d678947cee28cfdf991/src/main/java/spoon/support/StandardEnvironment.java#L661-L693

I've seen code setting both auto-imports and a custom creator multiple times now, for example here in Sorald: https://github.com/SpoonLabs/sorald/blob/2434d1d09812a40b3241adf942ad7b7bf4e0c824/src/main/java/sorald/SoraldAbstractRepair.java#L46-L65

I've myself made the mistake of thinking that I could use the sniper printer _and_ auto-imports. I see two reasonable options for improving this:

1. Simply issue a warning if both a custom pretty-printer creator and auto-imports are set, saying that the one overrides the other.
2. Prepend or append the auto-import processors to the preprocessors of the printer created by the pretty-printer creator.

I would personally prefer option 2, but I also see how that somewhat conflicts with the idea of setting a custom pretty printer and may cause breakage in existing applications.

Any thoughts on this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.