diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-17 18:46:20 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-17 21:55:03 +0800 |
commit | 6220c78031c8459be46d408242deb3865d4719a8 (patch) | |
tree | a1fd81cf8df5e20f8af48e6b4d37c69badc4bde0 /moduledefs | |
parent | 16e67cb248ba96fc3722561bcadbba27a2779a03 (diff) | |
download | mill-6220c78031c8459be46d408242deb3865d4719a8.tar.gz mill-6220c78031c8459be46d408242deb3865d4719a8.tar.bz2 mill-6220c78031c8459be46d408242deb3865d4719a8.zip |
tidy up root folder
Diffstat (limited to 'moduledefs')
-rw-r--r-- | moduledefs/resources/scalac-plugin.xml | 4 | ||||
-rw-r--r-- | moduledefs/src/mill/moduledefs/AutoOverridePlugin.scala | 58 | ||||
-rw-r--r-- | moduledefs/src/mill/moduledefs/Cacher.scala | 35 |
3 files changed, 0 insertions, 97 deletions
diff --git a/moduledefs/resources/scalac-plugin.xml b/moduledefs/resources/scalac-plugin.xml deleted file mode 100644 index 48753a22..00000000 --- a/moduledefs/resources/scalac-plugin.xml +++ /dev/null @@ -1,4 +0,0 @@ -<plugin> - <name>auto-override-plugin</name> - <classname>mill.moduledefs.AutoOverridePlugin</classname> -</plugin>
\ No newline at end of file diff --git a/moduledefs/src/mill/moduledefs/AutoOverridePlugin.scala b/moduledefs/src/mill/moduledefs/AutoOverridePlugin.scala deleted file mode 100644 index 5b33abbe..00000000 --- a/moduledefs/src/mill/moduledefs/AutoOverridePlugin.scala +++ /dev/null @@ -1,58 +0,0 @@ -package mill.moduledefs - -import scala.reflect.internal.Flags -import scala.tools.nsc.io.VirtualFile -import scala.tools.nsc.util.BatchSourceFile -import scala.tools.nsc.{Global, Phase} -import scala.tools.nsc.plugins.{Plugin, PluginComponent} - -class AutoOverridePlugin(val global: Global) extends Plugin { - import global._ - override def init(options: List[String], error: String => Unit): Boolean = true - - val name = "auto-override-plugin" - val description = "automatically inserts `override` keywords for you" - val components = List[PluginComponent]( - new PluginComponent { - - val global = AutoOverridePlugin.this.global - import global._ - - override val runsAfter = List("typer") - override val runsBefore = List("patmat") - - val phaseName = "auto-override" - - override def newPhase(prev: Phase) = new GlobalPhase(prev) { - - def name: String = phaseName - - def isCacher(owner: Symbol) = { - val baseClasses = - if (owner.isClass) Some(owner.asClass.baseClasses) - else if (owner.isModule) Some(owner.asModule.baseClasses) - else None - baseClasses.exists(_.exists(_.fullName == "mill.moduledefs.Cacher")) - } - - def apply(unit: global.CompilationUnit): Unit = { - object AutoOverrider extends global.Transformer { - override def transform(tree: global.Tree) = tree match{ - case d: DefDef - if d.symbol.overrideChain.count(!_.isAbstract) > 1 - && !d.mods.isOverride - && isCacher(d.symbol.owner) => - - d.symbol.flags = d.symbol.flags | Flags.OVERRIDE - copyDefDef(d)(mods = d.mods | Flags.OVERRIDE) - case _ => super.transform(tree) - - } - } - - unit.body = AutoOverrider.transform(unit.body) - } - } - } - ) -}
\ No newline at end of file diff --git a/moduledefs/src/mill/moduledefs/Cacher.scala b/moduledefs/src/mill/moduledefs/Cacher.scala deleted file mode 100644 index 023f03be..00000000 --- a/moduledefs/src/mill/moduledefs/Cacher.scala +++ /dev/null @@ -1,35 +0,0 @@ -package mill.moduledefs - -import scala.collection.mutable -import scala.reflect.macros.blackbox.Context - - -trait Cacher{ - private[this] lazy val cacherLazyMap = mutable.Map.empty[sourcecode.Enclosing, Any] - - protected[this] def cachedTarget[T](t: => T) - (implicit c: sourcecode.Enclosing): T = synchronized{ - cacherLazyMap.getOrElseUpdate(c, t).asInstanceOf[T] - } -} - -object Cacher{ - def impl0[T: c.WeakTypeTag](c: Context) - (t: c.Expr[T]): c.Expr[T] = { - c.Expr[T](wrapCached[T](c)(t.tree)) - } - def wrapCached[R: c.WeakTypeTag](c: Context)(t: c.Tree) = { - - import c.universe._ - val owner = c.internal.enclosingOwner - val ownerIsCacherClass = - owner.owner.isClass && - owner.owner.asClass.baseClasses.exists(_.fullName == "mill.moduledefs.Cacher") - - if (ownerIsCacherClass && owner.isMethod) q"this.cachedTarget[${weakTypeTag[R]}]($t)" - else c.abort( - c.enclosingPosition, - "T{} members must be defs defined in a Cacher class/trait/object body" - ) - } -}
\ No newline at end of file |