Exemple #1
0
 void IndentMultiple(ICodeWriter writer, int numberOfIdentions)
 {
     for (var i = 0; i < numberOfIdentions; i++)
     {
         writer.Indent();
     }
 }
Exemple #2
0
#pragma warning disable 1591
        public override void Write(ICodeWriter writer)
        {
            var childIndex       = 0;
            var numberOfChildren = Children.Count;

            writer.Write("{{");

            if (numberOfChildren > 0)
            {
                writer.Newline();
                writer.Indent();

                foreach (var child in Children)
                {
                    child.Write(writer);
                    childIndex++;

                    if (childIndex > 0 && childIndex < numberOfChildren)
                    {
                        writer.Write(",");
                    }
                    writer.Newline();
                }

                writer.Unindent();
                writer.WriteWithIndentation("}}");
            }
            else
            {
                writer.Write("}}");
            }
        }
Exemple #3
0
#pragma warning disable 1591
        public override void Write(ICodeWriter writer)
        {
            var childIndex = 0;
            var numberOfChildren = Children.Count;

            writer.Write("{{");

            if (numberOfChildren > 0)
            {
                writer.Newline();
                writer.Indent();

                foreach (var child in Children)
                {
                    child.Write(writer);
                    childIndex++;

                    if (childIndex > 0 && childIndex < numberOfChildren)
                        writer.Write(",");
                    writer.Newline();
                }

                writer.Unindent();
                writer.WriteWithIndentation("}}");
            }
            else
            {
                writer.Write("}}");
            }
        }
Exemple #4
0
#pragma warning disable 1591
        public override void Write(ICodeWriter writer)
        {
            base.Write(writer);
            if (_extensions.Count > 0)
            {
                writer.Newline();
                IndentMultiple(writer, 3);
                writer.WriteWithIndentation(".extend({{");
                writer.Newline();
                writer.Indent();

                foreach (var extension in _extensions)
                {
                    if (extension != _extensions[0])
                    {
                        writer.Write(",");
                        writer.Newline();
                    }
                    writer.WriteWithIndentation("{0} : {1}", extension.Name, extension.Options);
                }
                writer.Unindent();
                writer.Newline();
                writer.WriteWithIndentation("}})");
                UnindentMultiple(writer, 3);
            }
        }
 protected override void LLWrite(ICodeWriter writer, object o)
 {
     writer.BeginNewLine(true);
     if (CaseExpr != null)
     {
         writer.Write("case ", true);
         CaseExpr.WriteAll(writer);
     }
     else
     {
         writer.Write("default", true);
     }
     writer.Write(" : ", true);
     if (Actions != null)
     {
         if (Actions is ICodeElementSet)
         {
             writer.EndLine();
             writer.Indent();
             writer.BeginNewLine(true);
         }
         Actions.WriteAll(writer);
         writer.EndLine();
         if (Actions is ICodeElementSet)
         {
             writer.Exdent();
         }
     }
 }
Exemple #6
0
#pragma warning disable 1591
        public override void Write(ICodeWriter writer)
        {
            base.Write(writer);
            if( _extensions.Count > 0 )
            {
                writer.Newline();
                IndentMultiple(writer, 3);
                writer.WriteWithIndentation(".extend({{");
                writer.Newline();
                writer.Indent();

                foreach (var extension in _extensions)
                {
                    if (extension != _extensions[0])
                    {
                        writer.Write(",");
                        writer.Newline();
                    }
                    writer.WriteWithIndentation("{0} : {1}", extension.Name, extension.Options);
                }
                writer.Unindent();
                writer.Newline();
                writer.WriteWithIndentation("}})");
                UnindentMultiple(writer, 3);
            }
        }
Exemple #7
0
 public void Write(ICodeWriter writer, object o)
 {
     if (indent)
     {
         writer.Indent();
     }
     writer.BeginNewLine(prependIndents);
     writer.Write(Contents, allowSplit);
     writer.EndLine();
 }
Exemple #8
0
 public override void Write(ICodeWriter writer, object o)
 {
     if (isSingleLine)
     {
         if (indent)
         {
             writer.Indent();
         }
         writer.BeginNewLine(prependIndents);
     }
 }
Exemple #9
0
 public override void Write(ICodeWriter writer, object o)
 {
     if (StartDecoration != null)
     {
         if (startOnOwnLine)
         {
             writer.BeginNewLine(true);
         }
         writer.Write(StartDecoration, true);
         if (startOnOwnLine)
         {
             writer.EndLine();
         }
     }
     if (indent)
     {
         writer.Indent();
     }
 }
