Groovy @TypeChecked or @Builder + IntelliJ IDEA = false error. This is mistake?

Groovy 2.3.2 and IntelliJ IDEA 13.1.4

Consider the following examples:

1.

@TypeChecked
class ImmutabilityUtils {

    static List<Map<String, String>> asImmutable(List<Map<String, String>> relatedFeed) {
        relatedFeed*.asImmutable().asImmutable()
    }
}

      

In the examples above, the line is relatedFeed*.asImmutable().asImmutable()

underlined in red the first time it is called asImmutable()

with the message:

The category method "asImmutable" cannot be applied to java.util.List <java.util.Map <java.lang.String, java.lang.String β†’ </p>

Strange remark - when I did the same inline operation before passing the result as a constructor argument, the IDE didn't complain. Something like:

new FeedProcessor(relatedFeed*.asImmutable().asImmutable())

where the definition of constuctor looks like this:

FeedProcessor(List<Map<String, String>> relatedFeed)

... not relevant to the IDE complaint.

Screen shot illustrating issue 1. and 2.

2.

@TypeChecked
class ImmutabilityUtils {

    static Map<String, Map<String, String>> asImmutable(Map<String, Map<String, String>> lookupFeed) {
        lookupFeed.collectEntries { [it.key, it.value.asImmutable()] }.asImmutable()
    }
}

      

To make things shorter, here we have the same situation as in the first example. The only difference is asImmutable()

that the underlined method call is the one at the end of the line (after the closing parenthesis is closed). IDE message

The category method "asImmutable" cannot be bound to java.util.Map <?,? >

Similar to the first example, there were no complaints when executing inline as a constructor argument.

3.

@Builder(buildMethodName='build', builderMethodName='builder', prefix='with')
class Whatever { ... }

      

Here the annotation itself is @Builder

underlined by the message

Missing attributes: forClass, builderClassName

Wrong, because forClass and builderMethodName, for example, cannot be used at the same time.

Screen shot illustrating issue 3.

Any red underline in IntelliJ means the code won't even compile. It compiles and works as expected, although compiled by the IDE itself and with Gradle outside of the IDE.

Why is IntelliJ complaining about what is correct?

+3


source to share


1 answer


The red underline does not necessarily mean that the code will not compile. This means that IntelliJ's own code analysis thinks there is a bug, but this is not always correct - especially for languages ​​other than Java. IntelliJ Groovy support is good, but not perfect, but might not be that good for the new mode @TypeChecked

, and it might not have specific knowledge of lesser / recent AST transformations like @Builder

at all (in which case it won't understand them).



The correct course of action in this case is to submit a question to the IntelliJ bug tracker - not only in your own interest, but in the interest of the entire Groovy community.

+1


source







All Articles