Renny Barrett Renny Barrett - 1 month ago 5
Groovy Question

groovyc won't report multiple errors

I'm playing around with Groovy and in particular compiling and running Groovy classes from within a Java application.

The Groovy can, of course, have compilation problems, and I'm seeing different behaviour regarding reporting of compilation problems from
- running groovyc on the command line or loading a class using GroovyClassLoader vs.
- using an IDE such as Intellij.

Here's my test Groovy:

package test;

class MyTestGroovyClass2 {

causesACompileError();
alsoCausesACompileError();
}


In groovyc and using GroovyClassLoader, only the first error is reported:

groovyc "src\test\MyTestGroovyClass2.groovy"

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Users\barrettr\IdeaProjects\TestGroovy\src\test\MyTestGroovyClass2.groovy: 5: unexpected token: causesACompileError @ line 5, column 2.
causesACompileError();
^

1 error


...but in IntelliJ I see both errors:
enter image description here

I debugged briefly through the
GroovyClassLoader
and saw it stopping after finding the first error.

Is there any support in Groovy for reporting multiple errors, a la IntelliJ?

Answer

IntelliJ utilizes its own parser trying to parse as much as it can. After the first parsing error the parser state is recovered and the parser then tries to process the next statement.