예제 #1
0
 public override void WriteTo(TranslationWriter writer)
 {
     WriteIfStatement(writer);
     writer.WriteNewLineToTranslation();
     writer.WriteNewLineToTranslation();
     IfFalseTranslation.WriteTo(writer);
 }
예제 #2
0
        public static void WriteOpeningBraceToTranslation(this TranslationWriter writer, bool startOnNewLine = true)
        {
            if (startOnNewLine && writer.TranslationQuery(q => !q.TranslationEndsWith('{')))
            {
                writer.WriteNewLineToTranslation();
            }

            writer.WriteToTranslation('{');
            writer.WriteNewLineToTranslation();
            writer.Indent();
        }
예제 #3
0
        private void WriteDefaultIfPresent(TranslationWriter writer)
        {
            if (_defaultCaseTranslation == null)
            {
                return;
            }

            writer.WriteNewLineToTranslation();
            writer.WriteNewLineToTranslation();
            writer.WriteControlStatementToTranslation("default:");
            writer.WriteNewLineToTranslation();

            WriteCaseBody(_defaultCaseTranslation, writer);
        }
 public void WriteTo(TranslationWriter writer)
 {
     writer.WriteNewLineToTranslation();
     writer.WriteKeywordToTranslation("catch");
     _exceptionClause?.WriteTo(writer);
     _catchBodyTranslation.WriteTo(writer);
 }
예제 #5
0
            private void WriteMultiLineTernary(TranslationWriter writer)
            {
                TestTranslation.WriteInParenthesesIfRequired(writer, _context);

                writer.WriteNewLineToTranslation();
                writer.Indent();
                writer.WriteToTranslation("? ");

                IfTrueTranslation.WriteTo(writer);

                writer.WriteNewLineToTranslation();
                writer.WriteToTranslation(": ");

                IfFalseTranslation.WriteTo(writer);

                writer.Unindent();
            }
 public void WriteTo(TranslationWriter writer)
 {
     _binaryConditionLeftTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.WriteToTranslation(_binaryConditionOperator.TrimEnd());
     writer.WriteNewLineToTranslation();
     writer.Indent();
     _binaryConditionRightTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.Unindent();
 }
        public void WriteTo(TranslationWriter writer)
        {
            if (_isEmpty)
            {
                return;
            }

            if (_hasVariables)
            {
                foreach (var parametersByType in _variables)
                {
                    var parametersType = parametersByType.Key;
                    var parameters     = parametersByType.Value;

                    parametersType.WriteTo(writer);
                    writer.WriteSpaceToTranslation();
                    parameters.WriteTo(writer);
                    writer.WriteToTranslation(';');
                    writer.WriteNewLineToTranslation();
                }

                switch (_statements[0].NodeType)
                {
                case Conditional when !_statements[0].Expression.IsTernary():
                case Switch:
                    writer.WriteNewLineToTranslation();
                    break;
                }
            }

            for (var i = 0; ;)
            {
                _statements[i].WriteTo(writer);

                ++i;

                if (i == _statementCount)
                {
                    break;
                }

                writer.WriteNewLineToTranslation();
            }
        }
        public void WriteTo(TranslationWriter writer)
        {
            writer.WriteKeywordToTranslation("try");
            _bodyTranslation.WriteTo(writer);

            switch (_catchBlockCount)
            {
            case 0:
                break;

            case 1:
                _catchBlockTranslations[0].WriteTo(writer);
                break;

            default:
                for (var i = 0; ;)
                {
                    _catchBlockTranslations[i].WriteTo(writer);

                    ++i;

                    if (i == _catchBlockCount)
                    {
                        break;
                    }
                }

                break;
            }

            if (_hasFault)
            {
                writer.WriteNewLineToTranslation();
                writer.WriteKeywordToTranslation("fault");
                _faultTranslation.WriteTo(writer);
            }

            if (_hasFinally)
            {
                writer.WriteNewLineToTranslation();
                writer.WriteKeywordToTranslation("finally");
                _finallyTranslation.WriteTo(writer);
            }
        }
예제 #9
0
        public static void WriteClosingBraceToTranslation(this TranslationWriter writer, bool startOnNewLine = true)
        {
            if (startOnNewLine)
            {
                writer.WriteNewLineToTranslation();
            }

            writer.Unindent();
            writer.WriteToTranslation('}');
        }
