@@ -124,9 +124,9 @@ public class Order {
124124
125125func TestExtract_InterfaceEnumRecord (t * testing.T ) {
126126 ff := extractAll (t , map [string ]string {
127- "a/Shape.java" : "package a;\n public interface Shape { double area(); }\n " ,
128- "a/Color.java" : "package a;\n public enum Color { RED, GREEN, BLUE }\n " ,
129- "a/Point.java" : "package a;\n public record Point(int x, int y) {}\n " ,
127+ "a/Shape.java" : "package a;\n public interface Shape { double area(); }\n " ,
128+ "a/Color.java" : "package a;\n public enum Color { RED, GREEN, BLUE }\n " ,
129+ "a/Point.java" : "package a;\n public record Point(int x, int y) {}\n " ,
130130 })
131131
132132 iface , _ := findFact (ff , "a.Shape" )
@@ -201,6 +201,99 @@ public class Service {
201201 }
202202}
203203
204+ // TestExtract_StaticImportResolvesInternal covers the parent-FQN fallback:
205+ // a static member import names the member, not the type, so the declaring type's
206+ // FQN is the parent of the import string.
207+ func TestExtract_StaticImportResolvesInternal (t * testing.T ) {
208+ ff := extractAll (t , map [string ]string {
209+ "app/svc/Service.java" : `package app.svc;
210+
211+ import static app.data.Constants.MAX;
212+
213+ public class Service {
214+ int v = MAX;
215+ }
216+ ` ,
217+ "app/data/Constants.java" : "package app.data;\n public class Constants { public static final int MAX = 1; }\n " ,
218+ })
219+
220+ var ok bool
221+ for _ , f := range factsByKind (ff , facts .KindDependency ) {
222+ if f .Props ["import" ] == "app.data.Constants.MAX" {
223+ if f .Props ["source" ] == "internal" && hasRelation (f , facts .RelImports , "app/data" ) {
224+ ok = true
225+ }
226+ }
227+ }
228+ if ! ok {
229+ t .Error ("static import app.data.Constants.MAX should resolve internal to module app/data" )
230+ }
231+ }
232+
233+ // TestExtract_UnindexedTypeResolvesViaPackage covers the second fallback branch:
234+ // an imported type we didn't index as a top-level class still resolves to its
235+ // package's module dir, because the package is internal.
236+ func TestExtract_UnindexedTypeResolvesViaPackage (t * testing.T ) {
237+ ff := extractAll (t , map [string ]string {
238+ "app/svc/Service.java" : `package app.svc;
239+
240+ import app.data.Repo.Inner;
241+
242+ public class Service {}
243+ ` ,
244+ "app/data/Repo.java" : "package app.data;\n public class Repo { public static class Inner {} }\n " ,
245+ })
246+
247+ var ok bool
248+ for _ , f := range factsByKind (ff , facts .KindDependency ) {
249+ if f .Props ["import" ] == "app.data.Repo.Inner" {
250+ // Resolves via parent type app.data.Repo (or package app.data) → app/data.
251+ if f .Props ["source" ] == "internal" && hasRelation (f , facts .RelImports , "app/data" ) {
252+ ok = true
253+ }
254+ }
255+ }
256+ if ! ok {
257+ t .Error ("import of un-indexed type app.data.Repo.Inner should resolve internal to app/data" )
258+ }
259+ }
260+
261+ // TestExtract_WildcardNotOverResolved guards that the parent-FQN fallback is NOT
262+ // applied to wildcard imports: an external wildcard stays external (it must not
263+ // walk to a grandparent), while an internal wildcard still resolves normally.
264+ func TestExtract_WildcardNotOverResolved (t * testing.T ) {
265+ ff := extractAll (t , map [string ]string {
266+ "app/svc/Service.java" : `package app.svc;
267+
268+ import app.data.*;
269+ import com.external.lib.*;
270+
271+ public class Service {}
272+ ` ,
273+ "app/data/Repo.java" : "package app.data;\n public class Repo {}\n " ,
274+ })
275+
276+ var internalWildcardOK , externalWildcardExternal = false , true
277+ for _ , f := range factsByKind (ff , facts .KindDependency ) {
278+ switch f .Props ["import" ] {
279+ case "app.data" :
280+ if f .Props ["source" ] == "internal" && hasRelation (f , facts .RelImports , "app/data" ) {
281+ internalWildcardOK = true
282+ }
283+ case "com.external.lib" :
284+ if f .Props ["source" ] != "external" {
285+ externalWildcardExternal = false
286+ }
287+ }
288+ }
289+ if ! internalWildcardOK {
290+ t .Error ("internal wildcard import app.data.* should resolve to app/data" )
291+ }
292+ if ! externalWildcardExternal {
293+ t .Error ("external wildcard import com.external.lib.* must stay external (no grandparent fallback)" )
294+ }
295+ }
296+
204297func TestExtract_InstantiatesAndCalls (t * testing.T ) {
205298 ff := extractAll (t , map [string ]string {
206299 "m/Widget.java" : "package m;\n public class Widget {}\n " ,
0 commit comments