codingwell / scala-guice

Scala extensions for Google Guice
Apache License 2.0
341 stars 44 forks source link

Make implicit classes extend AnyVal and add a method to KeyExtensions #89

Closed cacoco closed 4 years ago

cacoco commented 4 years ago

Problem

This started as a desire to add another method to KeyExtensions:

def annotatedWith(clazz: Class[_ <: JAnnotation]): Key[T]

Solution

However, I noticed some low-hanging fruit that I thought it might be worth doing/fixing:

  1. make the implicit classes extend AnyVal, which means that we will not allocate any runtime objects, see: https://docs.scala-lang.org/overviews/core/value-classes.html. Implicit classes are generally very good candidates to make Value classes.
  2. prefer not to use arity-1 (infix notation) as per the Scala Style guide (we've had fun in the past tracking down bugs due to this): https://docs.scala-lang.org/style/method-invocation.html#arity-1-infix-notation.
  3. fix up scaladoc in BindingExtensions as it used javadoc syntax for code blocks.
  4. add return types on public members and methods (good practice in general, really good for libraries).
  5. finally, add the new method to KeyExtensions and add tests.
tsuckow commented 4 years ago

Be careful of .DS_Store files in the future

cacoco commented 4 years ago

Be careful of .DS_Store files in the future

Gah, yep. Sorry about that.