mirror of https://github.com/sbt/sbt.git
drop unused mutable data type generator
This commit is contained in:
parent
7d49bcdbf2
commit
d4aa7bf0e9
|
|
@ -74,7 +74,7 @@ object Util
|
|||
{
|
||||
IO.delete(out)
|
||||
IO.createDirectory(out)
|
||||
val args = "immutable" :: "xsbti.api" :: out.getAbsolutePath :: defs.map(_.getAbsolutePath).toList
|
||||
val args = "xsbti.api" :: out.getAbsolutePath :: defs.map(_.getAbsolutePath).toList
|
||||
val mainClass = main getOrElse "No main class defined for datatype generator"
|
||||
toError(run.run(mainClass, cp.files, args, s.log))
|
||||
(out ** "*.java").get
|
||||
|
|
|
|||
|
|
@ -9,31 +9,29 @@ import java.util.Locale
|
|||
/** Generates a datatype hierarchy from a definition file.*/
|
||||
object GenerateDatatypes
|
||||
{
|
||||
/** Arguments: ('mutable' | 'immutable') <base package name> <base directory> <input file>+*/
|
||||
/** Arguments: <base package name> <base directory> <input file>+*/
|
||||
def main(args: Array[String])
|
||||
{
|
||||
if(args.length < 4)
|
||||
if(args.length < 3)
|
||||
{
|
||||
System.err.println("Invalid number of arguments, expected 'mutable' or 'immutable', package, base directory, and files to process")
|
||||
System.err.println("Invalid number of arguments, expected package, base directory, and files to process")
|
||||
System.exit(1)
|
||||
}
|
||||
else
|
||||
{
|
||||
val immutable = args(0).trim.toLowerCase(Locale.ENGLISH) == "immutable"
|
||||
|
||||
val packageName = args(1).trim
|
||||
val packageName = args(0).trim
|
||||
require(!packageName.isEmpty)
|
||||
|
||||
val baseDirectory = new File(args(2))
|
||||
val baseDirectory = new File(args(1))
|
||||
baseDirectory.mkdirs
|
||||
|
||||
val files = args.drop(3).map(new File(_))
|
||||
val files = args.drop(2).map(new File(_))
|
||||
// parse the files, getting all interface and enums
|
||||
val parser = new DatatypeParser
|
||||
val definitions = files.flatMap(parser.parseFile)
|
||||
|
||||
// create the interfaces, enums, and class implementations
|
||||
val generator = if(immutable) new ImmutableGenerator(packageName, baseDirectory) else new MutableGenerator(packageName, baseDirectory)
|
||||
val generator = new ImmutableGenerator(packageName, baseDirectory)
|
||||
generator.writeDefinitions(definitions)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import sbt.IO.write
|
|||
import Generator._
|
||||
import java.util.Locale
|
||||
|
||||
abstract class GeneratorBase(val basePkgName: String, val baseDirectory: File) extends NotNull
|
||||
abstract class GeneratorBase(val basePkgName: String, val baseDirectory: File)
|
||||
{
|
||||
def writeDefinitions(ds: Iterable[Definition]) = Generator.writeDefinitions(ds)(writeDefinition)
|
||||
def writeDefinition(d: Definition) = d match { case e: EnumDef => writeEnum(e); case c: ClassDef => writeClass(c) }
|
||||
|
|
@ -39,7 +39,7 @@ abstract class GeneratorBase(val basePkgName: String, val baseDirectory: File) e
|
|||
* A ClassDef is written as a class with an optional parent class. The class has a single constructor with
|
||||
* parameters for all declared and inherited members. Declared members are listed first in the constructor.
|
||||
* Inherited members are passed to the super constructor. The value of each member is held in a private
|
||||
* final field and.is accessed by a method of the same name.
|
||||
* final field and is accessed by a method of the same name.
|
||||
*
|
||||
* A toString method is generated for debugging.
|
||||
* The classes implement java.io.Serializable.
|
||||
|
|
@ -80,47 +80,7 @@ class ImmutableGenerator(pkgName: String, baseDir: File) extends GeneratorBase(p
|
|||
}
|
||||
|
||||
}
|
||||
class MutableGenerator(pkgName: String, baseDir: File) extends GeneratorBase(pkgName, baseDir)
|
||||
{
|
||||
def writeClass(c: ClassDef): Unit =
|
||||
{
|
||||
writeSource(c.name, basePkgName, interfaceContent(c))
|
||||
writeSource(implName(c.name), basePkgName + ".mutable", implContent(c))
|
||||
}
|
||||
def interfaceContent(c: ClassDef): String =
|
||||
{
|
||||
val normalizedMembers = c.members.map(normalize)
|
||||
val getters = normalizedMembers.map(m => "public " + m.asJavaDeclaration(true) + "();")
|
||||
val setters = normalizedMembers.map(m => "public void " + m.name + "(" + m.javaType(false) + " newValue);")
|
||||
val extendsPhrase = c.parent.map(_.name).map(" extends " + _).getOrElse("")
|
||||
|
||||
("public interface " + c.name + extendsPhrase + "\n" +
|
||||
"{\n\t" +
|
||||
(setters ++ getters).mkString("\n\t") + "\n" +
|
||||
"}\n")
|
||||
}
|
||||
def implContent(c: ClassDef): String =
|
||||
{
|
||||
val normalizedMembers = c.members.map(normalize)
|
||||
val fields = normalizedMembers.map(m => "private " + m.asJavaDeclaration(false) + ";")
|
||||
val getters = normalizedMembers.map(m => "public final " + m.asJavaDeclaration(true) + "()\n\t{\n\t\treturn " + m.asGet + ";\n\t}")
|
||||
val setters = normalizedMembers.map(m => "public final void " + m.name + "(" + m.javaType(false) + " newValue)\n\t{\n\t\t" + m.name + " = newValue;\n\t}")
|
||||
val extendsClass = c.parent.map(p => implName(p.name))
|
||||
val serializable = if(c.parent.isDefined) Nil else "java.io.Serializable" :: Nil
|
||||
val implements = c.name :: serializable
|
||||
val extendsPhrase = extendsClass.map(" extends " + _).getOrElse("") + " implements " + implements.mkString(", ")
|
||||
|
||||
("import java.util.Arrays;\n" +
|
||||
"import java.util.List;\n" +
|
||||
"import " + pkgName + ".*;\n\n" +
|
||||
"public class " + implName(c.name) + extendsPhrase + "\n" +
|
||||
"{\n\t" +
|
||||
(fields ++ getters ++ setters).mkString("\n\t") + "\n\t" +
|
||||
toStringMethod(c) + "\n" +
|
||||
"}\n")
|
||||
}
|
||||
|
||||
}
|
||||
object Generator
|
||||
{
|
||||
def methodSignature(modifiers: String, returnType: String, name: String, parameters: String) =
|
||||
|
|
|
|||
Loading…
Reference in New Issue