diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-12-28 09:09:39 +0100 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-12-28 09:09:39 +0100 |
commit | a84c09efcb2d843ee04ee3299ceb592a00a42267 (patch) | |
tree | f0fd2cf8cadd7bc4bf91ebd31bd41d34a170a7f3 /scalatex/compilerPlugin | |
parent | 7d14b23dbbdaf66b222839874a29fff4a34e1762 (diff) | |
download | hands-on-scala-js-a84c09efcb2d843ee04ee3299ceb592a00a42267.tar.gz hands-on-scala-js-a84c09efcb2d843ee04ee3299ceb592a00a42267.tar.bz2 hands-on-scala-js-a84c09efcb2d843ee04ee3299ceb592a00a42267.zip |
wip
Diffstat (limited to 'scalatex/compilerPlugin')
-rwxr-xr-x | scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml | 4 | ||||
-rwxr-xr-x | scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala | 79 |
2 files changed, 0 insertions, 83 deletions
diff --git a/scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml b/scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml deleted file mode 100755 index a446f13..0000000 --- a/scalatex/compilerPlugin/src/main/resources/scalac-plugin.xml +++ /dev/null @@ -1,4 +0,0 @@ -<plugin> - <name>demo-plugin</name> - <classname>scalatex.CompilerPlugin</classname> -</plugin>
\ No newline at end of file diff --git a/scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala b/scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala deleted file mode 100755 index e122de5..0000000 --- a/scalatex/compilerPlugin/src/main/scala/scalatex/CompilerPlugin.scala +++ /dev/null @@ -1,79 +0,0 @@ -package scalatex - -import java.nio.file.Paths - -import scala.reflect.internal.util.BatchSourceFile -import scala.reflect.io.VirtualFile -import scala.tools.nsc.{ Global, Phase } -import scala.tools.nsc.plugins.{ Plugin, PluginComponent } - -class CompilerPlugin(val global: Global) extends Plugin { - import global._ - - override def init(options: List[String], error: String => Unit): Boolean = true - - val name = "scalatex" - val description = "Compiles scalatex files into Scala compilation units" - val components = List[PluginComponent](DemoComponent) - private object DemoComponent extends PluginComponent { - - val global = CompilerPlugin.this.global - import global._ - - override val runsAfter = List("parser") - override val runsBefore = List("namer") - - val phaseName = "Demo" - - override def newPhase(prev: Phase) = new GlobalPhase(prev) { - val splitOptions = options.map(o => o.splitAt(o.indexOf(":")+1)) - val scalatexRoots = splitOptions.collect{case ("root:", p) => p} - override def run() = { - def recursiveListFiles(f: java.io.File): Iterator[java.io.File] = { - val (dirs, files) = - Option(f.listFiles()) - .toSeq - .flatten - .partition(_.isDirectory) - files.iterator ++ dirs.iterator.flatMap(recursiveListFiles) - } - for { - scalatexRoot <- scalatexRoots - file <- recursiveListFiles(new java.io.File(scalatexRoot)) - } { - val name = file.getCanonicalPath - val fakeJfile = new java.io.File(name) - val txt = io.Source.fromFile(name).mkString - val virtualFile = new VirtualFile(name) { - override def file = fakeJfile - } - val sourceFile = new BatchSourceFile(virtualFile, txt) - val unit = new CompilationUnit(sourceFile) - val objectName = name.slice(name.lastIndexOf('/')+1, name.lastIndexOf('.')) - val pkgName = - Paths.get(scalatexRoot) - .relativize(fakeJfile.getParentFile.toPath) - .toString - .split("/") - .map(s => s"package $s") - .mkString("\n") - - val shim = s""" - $pkgName - import scalatags.Text.all._ - - object $objectName{ - def apply() = scalatex.twf("${name}") - } - """ - unit.body = global.newUnitParser(shim).parse() - global.currentRun.compileLate(unit) - } - } - - def name: String = phaseName - - def apply(unit: global.CompilationUnit): Unit = {} - } - } -} |