You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Silvio Assuncao (JIRA)" <ji...@apache.org> on 2017/07/31 13:48:01 UTC
[jira] [Created] (GROOVY-8273) JavaAwareCompilationUnit with array
Silvio Assuncao created GROOVY-8273:
---------------------------------------
Summary: JavaAwareCompilationUnit with array
Key: GROOVY-8273
URL: https://issues.apache.org/jira/browse/GROOVY-8273
Project: Groovy
Issue Type: Bug
Components: groovy-jdk, groovy-runtime
Affects Versions: 2.4.7
Reporter: Silvio Assuncao
I have the generated java class below with Array, when I try compile using JavaAwareCompilationUnit I receive the error:
{code:java}
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
br/com/me/geodata/message/City.java: 33: unexpected token: id @ line 33, column 5.org.codehaus.groovy.syntax.SyntaxException: unexpected token: id @ line 33, column 5.
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:143)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:111)
{code}
City.java
{code:java}
package br.com.me.geodata.message;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for City complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="City">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="state" type="{http://message.geodata.me.com.br/}State" minOccurs="0"/>
* <element name="version" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "City", propOrder = {
"id",
"name",
"state",
"version"
})
public class City {
protected String id;
protected String name;
protected State state;
protected Integer version;
/**
* Gets the value of the id property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getId() {
return id;
}
/**
* Sets the value of the id property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setId(String value) {
this.id = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the state property.
*
* @return
* possible object is
* {@link State }
*
*/
public State getState() {
return state;
}
/**
* Sets the value of the state property.
*
* @param value
* allowed object is
* {@link State }
*
*/
public void setState(State value) {
this.state = value;
}
/**
* Gets the value of the version property.
*
* @return
* possible object is
* {@link Integer }
*
*/
public Integer getVersion() {
return version;
}
/**
* Sets the value of the version property.
*
* @param value
* allowed object is
* {@link Integer }
*
*/
public void setVersion(Integer value) {
this.version = value;
}
}
{code}
{code:java}
@Override
public List<CompiledCode> compile(DynamicClassLoader classLoader, List<SourceCode> sourceCodes) throws CantCompileException {
File tempDir = createTempDir();
try {
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.setDebug(true);
configuration.setTargetBytecode(CompilerConfiguration.JDK8);
Map<String, Object> compilationOptions = new HashMap<>();
compilationOptions.put("jointCompilation", true);
compilationOptions.put("stubDir", tempDir);
configuration.setJointCompilationOptions(compilationOptions);
JavaAwareCompilationUnit javaCompilerUnit = new JavaAwareCompilationUnit(configuration, classLoader);
for (SourceCode sourceCode : sourceCodes) {
javaCompilerUnit.addSource(sourceCode.getCanonicalPath(), new ByteArrayInputStream(sourceCode.getCode()));
}
javaCompilerUnit.setCompilerFactory(new JavacCompilerFactory());
javaCompilerUnit.compile();
List<GroovyClass> groovyClassList = javaCompilerUnit.getClasses();
return groovyClassList.stream()
.map(d -> new CompiledCode(d.getName(), null, d.getBytes()))
.collect(Collectors.toList());
} finally {
tempDir.delete();
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)