Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile failure on generated code #318

Closed
uwesimm opened this issue Apr 2, 2015 · 9 comments
Closed

compile failure on generated code #318

uwesimm opened this issue Apr 2, 2015 · 9 comments
Labels

Comments

@uwesimm
Copy link

uwesimm commented Apr 2, 2015

hi,

running scalaxb on the schema below leads to several issues. initially its that the generated code contains duplicated declarations for "attributes" such as the one below.

any hint ?

/uwe

case class MetricsPort(name: String,
  attributes: org.uwes.vplan2odf.vplanx.AttributesType,
  mappingPatterns: org.uwes.vplan2odf.vplanx.MappingPatterns,
  attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
  lazy val id = attributes.get("@id") map { _.as[String] }
}
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="expression">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute type="xs:string" name="local"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="elementName" type="xs:string"/>
  <xs:element name="annotationReference">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="spec"/>
        <xs:element ref="annotationId"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="hierarchies">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="hierarchy"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="ignoredLevel" type="xs:byte"/>
  <xs:element name="char" type="xs:string"/>
  <xs:element name="autoLoadSession">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute type="xs:string" name="sessionName" use="optional"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="planPath" type="xs:string"/>
  <xs:element name="settings">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="actualInstanceMappings"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="domains">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="domain"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="metricsTypes">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="block" minOccurs="0"/>
        <xs:element ref="expression" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="checksum" type="xs:int"/>
  <xs:element name="logicalInstanceName" type="xs:string"/>
  <xs:element name="annotation">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="header"/>
        <xs:element ref="trailer"/>
        <xs:element ref="ignoredLevel"/>
        <xs:element ref="glyphs" maxOccurs="unbounded" minOccurs="0"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="id" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="caseSensitivity" type="xs:string"/>
  <xs:element name="mappingPatterns">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="mappingPattern"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="height" type="xs:byte"/>
  <xs:element name="autoLoads">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="autoLoadSession" maxOccurs="unbounded" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="buildTime" type="xs:string"/>
  <xs:element name="value" type="xs:string"/>
  <xs:element name="pageNumber" type="xs:byte"/>
  <xs:element name="verificationScope" type="xs:string"/>
  <xs:element name="metaData">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="planId"/>
        <xs:element ref="sourceTool"/>
        <xs:element ref="toolVersion"/>
        <xs:element ref="schemaVersion"/>
        <xs:element ref="buildTime"/>
        <xs:element ref="autoLoads"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="id"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="rootElements">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="section"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="actualInstance" type="xs:string"/>
  <xs:element name="toolVersion" type="xs:float"/>
  <xs:element name="declaredPlanId" type="xs:string"/>
  <xs:element name="width" type="xs:byte"/>
  <xs:element name="annotationId" type="xs:string"/>
  <xs:element name="dotResolve" type="xs:string"/>
  <xs:element name="header" type="xs:string"/>
  <xs:element name="planElementReference">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="plan"/>
        <xs:element ref="elementPaths"/>
        <xs:element ref="settings"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="id" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="actualInstanceMapping">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="logicalInstanceName"/>
        <xs:element ref="declaredPlanId"/>
        <xs:element ref="actualInstances"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="fileName" type="xs:string"/>
  <xs:element name="specs">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="spec"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="spec">
    <xs:complexType mixed="true">
      <xs:sequence>
        <xs:element ref="fileName" minOccurs="0"/>
        <xs:element ref="checksum" minOccurs="0"/>
        <xs:element ref="annotation" maxOccurs="unbounded" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="trailer" type="xs:string"/>
  <xs:element name="actualInstances">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="actualInstanceInfo"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="attribute">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="value"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="block">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute type="xs:string" name="local"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="sourceTool" type="xs:string"/>
  <xs:element name="name" type="xs:string"/>
  <xs:element name="domain" type="xs:string"/>
  <xs:element name="hierarchy" type="xs:string"/>
  <xs:element name="metricsPort">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="attributes"/>
        <xs:element ref="mappingPatterns"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="id" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="actualInstanceMappings">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="actualInstanceMapping"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="planId" type="xs:string"/>
  <xs:element name="section">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="attributes" minOccurs="0"/>
        <xs:element ref="annotationReference" maxOccurs="unbounded" minOccurs="0"/>
        <xs:element ref="subElements" minOccurs="0"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="id" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="mappingPattern">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="domains" minOccurs="0"/>
        <xs:element ref="hierarchies" minOccurs="0"/>
        <xs:element ref="metricsTypes" minOccurs="0"/>
        <xs:element ref="pattern"/>
        <xs:element ref="dotResolve"/>
        <xs:element ref="caseSensitivity"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="id" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="glyphs">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="pageNumber"/>
        <xs:element ref="x"/>
        <xs:element ref="y"/>
        <xs:element ref="width"/>
        <xs:element ref="height"/>
        <xs:element ref="char"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="elementPaths">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="elementPath"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="plan">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="planId"/>
        <xs:element ref="planPath"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="pattern" type="xs:string"/>
  <xs:element name="actualInstanceInfo">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="actualInstance"/>
        <xs:element ref="verificationScope"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="elementPath">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="elementName"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="subElements">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="planElementReference" minOccurs="0"/>
        <xs:element ref="section" maxOccurs="unbounded" minOccurs="0"/>
        <xs:element ref="metricsPort" maxOccurs="unbounded" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="attributes">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="attribute" maxOccurs="unbounded" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="schemaVersion" type="xs:float"/>
  <xs:element name="y" type="xs:short"/>
  <xs:element name="x" type="xs:short"/>
</xs:schema>
@eed3si9n
Copy link
Owner

eed3si9n commented Apr 2, 2015

Try param prefix to work around it.

@uwesimm
Copy link
Author

uwesimm commented Apr 2, 2015

hi,

adding –param is adding a prefix to every member. so that doesn’t solve the issue.

case class MetricsPortType(param_name: String,
param_attributes: org.uwes.vplan2odf.vplanx.AttributesType,
param_mappingPatterns: org.uwes.vplan2odf.vplanx.MappingPatternsType,
param_attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
lazy val param_id = param_attributes.get("@id") map { _.as[String] }
}

From: eugene yokota [mailto:notifications@github.com]
Sent: Thursday, April 02, 2015 3:43 PM
To: eed3si9n/scalaxb
Cc: Uwe Simm
Subject: Re: [scalaxb] compile failure on generated code (#318)

Try param prefix to work around it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/318#issuecomment-88905328.

@eed3si9n
Copy link
Owner

eed3si9n commented Apr 2, 2015

It's a bug of scalaxb it seems.

@etitov
Copy link
Contributor

etitov commented Feb 19, 2021

hi,
I have the same problem.

The problem can be solved

  1. change ATTRS_PARAM to "tagАttributes" or whatever
  2. make ATTRS_PARAM parameterized
  3. scalaxbAttributePrefix affects the renaming of ATTRS_PARAM in generated code

I can fix it. What to choose?

@eed3si9n
Copy link
Owner

Whatever works is fine by me. 3 sounds least surprising?

@etitov
Copy link
Contributor

etitov commented Feb 24, 2021

when set scalaxbAttributePrefix := Some("a_")

case class MetricsPort(name: String,
  attributes: org.uwes.vplan2odf.vplanx.AttributesType,
  mappingPatterns: org.uwes.vplan2odf.vplanx.MappingPatterns,
  a_attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
  lazy val a_id = a_attributes.get("@id") map { _.as[String] }
}

but now the parameter only affects class variables like id
I will try to make a pull request with 2 or 3 options

@etitov
Copy link
Contributor

etitov commented Mar 4, 2021

the problem can be solved by the parameter scalaxbNamedAttributes := true

case class MetricsPort(name: String,
  attributes: org.uwes.vplan2odf.vplanx.AttributesType,
  mappingPatterns: org.uwes.vplan2odf.vplanx.MappingPatterns,
  id: Option[String] = None)

@eed3si9n
Copy link
Owner

eed3si9n commented Mar 4, 2021

I don't remember why I defaulted that to be false. I vaguely remember they merge in some unpredictable way when types extend one another. Maybe it's also to do with the whole 22 limit thing. Either way, it's good to know of a workaround when it works though.

@eed3si9n
Copy link
Owner

Fixed by @etitov in #558

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants