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

Support unboxing of mojo parameters. #18

Merged
merged 1 commit into from
Apr 2, 2013
Merged

Support unboxing of mojo parameters. #18

merged 1 commit into from
Apr 2, 2013

Conversation

argv-minus-one
Copy link
Contributor

Currently, the scala-mojo-support code throws an exception if it encounters a mojo parameter with a primitive type.

This change adds support for unboxing, by simply stripping out the offending type check. I did this because:

  • Maven already knows what the correct type is for each parameter, because it is listed in the plugin descriptor.
  • Java reflection handles unboxing automatically.
  • Java reflection will throw an exception itself, in the unlikely event that Maven hands us a value with the wrong type.

This change also adds handling for Maven passing a null value to a parameter with a primitive type. I don't think it will ever do this, but in case it does, scala-mojo-support will now react by resetting the var to the default value for its primitive type (0 for integers, floats, and characters, and false for Boolean).

*
* See the Java Language Specification, Java SE 7 Edition, §4.12.5 "Initial Values of Variables".
*/
private val boxedDefaultValues = scala.collection.immutable.Map[Class[_], AnyRef](
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW - null.asInstanceOf[PrimitiveType] in scala gives you the default, although it's kind of hacky. This is way better.

@jsuereth
Copy link
Owner

jsuereth commented Apr 2, 2013

LGTM. Thanks for the fix!

jsuereth added a commit that referenced this pull request Apr 2, 2013
…arams

Support unboxing of mojo parameters.
@jsuereth jsuereth merged commit 8de0ec7 into jsuereth:master Apr 2, 2013
@argv-minus-one argv-minus-one deleted the support-unboxing-in-mojo-params branch April 4, 2013 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants