Exemplo n.º 1
0
        public static void Generate(Language language, string documentPath, string destinationPath)
        {
            if (!File.Exists(documentPath))
            {
                throw new ApplicationException(string.Format(
                    "The specified input file \"{0}\" does not exist.", documentPath));
            }

            PropertyDictionary documentOptions;
            string actualDocumentPath;

            if (_suffixRegex.IsMatch(documentPath))
            {
                documentOptions = PropertyDictionary.FromFile(documentPath);
                actualDocumentPath = _suffixRegex.Replace(documentPath, ".pinch");

                if (!File.Exists(actualDocumentPath))
                {
                    throw new ApplicationException(string.Format(
                        "The instance configuration \"{0}\" exists, but not the expected corresponding specification file \"{1}\".",
                        documentPath, actualDocumentPath));
                }
            }
            else
            {
                actualDocumentPath = documentPath;

                documentOptions = PropertyDictionary.EmptyDictionary();
                actualDocumentPath = documentPath;
            }

            DateTime documentModified = File.GetLastWriteTimeUtc(documentPath);
            DateTime actualDocumentModified = File.GetLastWriteTimeUtc(actualDocumentPath);

            DateTime mostRecent = documentModified > actualDocumentModified ? documentModified : actualDocumentModified;

            Document document = Document.Parse(actualDocumentPath);

            Compilation compilation = new Compilation();
            compilation.AddDocument(document);
            compilation.Resolve();
            compilation.Number();

            language.CreateDomImplementationHelpers(document, documentOptions);

            Generator generator = new Generator(language, document, actualDocumentPath, destinationPath, mostRecent);

            language.GenerateFiles(generator, document);
        }
Exemplo n.º 2
0
 public abstract void GenerateFiles(Generator generator, Document document);
Exemplo n.º 3
0
        public override void GenerateFiles(Generator generator, Document document)
        {
            foreach (Protocol protocol in document.Protocols)
            {
                foreach (Declaration declaration in protocol.Declarations)
                {
                    JavaStructure implementation = declaration.Implementation as JavaStructure;

                    string fileSuffix = implementation != null && implementation.IsSurrogate ? "Surrogate.java" : ".java";

                    generator.GenerateFile(
                        Path.Combine(generator.DestinationPath, declaration.Identifier + fileSuffix),
                        Templates.JavaTemplate, "file", "Declaration", declaration);
                }
            }
        }
Exemplo n.º 4
0
 public override void GenerateFiles(Generator generator, Document document)
 {
     generator.GenerateFile(
         Path.Combine(generator.DestinationPath, generator.BaseName + ".cs"), Templates.CsTemplate, "file", "Document", document);
 }
Exemplo n.º 5
0
        public override void GenerateFiles(Generator generator, Document document)
        {
            foreach (Protocol protocol in document.Protocols)
            {
                PythonProtocol pythonProtocol = protocol.Implementation as PythonProtocol;

                generator.GenerateFile(
                    Path.Combine(generator.DestinationPath, pythonProtocol.ModuleName + ".py"),
                    Templates.PythonTemplate, "file", "Protocol", protocol);
            }
        }