Exemplo n.º 1
0
        public static DartFile Construct(string filename, string folder, string dart)
        {
            dart = dart.RemoveComments()
                   .RemoveLines()
                   .CleanDoubleSpace();

            var file = new DartFile()
            {
                Name    = filename,
                Classes = new List <DartClass>(),
                Imports = GetImports(dart),
                Folder  = folder
            };

            foreach (var section in GetClasses(dart))
            {
                var name        = GetClassName(section.Value);
                var type        = GetVisibilityType(name);
                var constraints = GetGeneric(name);
                var clearName   = GetClearName(name);
                var sections    = GetSections(section.Value);
                ProcessSections(sections, clearName);

                file.Classes.Add(new DartClass()
                {
                    Extends            = GetExtends(section.Value, name),
                    Implements         = GetImplements(section.Value, name),
                    Sections           = sections,
                    RawName            = name,
                    Name               = clearName,
                    VisibilityType     = type,
                    IsAbstract         = IsAbstract(dart),
                    IsImmutable        = IsImmutable(dart),
                    Raw                = section.Value.Trim(),
                    Filename           = filename,
                    GenericConstraints = constraints
                });
            }

            // File level properties, typedefs, enums, methods etc.
            file.Sections = GetFileLevelSections(dart, file);
            ProcessSections(file.Sections, "");

            // Combine all sections
            var sectionList = new List <Section>();

            sectionList.AddRange(file.Sections);
            foreach (var item in file.Classes)
            {
                sectionList.AddRange(item.Sections);
            }

            return(file);
        }
Exemplo n.º 2
0
        public static IList <Section> GetFileLevelSections(string dart, DartFile file)
        {
            foreach (var item in file.Classes)
            {
                dart = dart.Replace(item.Raw, "");
            }

            foreach (var import in file.Imports)
            {
                dart = dart.Replace(import.Raw, "");
            }

            return(GetSections("{ " + dart.Trim() + " }"));
        }
Exemplo n.º 3
0
        public static string CreateFile(DartFile dart, DartModel model)
        {
            var @namespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(dart.Folder))
                             .NormalizeWhitespace();

            foreach (var @class in dart.Classes)
            {
                var classDeclaration = SyntaxFactory.ClassDeclaration(@class.Name);
                classDeclaration = classDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));

                // Add class to namespace
                @namespace = @namespace.AddMembers(classDeclaration);
            }

            // Output code
            var code = @namespace
                       .NormalizeWhitespace()
                       .ToFullString();

            return(code);
        }