drccrd commented on code in PR #3998:
URL:
https://github.com/apache/incubator-kie-tools/pull/3998#discussion_r4004899371
##########
packages/drools-lsp/drools-completion/src/test/java/org/drools/completion/DRLLintHelperTest.java:
##########
@@ -799,4 +819,144 @@ void lowercasePropertyTailIsNotChased() {
+ "rule R\n when\n Animal( legs == PetKind.CAT.ordinal )\n
then\nend\n";
assertThat(lintUnknownTypes(text)).isEmpty();
}
+
+ // ── sibling imports (same-package) ───────────────────────────────────
+
+ private static final String USES_ORDER =
+ "package demo;\nrule R\n when\n Order( )\n then\nend\n";
+
+ /** Builds a class index from empty {@code .class} files for {@code
fqcns}. */
+ private static ClassIndex classIndexOf(Path tempDir, String... fqcns)
throws IOException {
+ Path classesDir = tempDir.resolve("classes");
+ Files.createDirectories(classesDir);
+ for (String fqcn : fqcns) {
+ Path classFile = classesDir.resolve(fqcn.replace('.', '/') +
".class");
+ Files.createDirectories(classFile.getParent());
+ Files.createFile(classFile);
+ }
+ return ClassIndex.build(Set.of(classesDir));
+ }
+
+ @Test
+ void siblingImportLegalizesPatternType(@TempDir Path tempDir) throws
IOException {
+ // A same-package sibling imports Order; the current file uses it as a
+ // pattern type without importing it itself. The exact sibling import
+ // makes it resolvable, so no unknown-type diagnostic fires.
+ Path current = tempDir.resolve("current.drl");
+ Files.writeString(current, USES_ORDER);
+ Files.writeString(tempDir.resolve("sibling.drl"),
+ "package demo;\nimport com.example.model.Order;\n");
+
+ List<Diagnostic> diags = DRLLintHelper.lintUnknownTypes(
+ Files.readString(current), current, Map.of(),
ClassIndex.empty(), members, true);
+
+ assertThat(diags).isEmpty();
+ }
+
+ @Test
+ void siblingWildcardImportLegalizesThroughClassIndex(@TempDir Path
tempDir) throws IOException {
+ // A wildcard sibling import (com.example.model.*) legalizes Order only
+ // when the class index confirms that package provides it. Two Order
+ // classes make the bare simple name ambiguous, so only the wildcard's
+ // package can disambiguate it — a path local wildcard imports never
+ // exercise (their extraction yields the bare package name).
Review Comment:
Fixed in
[bc4ef1c](https://github.com/apache/incubator-kie-tools/pull/3998/commits/bc4ef1c3fe948df9a924f2a0a19e53cf3f97b77b)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]