diff options
author | michelou <michelou@epfl.ch> | 2011-09-25 17:06:54 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2011-09-25 17:06:54 +0000 |
commit | 5d5826812ae66b748342d86c5185e9bf7612fe7f (patch) | |
tree | d7d41146c5391c6963b50668d872ddb82b14d8e4 /src/compiler/scala/tools/nsc/plugins | |
parent | 3e24f4c48d39681b948836f70f58a84f02fb76e2 (diff) | |
download | scala-5d5826812ae66b748342d86c5185e9bf7612fe7f.tar.gz scala-5d5826812ae66b748342d86c5185e9bf7612fe7f.tar.bz2 scala-5d5826812ae66b748342d86c5185e9bf7612fe7f.zip |
updated man pages, fixed svn props, did some cl...
updated man pages, fixed svn props, did some cleanup
Diffstat (limited to 'src/compiler/scala/tools/nsc/plugins')
-rw-r--r-- | src/compiler/scala/tools/nsc/plugins/PluginDescription.scala | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala index a3e6a844ba..703a2453eb 100644 --- a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala +++ b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala @@ -6,14 +6,18 @@ package scala.tools.nsc package plugins -import java.io.File - +/*@XML*/ import scala.xml.{Node,NodeSeq} +/*XML@*/ +/*@NOXML +import org.w3c.dom.{Node, Document, Text} +import scala.tools.util.XML +XMLNO@*/ /** A description of a compiler plugin, suitable for serialization * to XML for inclusion in the plugin's .jar file. * - * @author Lex Spoon + * @author Lex Spoon, Stephane Micheloud * @version 1.0, 2007-5-21 */ abstract class PluginDescription { @@ -29,31 +33,74 @@ abstract class PluginDescription { /** An XML representation of this description. It can be * read back using <code>PluginDescription.fromXML</code>. - * It should be stored inside the jar. + * It should be stored inside the jar archive file. */ +/*@XML*/ // NB. This code DOES rely on Scala native XML support. def toXML: Node = { <plugin> <name>{name}</name> <classname>{classname}</classname> </plugin> } -} +/*XML@*/ +/*@NOXML // NB. This code DOES NOT rely on Scala native XML support. + def toXML: Node = pluginDoc + + private lazy val pluginDoc: Node = { + val root = XML.newDocument() + val pluginElem = root createElement "plugin" + root appendChild pluginElem + + val nameElem = root createElement "name" + nameElem appendChild (root createTextNode name) + pluginElem appendChild nameElem + + val classnameElem = root createElement "classname" + classnameElem appendChild (root createTextNode classname) + pluginElem appendChild classnameElem + + root + } +XMLNO@*/ +} /** Utilities for the PluginDescription class. * - * @author Lex Spoon + * @author Lex Spoon, Stephane Micheloud * @version 1.0, 2007-5-21 */ object PluginDescription { + def fromXML(xml: Node): Option[PluginDescription] = { // check the top-level tag +/*@XML*/ xml match { case <plugin>{_*}</plugin> => () case _ => return None } +/*XML@*/ +/*@NOXML + val node = xml match { + case root: Document => root.getDocumentElement + case node => node + } + if (node.getNodeName != "plugin") + return None - /** Extract one field */ + class RichNode(node: Node) { + def \\(tagName: String): Node = node match { + case root: Document => root.getElementsByTagName(tagName) item 0 + case _ => node //TODO: visit children + } + def text: String = node match { + case t: Text => t.getWholeText + case e => e.getTextContent + } + } + implicit def nodeWrapper(node: Node) = new RichNode(node) +XMLNO@*/ + // extract one field def getField(field: String): Option[String] = { val text = (xml \\ field).text.trim if (text == "") None else Some(text) @@ -74,4 +121,5 @@ object PluginDescription { val classname = classname1 }) } + } |