コード例 #1
0
ファイル: Program.cs プロジェクト: WarrenFerrell/CsScala
        private static void Generate()
        {
            Console.WriteLine("Parsing...");
            var sw = Stopwatch.StartNew();

            if (!Directory.Exists(OutDir))
            {
                Directory.CreateDirectory(OutDir);
            }

            var allTypes = Compilation.SyntaxTrees
                           .SelectMany(o => o.GetRoot().DescendantNodes().OfType <BaseTypeDeclarationSyntax>())
                           .Select(o => new { Syntax = o, Symbol = GetModel(o).GetDeclaredSymbol(o), TypeName = WriteType.TypeName(GetModel(o).GetDeclaredSymbol(o)) })
                           .GroupBy(o => o.Symbol.ContainingNamespace.FullNameWithDot() + o.TypeName)
                           .ToList();

            Utility.Parallel(Compilation.SyntaxTrees.ToList(), tree =>
            {
                foreach (var n in TriviaProcessor.DoNotWrite(tree))
                {
                    DoNotWrite.TryAdd(n, null);
                }

                //Init ClassTags
                foreach (var method in tree.GetRoot().DescendantNodes().OfType <MethodDeclarationSyntax>().Where(o => o.TypeParameterList != null))
                {
                    ClassTags.InitMethod(GetModel(method).GetDeclaredSymbol(method), method);
                }
            });

            Console.WriteLine("Parsed in " + sw.Elapsed + ". Writing out scala...");
            sw.Restart();

            Compilation.SyntaxTrees.SelectMany(o => o.GetRoot().DescendantNodes().OfType <AnonymousObjectCreationExpressionSyntax>())
            .Select(o => new { Syntax = o, Name = WriteAnonymousObjectCreationExpression.TypeName(o) })
            .GroupBy(o => o.Name)
            .Parallel(o => WriteAnonymousObjectCreationExpression.WriteAnonymousType(o.First().Syntax));


            allTypes.Parallel(type =>
            {
                TypeState.Instance          = new TypeState();
                TypeState.Instance.TypeName = type.First().TypeName;
                TypeState.Instance.Partials = type.Select(o => new TypeState.SyntaxAndSymbol {
                    Symbol = o.Symbol, Syntax = o.Syntax
                })
                                              .Where(o => !DoNotWrite.ContainsKey(o.Syntax))
                                              .ToList();

                if (TypeState.Instance.Partials.Count > 0)
                {
                    WriteType.Go();
                }
            });

            WriteConstructorBody.WriteConstructorsHelper(allTypes.SelectMany(o => o).Where(o => !DoNotWrite.ContainsKey(o.Syntax)).Select(o => o.Symbol));

            Console.WriteLine("Scala written out in " + sw.Elapsed);
        }
コード例 #2
0
ファイル: WriteType.cs プロジェクト: WarrenFerrell/CsScala
        private static string TypeParameter(TypeParameterSyntax type)
        {
            var ret = Utility.TypeConstraints(type, TypeState.Instance.Partials.SelectMany(z => z.Syntax.As <TypeDeclarationSyntax>().ConstraintClauses));

            if (ClassTags.NeedsClassTag(TypeState.Instance.Partials.First().Symbol, type.Identifier.ValueText))
            {
                ret += " :ClassTag";
            }

            return(ret);
        }
コード例 #3
0
ファイル: WriteMethod.cs プロジェクト: WarrenFerrell/CsScala
        public static string TypeParameter(TypeParameterSyntax prm, IMethodSymbol methodSymbol, MethodDeclarationSyntax methodSyntax)
        {
            var identifier = Utility.TypeConstraints(prm, methodSyntax.ConstraintClauses);

            if (ClassTags.NeedsClassTag(methodSymbol, methodSyntax, prm.Identifier.ValueText))
            {
                identifier += ":ClassTag";
            }

            return(identifier);
        }