Exemple #10
0
        public void Visit(IVisitor visitor, CMethod method)
        {
            NewMethod(method);

            foreach (var methodAttribute in method.Attribute)
            {
                methodAttribute.Accept(visitor);
            }

            var modifier     = !method.SignatureOnly ? method.AccessModifier.GetString() + " " : string.Empty;
            var abstractText = method.IsAbstract ? "abstract " : string.Empty;
            var overrideText = method.IsOverride ? "override " : string.Empty;
            var @static      = method.IsStatic ? "static " : string.Empty;
            var asyncText    = method.IsAsync ? "async " : string.Empty;
            var thisText     = method.IsExtensionMethod ? "this " : string.Empty;

            _codeWriter.Write(
                $"{modifier}{@static}{abstractText}{overrideText}{asyncText}{method.ReturnType} {method.MethodName}({thisText}");

            var first      = true;
            var paramIndex = 0;

            _codeWriter.SaveIndent();

            var methodTextLength = method.TextLength;

            foreach (var param in method.Parameter)
            {
                if (!first)
                {
                    _codeWriter.Write(", ");
                }
                if (methodTextLength > 100 && method.Parameter.Count > 1) //attempt to Mirror Resharper's rules
                {
                    //wrap the parameters to next line
                    _codeWriter.WriteLine("");
                    if (first)
                    {
                        _codeWriter.Indent();
                    }
                }
                visitor.VisitCParameter(param);
                first = false;
                paramIndex++;
            }
            _codeWriter.Write(")");
            _codeWriter.RestoreIndent();
            if (method.SignatureOnly || method.IsAbstract)
            {
                _codeWriter.WriteLine(";");
            }
            else if (method.UseExpressionDefinition)
            {
                _codeWriter.WriteLine($" => {method.CodeSnippet}");
            }
            else
            {
                _codeWriter.WriteLine(string.Empty);
                _codeWriter.WriteLine("{");
                _codeWriter.SaveIndent();
                _codeWriter.Indent();
                if (!string.IsNullOrEmpty(method.CodeSnippetFile) || !string.IsNullOrEmpty(method.CodeSnippet))
                {
                    if (!string.IsNullOrEmpty(method.CodeSnippet))
                    {
                        _codeWriter.WriteLine(method.CodeSnippet);
                    }
                    if (!string.IsNullOrEmpty(method.CodeSnippetFile))
                    {
                        var snippetService = new SnippetService();
                        _codeWriter.WriteLine(snippetService.GetCodeSnippet(method.MethodName, method.CodeSnippetFile));
                    }
                }
                else if (method.ReturnType != "void")
                {
                    _codeWriter.WriteLine("throw new NotImplementedException();");
                }
                _codeWriter.Unindent();
                _codeWriter.RestoreIndent();
                _codeWriter.WriteLine("}");
                // _codeWriter.WriteLine();
            }
        }
Exemple #11
0
#pragma warning disable 1591
        public override void Write(ICodeWriter writer)
        {
            writer.Indent();
            WriteChildren(writer);
            writer.Unindent();
        }
Exemple #12
0
 void IndentMultiple(ICodeWriter writer, int numberOfIdentions)
 {
     for (var i = 0; i < numberOfIdentions; i++) writer.Indent();
 }
Exemple #13
0
        public void Visit(IVisitor visitor, CConstructor constructor)
        {
            string staticString   = constructor.IsStatic ? "static " : string.Empty;
            var    accessModifier = constructor.IsStatic ? string.Empty : $"{constructor.AccessModifier.GetString()} ";

            _codeWriter.Write($"{accessModifier}{staticString}{constructor.ConstructorName}(");

            var first = true;

            foreach (var param in constructor.Parameter)
            {
                if (!first)
                {
                    _codeWriter.Write(", ");
                }

                visitor.VisitCParameter(param);
                first = false;
            }
            _codeWriter.Write(")");

            var passToBaseClass = constructor.Parameter.Where(p => p.PassToBaseClass);

            if (passToBaseClass.Any())
            {
                _codeWriter.Write(" : base(");
                var firstParameter = true;
                foreach (var parameter in passToBaseClass)
                {
                    if (!firstParameter)
                    {
                        _codeWriter.Write(", ");
                    }
                    firstParameter = false;
                    _codeWriter.Write($"{parameter.ParameterName}");
                }
                _codeWriter.Write(")");
            }

            {
                _codeWriter.WriteLine(string.Empty);
                _codeWriter.WriteLine("{");
                _codeWriter.Indent();
                if (!string.IsNullOrEmpty(constructor.CodeSnippetFile) ||
                    !string.IsNullOrEmpty(constructor.CodeSnippet))
                {
                    if (!string.IsNullOrEmpty(constructor.CodeSnippet))
                    {
                        _codeWriter.WriteLine(constructor.CodeSnippet);
                    }
                    if (!string.IsNullOrEmpty(constructor.CodeSnippetFile))
                    {
                        var snippetService = new SnippetService();
                        _codeWriter.WriteLine(snippetService.GetCodeSnippet(constructor.ConstructorName,
                                                                            constructor.CodeSnippetFile));
                    }
                }
                else
                {
                    //_codeWriter.WriteLine("throw new NotImplementedException();");
                }
                _codeWriter.Unindent();
                _codeWriter.WriteLine("}");
                _codeWriter.WriteLine();
            }
        }
Exemple #14
0
#pragma warning disable 1591
        public override void Write(ICodeWriter writer)
        {
            writer.Indent();
            WriteChildren(writer);
            writer.Unindent();
        }
Exemple #15
0
 /// <summary>
 /// Indents then write
 /// </summary>
 /// <param name="self"></param>
 /// <param name="str"></param>
 /// <param name="ctx"></param>
 public static void IndentAndWrite(this ICodeWriter self, string str, Context ctx)
 {
     self.Indent(ctx);
     self.Write(str);
 }
Exemple #16
0
 /// <inheritdoc/>
 public IDisposable Indent() => _codeWriter.Indent();