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

static import not written out by Spoon #3214

Open
shoeoffhead opened this issue Jan 25, 2020 · 9 comments
Open

static import not written out by Spoon #3214

shoeoffhead opened this issue Jan 25, 2020 · 9 comments

Comments

@shoeoffhead
Copy link

I just did a little test reading in and writing out commons-io-2.6-sources.jar with Spoon.

IOUtils defines: public static final int EOF = -1;

This is statically imported by org.apache.commons.io.output.ByteArrayOutputStream and org.apache.commons.io.EndianUtils

Spoon just adds this static import to ByteArrayOutputStream but NOT EndianUtils

@monperrus
Copy link
Collaborator

Thanks a lot for the bug report.

Could you share a link to the source file you're analyzing?

@shoeoffhead
Copy link
Author

Just the latest commons-io version: 2.6
https://mvnrepository.com/artifact/commons-io/commons-io/2.6

You can also download it manually: https://repo1.maven.org/maven2/commons-io/commons-io/2.6
The file is called: commons-io-2.6-sources.jar

I also use the latest Spoon.

@monperrus
Copy link
Collaborator

monperrus commented Jan 27, 2020 via email

@shoeoffhead
Copy link
Author

shoeoffhead commented Jan 27, 2020

I did now several other tests read/writing sources from big libraries. I always have issues with static imports not written out.

I will prepare a minimal project for you showing the bug. I am not very familiar with Github ;)

[UPDATE]: I forgot that this problems happens when using launcher.getEnvironment().setAutoImports(true);

With this setting Spoon removes the static import in the written out source code:
for example: import static java.lang.Character.isLetter;

If I use setAutoImports(false), Spoon removes the static import BUT also writes the full qualified name for EVERY import in the source code:
for example: java.lang.Character.isLetter(...)

I would prefer using setAutoImports(true) because otherwise the source code is cluttered with qualified names.

@monperrus
Copy link
Collaborator

monperrus commented Jan 28, 2020 via email

@shoeoffhead
Copy link
Author

  1. extract the attached zip file
  2. execute on the cli: gradle run
  3. the files are written to folder 'output'. Add 'output' as a source folder to your IDE to see the described error in my first post.

commons-collections.zip

@shoeoffhead
Copy link
Author

Did you have time looking into this?

@monperrus
Copy link
Collaborator

Not yet. If you could reproduce the bug in a failing test case in a pull request, that would be super useful. Thanks!

@shoeoffhead
Copy link
Author

Sorry. I am not really familiar with Git. The zip project is super simple though. You can reproduce the problem in seconds.

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

2 participants