[
https://issues.apache.org/jira/browse/GROOVY-11202?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-11202:
-------------------------------
Description:
When running Gradle 8.4 -> GroovyDoc 4.0.15 which uses javaparser-core 3.25.5 i
get the following error:
{noformat}
[ant:groovydoc] Attempting to ignore error parsing Java source file:
se/alipsa/groovy/matrix/util/DataType.java
[ant:groovydoc] Consider reporting the error to the Groovy project:
https://issues.apache.org/jira/browse/GROOVY
[ant:groovydoc] ... or directly to the JavaParser project:
[https://github.com/javaparser/javaparser/issues]
[ant:groovydoc] Error: (line 55,col 9) Use of patterns with instanceof is not
supported.
{noformat}
The offending code is:
{code}
public static String sqlType(Object value, int... varcharSize) {
if (value instanceof BigDecimal bd) {
return "DECIMAL(" + bd.precision() + "," + bd.scale() + ")";
}
return value == null ? null : sqlType(value.getClass(), varcharSize);
}
{code}
Patterns with instanceof is supported by javaparser:
{code:groovy}
@Test
void testParseInstanceofPattern() {
String code = """
class A {
public static String sqlType(Object value, int... varcharSize) {
if (value instanceof BigDecimal bd) {
return "DECIMAL(" + bd.precision() + "," + bd.scale() + ")";
}
return value == null ? null : sqlType(value.getClass(),
varcharSize);
}
}
""";
ParserConfiguration config = new ParserConfiguration();
config.setLanguageLevel(LanguageLevel.JAVA_17);
JavaParser parser = new JavaParser(config);
CompilationUnit cu = JavaParserAdapter.of(parser).parse(code);
System.out.println(cu.toString());
}
{code}
This might mean that the groovy gradle plugin is not setting the language level
based on the tool chain e.g in my build.gradle, I have:
{code:groovy}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
{code}
was:
When running Gradle 8.4 -> GroovyDoc 4.0.15 which uses javaparser-core 3.25.5 i
get the following error:
{noformat}
[ant:groovydoc] Attempting to ignore error parsing Java source file:
se/alipsa/groovy/matrix/util/DataType.java
[ant:groovydoc] Consider reporting the error to the Groovy project:
https://issues.apache.org/jira/browse/GROOVY
[ant:groovydoc] ... or directly to the JavaParser project:
[https://github.com/javaparser/javaparser/issues]
[ant:groovydoc] Error: (line 55,col 9) Use of patterns with instanceof is not
supported.
{noformat}
The offending code is:
{code}
public static String sqlType(Object value, int... varcharSize) {
if (value instanceof BigDecimal bd) {
return "DECIMAL(" + bd.precision() + "," + bd.scale() + ")";
}
return value == null ? null : sqlType(value.getClass(), varcharSize);
}
{code}
Patterns with instanceof is supported by javaparser:
{code:groovy}
@Test
void testParseInstanceofPattern() {
String code = """
class A {
public static String sqlType(Object value, int... varcharSize) {
if (value instanceof BigDecimal bd) {
return "DECIMAL(" + bd.precision() + "," +
bd.scale() + ")";
}
return value == null ? null : sqlType(value.getClass(),
varcharSize);
}
}
""";
ParserConfiguration config = new ParserConfiguration();
config.setLanguageLevel(LanguageLevel.JAVA_17);
JavaParser parser = new JavaParser(config);
CompilationUnit cu = JavaParserAdapter.of(parser).parse(code);
System.out.println(cu.toString());
}
{code}
This might mean that the groovy gradle plugin is not setting the language level
based on the tool chain e.g in my build.gradle, I have:
{code:groovy}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
{code}
> Support use of patterns with instanceof in groovydoc
> ----------------------------------------------------
>
> Key: GROOVY-11202
> URL: https://issues.apache.org/jira/browse/GROOVY-11202
> Project: Groovy
> Issue Type: Bug
> Reporter: Per Nyfelt
> Priority: Minor
>
> When running Gradle 8.4 -> GroovyDoc 4.0.15 which uses javaparser-core 3.25.5
> i get the following error:
> {noformat}
> [ant:groovydoc] Attempting to ignore error parsing Java source file:
> se/alipsa/groovy/matrix/util/DataType.java
> [ant:groovydoc] Consider reporting the error to the Groovy project:
> https://issues.apache.org/jira/browse/GROOVY
> [ant:groovydoc] ... or directly to the JavaParser project:
> [https://github.com/javaparser/javaparser/issues]
> [ant:groovydoc] Error: (line 55,col 9) Use of patterns with instanceof is not
> supported.
> {noformat}
> The offending code is:
> {code}
> public static String sqlType(Object value, int... varcharSize) {
> if (value instanceof BigDecimal bd) {
> return "DECIMAL(" + bd.precision() + "," + bd.scale() + ")";
> }
> return value == null ? null : sqlType(value.getClass(), varcharSize);
> }
> {code}
> Patterns with instanceof is supported by javaparser:
> {code:groovy}
> @Test
> void testParseInstanceofPattern() {
> String code = """
> class A {
> public static String sqlType(Object value, int... varcharSize) {
> if (value instanceof BigDecimal bd) {
> return "DECIMAL(" + bd.precision() + "," + bd.scale() + ")";
> }
> return value == null ? null : sqlType(value.getClass(),
> varcharSize);
> }
> }
> """;
> ParserConfiguration config = new ParserConfiguration();
> config.setLanguageLevel(LanguageLevel.JAVA_17);
> JavaParser parser = new JavaParser(config);
> CompilationUnit cu = JavaParserAdapter.of(parser).parse(code);
> System.out.println(cu.toString());
> }
> {code}
> This might mean that the groovy gradle plugin is not setting the language
> level based on the tool chain e.g in my build.gradle, I have:
> {code:groovy}
> java {
> toolchain {
> languageVersion = JavaLanguageVersion.of(17)
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)