summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/plugins
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-05-23 12:58:15 +0000
committerLex Spoon <lex@lexspoon.org>2007-05-23 12:58:15 +0000
commit377310315a9c3ceac5cd86a62983ed932e363a4f (patch)
treee98b7c5a46fd20ec0ce3896d6e427cb305fa21f1 /src/compiler/scala/tools/nsc/plugins
parentc5b9e36ca3e2a2f26ba6308ef5bf15b0dad46d14 (diff)
downloadscala-377310315a9c3ceac5cd86a62983ed932e363a4f.tar.gz
scala-377310315a9c3ceac5cd86a62983ed932e363a4f.tar.bz2
scala-377310315a9c3ceac5cd86a62983ed932e363a4f.zip
*** empty log message ***
Diffstat (limited to 'src/compiler/scala/tools/nsc/plugins')
-rw-r--r--src/compiler/scala/tools/nsc/plugins/PluginDescription.scala99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
new file mode 100644
index 0000000000..4e3088b829
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
@@ -0,0 +1,99 @@
+package scala.tools.nsc.plugins
+import scala.xml.{Node,NodeSeq}
+import java.io.File
+
+/** A description of a compiler plugin.
+ *
+ * @author Lex Spoon
+ * @version 1.0, 2007-5-21
+ */
+abstract class PluginDescription {
+ /** A short name of the compiler, used to identify it in
+ * various contexts. The phase defined by the plugin
+ * should have the same name. */
+ val name: String
+
+ /** The name of the main class for the plugin */
+ val classname: String
+
+ /** The phase that this plugin should run after. It can
+ * be the name of another plugin. */
+ val runsAfter: String
+
+ /** A one-line description of the plugin, suitable for
+ * a -help listing. */
+ val description: Option[String]
+
+ /** A URL to get more information about the plugin */
+ val homepage: Option[String]
+
+ /** An XML representation of this description. It can be
+ * read back using PluginDescription.fromXML . It should
+ * be stored inside the jor. */
+ def toXML: Node = {
+ def ifSome(field: Option[String], handler: String=>Node): NodeSeq =
+ field match {
+ case None => NodeSeq.Empty
+ case Some(str) => handler(str)
+ }
+
+ <plugin>
+ <name>{name}</name>
+ <classname>{classname}</classname>
+ <after>{runsAfter}</after>
+ {ifSome(description, desc =>
+ <description>{desc}</description>)}
+ {ifSome(homepage, url =>
+ <homepage>{url}</homepage>)}
+ </plugin>
+ }
+}
+
+
+
+/** Utilities for the PluginDescription class.
+ *
+ * @author Lex Spoon
+ * @version 1.0, 2006-5-21
+ */
+object PluginDescription {
+ def fromXML(xml: Node): Option[PluginDescription] = {
+ // check the top-level tag
+ xml match {
+ case <plugin>_*</plugin> => ()
+ case _ => None
+ }
+
+ /** Extract one field */
+ def getField(field: String): Option[String] = {
+ val text = (xml \\ field).text.trim
+ if (text == "") None else Some(text)
+ }
+
+ // extract the required fields
+ val name1 = getField("name") match {
+ case None => return None
+ case Some(str) => str
+ }
+ val classname1 = getField("classname") match {
+ case None => return None
+ case Some(str) => str
+ }
+ val runsAfter1 = getField("after") match {
+ case None => return None
+ case Some(str) => str
+ }
+
+ // extract the optional fields
+ val homepage1 = getField("homepage")
+ val description1 = getField("description")
+
+ Some(new PluginDescription {
+ val name = name1
+ val classname = classname1
+ val runsAfter = runsAfter1
+ val homepage = homepage1
+ val description = description1
+ })
+ }
+}