public static string MethodDeclaration(MethodDeclarationSyntax method)
        {
            Builder.Instance.HintsClear();
            var parsedAttributes = ParseAttributes(method.AttributeLists);

            var output    = parsedAttributes.Item1;
            var nameToUse = parsedAttributes.Item2;

            output += ParseModifiers(method.Modifiers);

            switch (Builder.Instance.Language)
            {
            case Languages.Kotlin:
                output += "fun ";
                break;

            case Languages.Php:
                output += "function ";
                break;

            case Languages.TypeScript:
                output += "";
                break;

            case Languages.Swift:
            default:
                output += "func ";
                break;
            }

            output += nameToUse ?? SyntaxTokenConvert(method.Identifier);

            if (method.TypeParameterList != null) //public string Something<T>
            {
                output += SyntaxNode(method.TypeParameterList);
            }

            output += SyntaxNode(method.ParameterList).TrimEnd();

            var hasReturnType    = method.ReturnType != null;
            var returnTypeResult = "";

            if (hasReturnType)
            {
                returnTypeResult = SyntaxNode(method.ReturnType).TrimEnd();
                switch (Builder.Instance.Language)
                {
                case Languages.Kotlin:
                    hasReturnType = returnTypeResult != "Unit";
                    break;

                case Languages.Swift:
                    hasReturnType = returnTypeResult != "Void";
                    break;

                default:
                    break;
                }
            }

            if (hasReturnType && !string.IsNullOrWhiteSpace(returnTypeResult))
            {
                switch (Builder.Instance.Language)
                {
                case Languages.TypeScript:
                case Languages.Php:
                    output += ": " + returnTypeResult;
                    break;

                case Languages.Kotlin:
                    output += ": " + returnTypeResult;
                    break;

                case Languages.Swift:
                    output += " -> " + returnTypeResult;
                    break;

                default:
                    output += " -> " + returnTypeResult;
                    break;
                }
            }

            switch (Builder.Instance.Language)
            {
            case Languages.Php:
            case Languages.TypeScript:
                output += ";";
                break;

            default:
                break;
            }

            output +=
                " "
                + SyntaxNode(method.Body).TrimStart();

            var hints = Builder.Instance.HintsGenerate(Builder.Instance.FindLeadingLineSpaces(method.GetLeadingTrivia()));

            if (!string.IsNullOrWhiteSpace(hints))
            {
                output = hints + output;
            }
            return(method.ConvertTo(output.Trim()));
        }
Exemple #2
0
        public static string MethodDeclaration(MethodDeclarationSyntax method)
        {
            var parsedAttributes = ParseAttributes(method.AttributeLists);

            var output    = parsedAttributes.Item1;
            var nameToUse = parsedAttributes.Item2;

            output += ParseModifiers(method.Modifiers);

            switch (Builder.Instance.Language)
            {
            case Languages.Kotlin:
                output += "fun ";
                break;

            case Languages.Swift:
            default:
                output += "func ";
                break;
            }

            output += (nameToUse ?? SyntaxTokenConvert(method.Identifier));

            if (method.TypeParameterList != null) //public string Something<T>
            {
                output += SyntaxNode(method.TypeParameterList);
            }

            output += SyntaxNode(method.ParameterList).TrimEnd();

            var hasReturnType    = method.ReturnType != null;
            var returnTypeResult = "";

            if (hasReturnType)
            {
                returnTypeResult = SyntaxNode(method.ReturnType).TrimEnd();
                switch (Builder.Instance.Language)
                {
                case Languages.Kotlin:
                    hasReturnType = returnTypeResult != "Unit";
                    break;

                case Languages.Swift:
                default:
                    break;
                }
            }

            if (hasReturnType)
            {
                switch (Builder.Instance.Language)
                {
                case Languages.Kotlin:
                    output += ": ";
                    break;

                case Languages.Swift:
                default:
                    output += " -> ";
                    break;
                }

                output += returnTypeResult;
            }

            output +=
                " "
                + SyntaxNode(method.Body).TrimStart();
            return(method.ConvertTo(output.Trim()));
        }