aboutsummaryrefslogtreecommitdiff
path: root/libraries/common-1/common_1.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-20 22:09:38 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-27 19:56:13 -0400
commitbba2abe7ee38b8903822a07578c46466923d13ed (patch)
treea357fb8def6f58a9ea9a37411f3f5640dcb525fe /libraries/common-1/common_1.scala
parentd2f8cade709b7d55a93e18592b6e38247d648ca9 (diff)
downloadcbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.gz
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.bz2
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.zip
start modularizing cbt into libraries
this extracts certain parts of cbt into stand-alone libraries, which can be published to maven and used outside of cbt. This also adds scalariform for these parts of the code. This slows down cbt’s own build a lot because of the number of projects involved! So we’ll follow this by a bunch of performance tweak commits.
Diffstat (limited to 'libraries/common-1/common_1.scala')
-rw-r--r--libraries/common-1/common_1.scala34
1 files changed, 34 insertions, 0 deletions
diff --git a/libraries/common-1/common_1.scala b/libraries/common-1/common_1.scala
new file mode 100644
index 0000000..66da224
--- /dev/null
+++ b/libraries/common-1/common_1.scala
@@ -0,0 +1,34 @@
+package cbt.common_1
+import cbt.ExitCode
+object `package` extends Module {
+ implicit class CbtExitCodeOps( val exitCode: ExitCode ) extends AnyVal with ops.CbtExitCodeOps
+ implicit class TypeInferenceSafeEquals[T]( val value: T ) extends AnyVal with ops.TypeInferenceSafeEquals[T]
+ implicit class CbtBooleanOps( val condition: Boolean ) extends AnyVal with ops.CbtBooleanOps
+ implicit class CbtStringOps( val string: String ) extends AnyVal with ops.CbtStringOps
+}
+
+package ops {
+ trait CbtExitCodeOps extends Any {
+ def exitCode: ExitCode
+ def ||( other: => ExitCode ) = if ( exitCode == ExitCode.Success ) exitCode else other
+ def &&( other: => ExitCode ) = if ( exitCode != ExitCode.Success ) exitCode else other
+ }
+ trait TypeInferenceSafeEquals[T] extends Any {
+ def value: T
+ /** if you don't manually upcast, this will catch comparing different types */
+ def ===( other: T ) = value == other
+ def =!=( other: T ) = value != other // =!= instead of !==, because it has better precedence
+ }
+ trait CbtBooleanOps extends Any {
+ def condition: Boolean
+ def option[T]( value: => T ): Option[T] = if ( condition ) Some( value ) else None
+ }
+ trait CbtStringOps extends Any {
+ def string: String
+ def escape = string.replace( "\\", "\\\\" ).replace( "\"", "\\\"" )
+ def quote = s""""$escape""""
+ def ~( right: String ): String = string + right
+ }
+}
+
+trait Module