RFR: 8344079: Minor fixes and cleanups to compiler lint-related code [v4]

Archie Cobbs acobbs at openjdk.org
Mon Dec 2 14:20:46 UTC 2024


On Mon, 2 Dec 2024 10:07:02 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Archie Cobbs has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Address review comment by being less Streamy.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java line 446:
> 
>> 444:         EnumSet<LintCategory> result = LintCategory.newEmptySet();
>> 445:         Attribute.Array values = (Attribute.Array)suppressWarnings.member(names.value);
>> 446:         for (Attribute value : values.values) {
> 
> I think this loop is more stream-friendly - e.g. you start from `values.values` then:
> * `flatMap` using `Optional.of(value).stream()`
> * `map` (using `LintCategory::get`, as now)
> * `collect` to a new enum set
> 
> This allows to skip `ifPresent` check (subsumed by flatMap) and also the `result.add`. But, you'll end up with a complex expression inside the flat map (`Optional.of((String)((Attribute.Constant)value).value)`). So I'll leave to you whether this is worth it.

I used a loop based on the "use imperative logic" suggestion, but maybe that's not what you meant... In any case I agree it's somehow not fully satisfying, as there's no ideal solution here because of all the casting and null checking required.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22056#discussion_r1865930427


More information about the compiler-dev mailing list