public void WriteTo(TranslationWriter writer)
 {
     _binaryConditionLeftTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.WriteToTranslation(_binaryConditionOperator.TrimEnd());
     writer.WriteNewLineToTranslation();
     writer.Indent();
     _binaryConditionRightTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.Unindent();
 }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        private static void WriteCaseBody(ITranslation bodyTranslation, TranslationWriter writer)
        {
            writer.Indent();

            bodyTranslation.WriteTo(writer);

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

            writer.Unindent();
        }
Exemplo n.º 4
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();
            }
Exemplo n.º 5
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();
                }
            }
Exemplo n.º 6
0
        public void WriteTo(TranslationWriter writer)
        {
            if (_writeBraces)
            {
                writer.WriteOpeningBraceToTranslation(_startOnNewLine);

                if (WriteEmptyCodeBlock(writer))
                {
                    return;
                }
            }

            if (_indentContents)
            {
                writer.Indent();
            }

            if (_writeBraces && _ensureReturnKeyword && !_translation.IsMultiStatement())
            {
                writer.WriteReturnToTranslation();
            }

            _translation.WriteTo(writer);

            if (EnsureTerminated())
            {
                writer.WriteToTranslation(';');
            }

            if (_writeBraces)
            {
                writer.WriteClosingBraceToTranslation();
            }

            if (_indentContents)
            {
                writer.Unindent();
            }
        }
Exemplo n.º 7
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();
            }
        }