Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8273

JavaAwareCompilationUnit with array

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.4.7
    • Fix Version/s: None
    • Component/s: groovy-jdk, groovy-runtime
    • Labels:
      None

      Description

      I have the generated java class below with Array, when I try compile using JavaAwareCompilationUnit I receive the error:

      Error

      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)
      

      Generated class City.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>
       * &lt;complexType name="City"&gt;
       *   &lt;complexContent&gt;
       *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
       *       &lt;sequence&gt;
       *         &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
       *         &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
       *         &lt;element name="state" type="{http://message.geodata.me.com.br/}State" minOccurs="0"/&gt;
       *         &lt;element name="version" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/&gt;
       *       &lt;/sequence&gt;
       *     &lt;/restriction&gt;
       *   &lt;/complexContent&gt;
       * &lt;/complexType&gt;
       * </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;
          }
      
      }
      

      My method compilation

          @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();
              }
         }
      

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              assuncao.s Silvio Assuncao
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: