eed3si9n / scalaxb

scalaxb is an XML data binding tool for Scala.
http://scalaxb.org/
MIT License
337 stars 156 forks source link

Lots of warnings in generated output #224

Open mmc41 opened 11 years ago

mmc41 commented 11 years ago

I got lots of warnings when compiling generated code from an XSD file using mavens scalaxb pluging (btw: nice plugin!) and latest scala version. For people (like me) that leans towards a no-warning policy this makes use of scalaxb problematic:

WARNING] test/target/generated-sources/scalaxb/com/test/plugins/xmlprotocol.scala:194: warning: postfix operator get should be enabled
[WARNING] by making the implicit value scala.language.postfixOps visible.
[WARNING] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[WARNING] or by setting the compiler option -language:postfixOps.
[WARNING] See the Scala docs for value scala.language.postfixOps for a discussion
[WARNING] why the feature should be explicitly enabled.
[WARNING]       (Some(__obj.groupoption) map {x => scalaxb.toXML[scalaxb.DataRecord[com.test.plugins.GroupOption]](x, x.namespace, x.key, __scope, false)} get)
[WARNING]                                                                                                                                                               ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:219: warning: postfix operator orNull should be enabled
[WARNING] by making the implicit value scala.language.postfixOps visible.
[WARNING]           Right(new QName(namespace orNull, localPart))
[WARNING]                                     ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:821: warning: postfix operator != should be enabled
[WARNING] by making the implicit value scala.language.postfixOps visible.
[WARNING]   def splitBySpace(text: String) = text.split(' ').filter("" !=)
[WARNING]                                                              ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:371: warning: inferred existential type Option[(Option[String], Option[String], Option[String], Option[String], A, scalaxb.CanWriteXML[_$1])] forSome { type _$1 }, which cannot be expressed by wildcards,  should be enabled
[WARNING] by making the implicit value scala.language.existentials visible.
[WARNING] This can be achieved by adding the import clause 'import scala.language.existentials'
[WARNING] or by setting the compiler option -language:existentials.
[WARNING] See the Scala docs for value scala.language.existentials for a discussion
[WARNING] why the feature should be explicitly enabled.
[WARNING]   private case class DataWriter[+A](
[WARNING]                      ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:599: warning: implicit conversion method apply should be enabled
[WARNING] by making the implicit value scala.language.implicitConversions visible.
[WARNING] This can be achieved by adding the import clause 'import scala.language.implicitConversions'
[WARNING] or by setting the compiler option -language:implicitConversions.
[WARNING] See the Scala docs for value scala.language.implicitConversions for a discussion
[WARNING] why the feature should be explicitly enabled.
[WARNING]   implicit def apply(node: scala.xml.Node): ElemName = node match {
[WARNING]                ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:610: warning: implicit conversion method toNodeSeq should be enabled
[WARNING] by making the implicit value scala.language.implicitConversions visible.
[WARNING]   implicit def toNodeSeq(elem: ElemName): scala.xml.NodeSeq = elem.node
[WARNING]                ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:617: warning: implicit conversion method toNodeSeq should be enabled
[WARNING] by making the implicit value scala.language.implicitConversions visible.
[WARNING]   implicit def toNodeSeq(elem: Elem): scala.xml.NodeSeq = elem.node
[WARNING]                ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:273: warning: method apply in object Elem is deprecated: Use the other apply method in this object
[WARNING]           Right(xs map { x => fromXML[A](scala.xml.Elem(node.prefix, node.label, scala.xml.Null, node.scope, scala.xml.Text(x)), stack) })
[WARNING]                                                    ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:637: warning: method apply in object Elem is deprecated: Use the other apply method in this object
[WARNING]     val elem =  scala.xml.Elem(Helper.getPrefix(namespace, scope).orNull,
[WARNING]                           ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:817: warning: method apply in object Elem is deprecated: Use the other apply method in this object
[WARNING]     scala.xml.Elem(getPrefix(namespace, scope).orNull, elementLabel,
[WARNING]               ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:862: warning: method apply in object Elem is deprecated: Use the other apply method in this object
[WARNING]       scala.xml.Elem(getPrefix(namespace, scope).orNull, label,
[WARNING]                 ^
[WARNING] test/target/generated-sources/scalaxb/scalaxb/scalaxb.scala:915: warning: method apply in object Elem is deprecated: Use the other apply method in this object
[WARNING]           Elem(prefix, label, attr remove("href"), scope, lookupRef((x \ "@href").text.tail): _*)
[WARNING]           ^
[WARNING] 12 warnings found
eed3si9n commented 11 years ago

Thanks for the feedback. The problem with writing code generator like scalaxb is that I need to target the oldest Scala version that would be useful to provide. For the current scalaxb, that's Scala 2.9.x.

I didn't check all the warning above, but the most look like SIP-18 warnings and deprecation on Elem.apply, both something new to 2.10. You should be able to suppress SIP-18 by using -language:_ flag.

To avoid this, I would need to release a new version of scalaxb that targets 2.10, or introduce an option so it could generate either.

mmc41 commented 11 years ago

Thanks for looking at my issue and for explaining. If I try to supress the warnings as you suggested I only get 5 warnings and besides I am not so happy with supressing warnings as it impacts other files as well where I need to observe if any warnings occur. I hope that you will support 2.10 (with no warnings) in the future as I can't move my current java code to scala until then. Anyway, thanks for a great promising project with apart from this issue looks very good. Look forward to revisit it again at a later time.

francisdb commented 11 years ago

+1 for an option that enables different code generation for 2.10+

carl297r commented 10 years ago

+1 for an option that enables different code generation for 2.10+. (Other than that, I've had no issues so far and found it very useful indeed.)

eed3si9n commented 10 years ago

scalaxb 1.2.0 dropped support for Scala 2.9 and I think I now use Elem constructor for 2.10. I probably should check what else warnings show up.

carl297r commented 10 years ago

FYI, I am using scalaxb 1.2.1 and I get the following warnings below in scalaxb.scala. Perhaps they could be addressed if you include the following imports:

import scala.language.postfixOps
import scala.language.implicitConversions
import scala.language.existentials

I put these into scalaxb.scala by hand and it did the trick for me. (Of course that's not really a solution but shows what needs to be done). Thanks for scalaxb. This is a minor thing but hopefully easy to address.

Warning:(219, 37) postfix operator orNull should be enabled
by making the implicit value scala.language.postfixOps visible.
This can be achieved by adding the import clause 'import scala.language.postfixOps'
or by setting the compiler option -language:postfixOps.
See the Scala docs for value scala.language.postfixOps for a discussion
why the feature should be explicitly enabled.
          Right(new QName(namespace orNull, localPart))
                                    ^
Warning:(853, 62) postfix operator != should be enabled
by making the implicit value scala.language.postfixOps visible.
  def splitBySpace(text: String) = text.split(' ').filter("" !=)
                                                             ^
Warning:(371, 22) inferred existential type Option[(Option[String], Option[String], Option[String], Option[String], A, scalaxb.CanWriteXML[_$1])] forSome { type _$1 }, which cannot be expressed by wildcards,  should be enabled
by making the implicit value scala.language.existentials visible.
This can be achieved by adding the import clause 'import scala.language.existentials'
or by setting the compiler option -language:existentials.
See the Scala docs for value scala.language.existentials for a discussion
why the feature should be explicitly enabled.
  private case class DataWriter[+A](
                     ^
Warning:(599, 16) implicit conversion method apply should be enabled
by making the implicit value scala.language.implicitConversions visible.
This can be achieved by adding the import clause 'import scala.language.implicitConversions'
or by setting the compiler option -language:implicitConversions.
See the Scala docs for value scala.language.implicitConversions for a discussion
why the feature should be explicitly enabled.
  implicit def apply(node: scala.xml.Node): ElemName = node match {
               ^
Warning:(610, 16) implicit conversion method toNodeSeq should be enabled
by making the implicit value scala.language.implicitConversions visible.
  implicit def toNodeSeq(elem: ElemName): scala.xml.NodeSeq = elem.node
               ^
Warning:(619, 16) implicit conversion method toNodeSeq should be enabled
by making the implicit value scala.language.implicitConversions visible.
  implicit def toNodeSeq(elem: Elem): scala.xml.NodeSeq = elem.node
               ^
lespea commented 10 years ago

In one of the wsdl files I'm parsing I'm getting a ton of Option.headOption is not recommended warnings... which makes sense as it's redundant. I can't really share the wsdl as it's private unfortunately. If you need me to dig into this a bit more to find out why it's doing this I can but it might be tricky for me.

eed3si9n commented 10 years ago

Calls to headOption are likely generated by Args.scala - https://github.com/eed3si9n/scalaxb/blob/1c6f4fbc6e551ffdb25cb26686430eb34f06e7d7/cli/src/main/scala/scalaxb/compiler/xsd/Args.scala#L55-L103

lespea commented 10 years ago

Also seeing a few "Using toString on something that is already of type String"