Skip to content

Conversation

@dilyanpalauzov
Copy link
Contributor

@dilyanpalauzov dilyanpalauzov commented Oct 25, 2025

The current addition:

imlicitImports.add(doCreateImportNormalizer(
    QualifiedName.create("java", "time", "temporal", "ChronoUnit"), false, false);

corresponds to having in DSL scripts/rules implicit: import java.time.temporal.ChronoUnit;, whereas

imlicitImports.add(doCreateImportNormalizer(
    QualifiedName.create("java", "time", "temporal"), true, false);

(cutting , "ChronoUnit" and toggling the middle parameter), would correspond to import java.time.temporal.*;.

The reason why DayOfWeek.MONDAY and logError("A", MonthDay.now.toString) (⇔ MonthDay.now()) work is, because ScriptImportSectionNamespaceScopeProvider.java:getImplicitImports() contains implicitImports.add(doCreateImportNormalizer(QualifiedName.create("java", "time"), true, false)); corresponding to implicit import java.time.*; in DSL scripts.

N.B. As the result of ScriptImplicitlyImportedTypes.java:getStaticImportClasses() includes ChronoUnit.class and DayOfWeek.class, DSL Scripts have implicit import static java.time.temporal.ChronoUnit.*; import static java.time.DayOfWeek.*;. For this reason just TUESDAY and DAYS in Script DSL are recognized.

Closes #4791.

@dilyanpalauzov dilyanpalauzov requested a review from a team as a code owner October 25, 2025 09:49
@dilyanpalauzov dilyanpalauzov changed the title Script DSL: do implicit “import java.time.temporal.ChronoUnit;” Script DSL: do implicit import java.time.temporal.ChronoUnit; Oct 25, 2025
@mherwege
Copy link
Contributor

Thanks.

@lolodomo
Copy link
Contributor

lolodomo commented Dec 6, 2025

@dilyanpalauzov : I am afraid none of your PRs will be accepted by @openhab/core-maintainers because they are not signed as requested.
Except that, your PR looks good to me.
@mherwege : did you check it solved properly your issue?

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the investigation and the fix.

With two simple lines, I am ok to merge this without DCO as a small patch exception.

@kaikreuzer kaikreuzer merged commit b3e5838 into openhab:main Dec 6, 2025
3 of 4 checks passed
@kaikreuzer kaikreuzer added this to the 5.1 milestone Dec 6, 2025
@kaikreuzer kaikreuzer added the bug An unexpected problem or unintended behavior of the Core label Dec 6, 2025
@dilyanpalauzov dilyanpalauzov deleted the import_chronounit_dsl branch December 7, 2025 07:08
@jimtng
Copy link
Contributor

jimtng commented Dec 7, 2025

@mherwege could this method be used to solve #4784 ?

@mherwege
Copy link
Contributor

mherwege commented Dec 8, 2025

@mherwege : did you check it solved properly your issue?

Yes, it does solve the issue for ChronoUnit.

@mherwege could this method be used to solve #4784 ?

Unfortunately not. It looks like it always treats the nested enum as a field when using file defined rules, whatever I try, including the pattern as in this PR. I probably miss something obvious but I don't see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An unexpected problem or unintended behavior of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rules DSL ChronoUnit behaving differently

5 participants