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

Spork often prints fully qualified names even if the package is implicit in all source files #94

Open
slarse opened this issue Mar 31, 2020 · 4 comments
Labels
bug Something isn't working might be fixed?

Comments

@slarse
Copy link
Collaborator

slarse commented Mar 31, 2020

When Spoon has managed to resolve the package of a type, it often does not mark it as implicit. This causes absolutely massive diffs in files with many type references to classes that are imported, as they're often printed fully qualified by Spork.

This should be pretty easy to solve in printer preprocessing by simply marking any package that's imported as implicit.

@slarse slarse added the bug Something isn't working label Mar 31, 2020
@slarse slarse changed the title Spoon fails to mark anything but trivial packages (e.g. java.lang) as implicit Spork often prints fully qualified names even if the package is implicit in all source files Mar 31, 2020
@slarse
Copy link
Collaborator Author

slarse commented Mar 31, 2020

After some investigation, this appears to happen when only static members of a class are used. As soon as a non-static member is used, the package is marked implicit. Very strange.

@slarse
Copy link
Collaborator Author

slarse commented Mar 31, 2020

Ah, this actually seems to be worse. When only static methods are used on a class, and that class is not qualified (but imported), Spoon will somehow figure that this class is from the current package. Even if it's imported.

@slarse
Copy link
Collaborator Author

slarse commented Mar 31, 2020

I've devised a workaround for use in preprocessing:

Provide the preprocessor with the active package as well as the list of imports. Then, each time a package reference is encountered, do this:

  1. If it references the active package, always mark as implicit. This could technically lead to name clashes, but it would be very strange style to import a class that clashes with the current package, and use the qualified name of the class in the current package, instead of the qualified name of the imported class.
  2. If it is the child of a type reference, then check if that type reference is imported, either explicitly or with a *. If so, mark as implicit.

This seems to mostly solve the problem. It's a workaround, so ideally it can be removed once the problem is fixed in Spoon.

slarse added a commit that referenced this issue Apr 5, 2020
This should be reverted once the bug is fixed in Spoon
@slarse
Copy link
Collaborator Author

slarse commented May 12, 2020

I believe that this issue has been solved by INRIA/spoon#3364 and INRIA/spoon#3357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working might be fixed?
Projects
None yet
Development

No branches or pull requests

1 participant