예제 #1
0
        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
        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
        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);
        }