コード例 #1
0
 private void WriteJavaLine(TargetCodeResult currentLineResult)
 {
     StreamWriter file = null;
     try
     {
         String javaFile = this.directoryName + @"/" + this.sourceCode.GetJavaDestinationFileName();
         file = new StreamWriter(javaFile, true);
         String[] breakUpLines = currentLineResult.GetCurrentCode().Split('\n');
         if (breakUpLines.Length > 1)
         {
             for (int i = 0; i < breakUpLines.Length; i++)
                 file.WriteLine(breakUpLines[i]);
         }
         else
             file.WriteLine(currentLineResult.GetCurrentCode());
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (file != null)
             file.Close();
     }
 }
コード例 #2
0
        private void RunCompile()
        {
            if (displayProgress)
                Console.WriteLine("Start compiling... File: {0}", this.sourceCode.GetFileName());

            int pos = 1;

            foreach (String currentSourceCodeLine in this.sourceCode.GetLines())
            {
                TargetCodeResult targetCode = new TargetCodeResult(currentSourceCodeLine);

                // TODO: For now we list the commands here, much get a better idea to handle (??) load it from a list (??)

                ICommand usingDirective = new UsingDirectiveComp();
                ICommand namespaceComp = new NamespaceComp();
                ICommand classDef = new ClassDefinitionComp();
                ICommand openStatementBlock = new OpenStatementBlockComp();
                ICommand mainMethod = new MainMethodComp();
                ICommand methodDef = new MethodDefinitionComp();
                ICommand closeStatementBlock = new CloseStatementBlockComp();
                ICommand keywords = new KeywordsComp();
                ICommand autoProperty = new AutoPropertiesComp();

                if (usingDirective.Identify(this.sourceCode, currentSourceCodeLine, pos))
                    targetCode = usingDirective.Compile(this.sourceCode, currentSourceCodeLine, pos);

                if (namespaceComp.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = namespaceComp.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (classDef.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = classDef.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (openStatementBlock.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = openStatementBlock.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (mainMethod.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = mainMethod.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (methodDef.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = methodDef.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (closeStatementBlock.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = closeStatementBlock.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (keywords.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = keywords.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (autoProperty.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = autoProperty.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                // TODO: Add additional commands here

                if (!targetCode.Success)
                    this.errors.Add(targetCode.ErrorMessage);

                if (UnitTestMode)
                    this.allCode.Add(targetCode.GetCurrentCode());

                if (writeJavaCode && targetCode.IsValidCode())
                    WriteJavaLine(targetCode);

                pos++;
            }
        }