GROOVY-11896: Support module import declarations#2429
GROOVY-11896: Support module import declarations#2429paulk-asert wants to merge 1 commit intoapache:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2429 +/- ##
==================================================
+ Coverage 66.4890% 66.4922% +0.0032%
- Complexity 30230 30244 +14
==================================================
Files 1408 1408
Lines 117815 117862 +47
Branches 20934 20946 +12
==================================================
+ Hits 78334 78369 +35
- Misses 33035 33043 +8
- Partials 6446 6450 +4
🚀 New features to boost your workflow:
|
|
It's better to verify if current implementation supports Here are some discussions about module discovery functionality: |
3b4fbe8 to
07e5977
Compare
| * Known differences from Java's module import behavior: | ||
| * <ul> | ||
| * <li>Ambiguous class names from multiple module imports silently resolve | ||
| * to the last match, consistent with Groovy's existing star import | ||
| * semantics. Java reports a compile-time error for such ambiguities.</li> | ||
| * <li>Explicit single-type imports take priority over module-expanded | ||
| * star imports (same as Java).</li> | ||
| * </ul> |
There was a problem hiding this comment.
I think Java's semantic is all public classes. Adding all these star imports includes private types as well.
There was a problem hiding this comment.
Yes, existing star imports includes package-private while Java doesn't. I created GROOVY-11916 in case we want to change that. I think it is okay to follow existing Groovy behavior and change it in GROOVY-11916 if we don't like that. I am not sure we document that difference for star imports. But we should do for both the same way. I'll await thoughts on GROOVY-11916 before making changes here.
There was a problem hiding this comment.
I could see it getting vexing if module imports and star imports have conflicts around one module's package-private class beating out another one's public class. That would violate the principle of least surprise, I think. It's hard to think of a case where implementing https://issues.apache.org/jira/browse/GROOVY-11916 would trip somebody up, since actual construction or use of the classes would throw an exception anyway.
I'd support merging this and moving on GROOVY-11916 separately, though, if we're trying to avoid that becoming a blocker.
eric-milles
left a comment
There was a problem hiding this comment.
Does the original import stay in the AST? If not, then there is nothing left for code navigation support in eclipse. Although, I'm not 100% what sort of nav is possible for a module name.
This doesn't create some kind of (new) ModuleImportNode AST type but rather replaces with one or more star imports. We could track via node metadata as some kind of alternative to a new AST type. But as you say, is there a need? |
07e5977 to
174e2f2
Compare
For module navigation, I can see that IntelliJ just takes me to |
|
Overall, I agree that following Java's example seems more prudent than Scala's. I suspect that treating module imports as a distinct thing from static star imports, at least at some level in the AST, might be prudent. That could be because I never fully recovered from the psychic damage I took in the OSGi salt mines. 🙂 That caveat aside, it does seem like there's something from the module imports JEP that we're not supporting: Transitive dependencies across modules (as described in JEP 476).
Unless I have made an error, the existing branch does not do this. I've added a test to my fork (see 301582f) that demonstrates the issue. This is part of what makes me think we may well need specific semantics for the AST of module imports. There are additional expectations built into the JEP that make me think we'd need some specific things to handle them properly. |
see https://issues.apache.org/jira/browse/GROOVY-11896