Permalink
Browse files

Scalaxy/Privacy: updated readme and created phony annotations package…

… (plugin now in scalaxy-privacy-plugin)
  • Loading branch information...
1 parent d845f4a commit c343d369084bebf61097b717fc43633bf09b9a29 @ochafik ochafik committed Feb 25, 2014
@@ -4,7 +4,10 @@ scalaVersion := "2.10.3"
autoCompilerPlugins := true
// Scalaxy/Privacy plugin
-addCompilerPlugin("com.nativelibs4java" %% "scalaxy-privacy" % "0.3-SNAPSHOT")
+addCompilerPlugin("com.nativelibs4java" %% "scalaxy-privacy-plugin" % "0.3-SNAPSHOT")
+
+// Scalaxy/Privacy annotations are only needed to avoid confusing IDEs.
+libraryDependencies += "com.nativelibs4java" %% "scalaxy-privacy" % "0.3-SNAPSHOT"
// Ensure Scalaxy/Privacy's plugin is used.
scalacOptions += "-Xplugin-require:scalaxy-privacy"
@@ -0,0 +1,7 @@
+private[this] class Foo
+
+object Run extends App {
+
+
+ println(new Foo)
+}
@@ -29,6 +29,10 @@ class ExplicitTypeAnnotationsTest extends TestBase {
def f = 10
def ff: Int = f
+ def unit {
+ // booh
+ }
+
val v = 10
val vv: Int = v
}
View
@@ -1,16 +1,35 @@
# Scalaxy/Privacy
-Compiler plugin that changes default privacy of vals, vars and defs to private, unless `@public` is used.
+Compiler plugin that changes default privacy of vals, vars and defs to private, unless `@public` is used, and warns about non-trivial public defs and vals that lack type annotations.
This is only at the **early stages of experimentation**, and since it **may alter the Scala semantics** of your code, well... you've been warned :-)
```scala
-object Foo {
+@public object Foo {
+ // Any val, def, class or object not marked with @public is assumed to be private[this].
val privateByDefault = 10
+
+ // The @public annotation is removed by the compiler plugin.
@public val explicitlyPublic = 12
+
+ // Warning: public `f` method has a non-trivial return type without type annotation.
+ @public def f(x: Int) = if (x < 0) "1" else 2
+
+ // Ok.
+ @public def g(x: Int): Int = f(x)
+}
+
+println(Foo.privateByDefault) // Error: Scalaxy/Privacy make that one private[this].
+println(Foo.explicitlyPublic) // Ok.
+
+// Regular Scala visibility rules apply within elements tagged with @noprivacy
+@noprivacy object Bar {
+ val publicByDefault = 10
+ private val explicitlyPrivate = 12
}
-println(Foo.privateByDefault) // Error: Scalaxy/Privacy turned that one private.
+println(Foo.publicByDefault) // Ok.
+println(Foo.explicitlyPrivate) // Error.
```
# Usage
@@ -22,7 +41,7 @@ scalaVersion := "2.10.3"
autoCompilerPlugins := true
// Scalaxy/Privacy plugin
-addCompilerPlugin("com.nativelibs4java" %% "scalaxy-privacy" % "0.3-SNAPSHOT")
+addCompilerPlugin("com.nativelibs4java" %% "scalaxy-privacy-plugin" % "0.3-SNAPSHOT")
// Ensure Scalaxy/Privacy's plugin is used.
scalacOptions += "-Xplugin-require:scalaxy-privacy"
@@ -45,14 +64,14 @@ If you want to build / test / hack on this project:
```
git clone git://github.com/ochafik/Scalaxy.git
cd Scalaxy
- sbt "project scalaxy-privacy" "; clean ; ~test"
+ sbt "project scalaxy-privacy-plugin" "; clean ; ~test"
```
- Test with:
```
git clone git://github.com/ochafik/Scalaxy.git
cd Scalaxy
- sbt "project scalaxy-privacy" "run examples/Test.scala"
+ sbt "project scalaxy-privacy-plugin" "run examples/Test.scala"
```
- You can also use plain `scalac` directly, once Scalaxy/Privacy's JAR is cached by sbt / Ivy:
@@ -62,6 +81,6 @@ If you want to build / test / hack on this project:
cd Scalaxy
sbt update
cd Privacy
- scalac -Xplugin:$HOME/.ivy2/cache/com.nativelibs4java/scalaxy-privacy_2.10/jars/scalaxy-privacy_2.10-0.3-SNAPSHOT.jar examples/Test.scala
+ scalac -Xplugin:$HOME/.ivy2/cache/com.nativelibs4java/scalaxy-privacy-plugin_2.10/jars/scalaxy-privacy-plugin_2.10-0.3-SNAPSHOT.jar examples/Test.scala
scalac examples/Test.scala
```
@@ -0,0 +1 @@
+class noprivacy extends scala.annotation.StaticAnnotation
@@ -0,0 +1 @@
+class public extends scala.annotation.StaticAnnotation
@@ -178,7 +178,7 @@ object Scalaxy extends Build {
settings =
standardSettings ++
Seq(publish := { }))
- .aggregate(integration, loops, compilets, fx, json, beans, components, debug, extensions, reified, scalaxyDoc, parano, privacy)
+ .aggregate(integration, loops, compilets, fx, json, beans, components, debug, extensions, reified, scalaxyDoc, parano, privacyPlugin)
lazy val integration =
Project(
@@ -187,7 +187,7 @@ object Scalaxy extends Build {
settings =
standardSettings ++
Seq(publish := { }))
- .dependsOn(loops, compilets, fx, json, beans, components, debug, extensions, reified, parano, privacy)
+ .dependsOn(loops, compilets, fx, json, beans, components, debug, extensions, reified, parano, privacyPlugin)
lazy val docProjects = Map(
// "Compilets" -> compilets,
@@ -380,10 +380,18 @@ object Scalaxy extends Build {
scalacOptions in console in Compile <+= (packageBin in Compile) map("-Xplugin:" + _)
))
+ lazy val privacyPlugin =
+ Project(id = "scalaxy-privacy-plugin", base = file("Privacy/Plugin"),
+ settings = reflectSettings ++ scalariformSettings ++ Seq(
+ watchSources <+= baseDirectory map { _ / "examples" },
+ scalacOptions in console in Compile <+= (packageBin in Compile) map("-Xplugin:" + _)
+ ))
+ .dependsOn(privacy)
+ .aggregate(privacy)
+
lazy val privacy =
Project(id = "scalaxy-privacy", base = file("Privacy"),
settings = reflectSettings ++ scalariformSettings ++ Seq(
- watchSources <+= baseDirectory map { _ / "examples" },
scalacOptions in console in Compile <+= (packageBin in Compile) map("-Xplugin:" + _)
))

0 comments on commit c343d36

Please sign in to comment.