예제 #10
0
        public void WriteTo(TranslationWriter writer)
        {
            writer.WriteControlStatementToTranslation(_switch);
            _valueTranslation.WriteInParentheses(writer);
            writer.WriteOpeningBraceToTranslation();

            for (var i = 0; ;)
            {
                var caseTestValueTranslations = _caseTestValueTranslations[i];

                for (int j = 0, l = caseTestValueTranslations.Length; ;)
                {
                    writer.WriteControlStatementToTranslation(_case);
                    caseTestValueTranslations[j].WriteTo(writer);
                    writer.WriteToTranslation(':');
                    writer.WriteNewLineToTranslation();

                    ++j;

                    if (j == l)
                    {
                        break;
                    }
                }

                WriteCaseBody(_caseTranslations[i], writer);

                ++i;

                if (i == _casesCount)
                {
                    break;
                }

                writer.WriteNewLineToTranslation();
                writer.WriteNewLineToTranslation();
            }

            WriteDefaultIfPresent(writer);

            writer.WriteClosingBraceToTranslation();
        }
            public void WriteTo(TranslationWriter writer)
            {
                if ((_writeBlankLineBefore || writer.TranslationQuery(q => q.TranslationEndsWith("};"))) &&
                    !writer.TranslationQuery(q => q.TranslationEndsWithBlankLine()))
                {
                    writer.WriteNewLineToTranslation();
                }

                if (_writeReturnKeyword)
                {
                    writer.WriteReturnToTranslation();
                }

                WriteStatementTo(writer);

                if (UseFinalBlankLine)
                {
                    writer.WriteNewLineToTranslation();
                }
            }
예제 #12
0
            public override void WriteTo(TranslationWriter writer)
            {
                WriteIfStatement(writer);
                writer.WriteNewLineToTranslation();
                writer.WriteControlStatementToTranslation("else");

                if (_isElseIf)
                {
                    writer.WriteSpaceToTranslation();
                }

                IfFalseTranslation.WriteTo(writer);
            }
예제 #13
0
        private static void WriteCaseBody(ITranslation bodyTranslation, TranslationWriter writer)
        {
            writer.Indent();

            bodyTranslation.WriteTo(writer);

            if (WriteBreak(bodyTranslation))
            {
                writer.WriteNewLineToTranslation();
                writer.WriteControlStatementToTranslation("break;");
            }

            writer.Unindent();
        }
예제 #14
0
            public void WriteTo(TranslationWriter writer)
            {
                _subjectTranslation.WriteInParenthesesIfRequired(writer, _context);

                if (_isPartOfMethodCallChain)
                {
                    writer.WriteNewLineToTranslation();
                    writer.Indent();
                }

                writer.WriteDotToTranslation();
                _methodInvocationTranslation.WriteTo(writer);

                if (_isPartOfMethodCallChain)
                {
                    writer.Unindent();
                }
            }
 public void WriteTo(TranslationWriter writer)
 {
     writer.WriteNewLineToTranslation();
     _quotedLambdaTranslation.WriteTo(writer);
 }
예제 #16
0
        public void WriteTo(TranslationWriter writer)
        {
            switch (Count)
            {
            case 0:
                if (_parenthesesMode != ParenthesesMode.Never)
                {
                    writer.WriteToTranslation(_openAndCloseParentheses);
                }

                return;

            case 1 when(_parenthesesMode != ParenthesesMode.Always):
                _parameterTranslations[0].WriteTo(writer);
                return;
            }

            if (_parenthesesMode != ParenthesesMode.Never)
            {
                writer.WriteToTranslation('(');
            }

            var writeParametersOnNewLines = WriteParametersOnNewLines();

            if (writeParametersOnNewLines)
            {
                writer.WriteNewLineToTranslation();
                writer.Indent();
            }

            for (var i = 0; ;)
            {
                var parameterTranslation = _parameterTranslations[i];

                if (writeParametersOnNewLines && (i == 0) && parameterTranslation.IsMultiStatement)
                {
                    parameterTranslation.WithoutStartingNewLine();
                }

                parameterTranslation.WriteTo(writer);
                ++i;

                if (i == Count)
                {
                    break;
                }

                if (writeParametersOnNewLines)
                {
                    writer.WriteToTranslation(',');

                    if (!_parameterTranslations[i].IsMultiStatement)
                    {
                        writer.WriteNewLineToTranslation();
                    }

                    continue;
                }

                writer.WriteToTranslation(", ");
            }

            if (_parenthesesMode != ParenthesesMode.Never)
            {
                writer.WriteToTranslation(')');
            }

            if (writeParametersOnNewLines)
            {
                writer.Unindent();
            }
        }