Пример #1
0
        private Class TraverseClass(ClassBlockSyntax cbs)
        {
            Class retClass = new Class();
            //Name
            retClass.Name = cbs.Begin.Identifier.ValueText;
            //encapsulation

            foreach (SyntaxToken st in cbs.Begin.Modifiers)
            {
                string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText);
                Encapsulation encap;
                Qualifiers qual;
                if (System.Enum.TryParse<Encapsulation>(modifier, out encap))
                {
                    retClass.Encapsulation.Add(encap);
                }
                else if (System.Enum.TryParse<Qualifiers>(modifier, out qual))
                {
                    retClass.Qualifiers.Add(qual);
                }
            }

            List<EnumBlockSyntax> enums = new List<EnumBlockSyntax>();
            List<StructureBlockSyntax> structs = new List<StructureBlockSyntax>();
            List<MethodBlockSyntax> methods = new List<MethodBlockSyntax>();
            List<FieldDeclarationSyntax> Fields = new List<FieldDeclarationSyntax>();
            List<PropertyBlockSyntax> properties = new List<PropertyBlockSyntax>();
            List<ConstructorBlockSyntax> constructors = new List<ConstructorBlockSyntax>();
            List<ModuleBlockSyntax> modules = new List<ModuleBlockSyntax>();
            List<ClassBlockSyntax> classes = new List<ClassBlockSyntax>();

            foreach (SyntaxNode sn in cbs.ChildNodes())
            {
                if (sn is EnumBlockSyntax)
                {
                    enums.Add(sn as EnumBlockSyntax);
                }
                else if (sn is StructureBlockSyntax)
                {
                    structs.Add(sn as StructureBlockSyntax);
                }
                else if (sn is MethodBlockSyntax)
                {
                    methods.Add(sn as MethodBlockSyntax);
                }
                else if (sn is FieldDeclarationSyntax)
                {
                    Fields.Add(sn as FieldDeclarationSyntax);
                }
                else if (sn is PropertyBlockSyntax)
                {
                    properties.Add(sn as PropertyBlockSyntax);
                }
                else if (sn is ConstructorBlockSyntax)
                {
                    constructors.Add(sn as ConstructorBlockSyntax);
                }
                else if (sn is ModuleBlockSyntax)
                {
                    modules.Add(sn as ModuleBlockSyntax);
                }
                else if (sn is ClassBlockSyntax)
                {
                    classes.Add(sn as ClassBlockSyntax);
                }
            }

            foreach (EnumBlockSyntax ebs in enums)
            {
                //traverse enums
                retClass.Enums.Add(TraverseEnum(ebs));
            }

            foreach (StructureBlockSyntax sbs in structs)
            {
                retClass.Structs.Add(TraverseStruct(sbs));
            }

            foreach (MethodBlockSyntax mbs in methods)
            {
                bool isConstructor = false;
                Method tempMethod = TraverseMethod(mbs, ref isConstructor);
                if (isConstructor)
                {
                    retClass.Constructors.Add(tempMethod as Constructor);
                }
                else
                {
                    retClass.Methods.Add(tempMethod);
                }
            }

            foreach (FieldDeclarationSyntax fds in Fields)
            {
                retClass.Fields.Add(TraverseField(fds));
            }

            foreach (PropertyBlockSyntax pbs in properties)
            {
                retClass.Properties.Add(TraverseProperties(pbs));
            }

            foreach (ConstructorBlockSyntax css in constructors)
            {
                retClass.Constructors.Add(TraverseConstructor(css));
            }

            foreach (ModuleBlockSyntax mbs in modules)
            {
                retClass.Modules.Add(TraverseModule(mbs));
            }

            foreach (ClassBlockSyntax cbs2 in classes)
            {
                retClass.Classes.Add(TraverseClass(cbs2));
            }

            foreach (SyntaxNode sn in cbs.Begin.ChildNodes())
            {
                if (sn is InheritsOrImplementsStatementSyntax)
                {
                }
            }

            return retClass;
        }
Пример #2
0
        public Class TraverseClass(ClassDeclarationSyntax cds)
        {
            Class retClass = new Class();
            //public List<Delegate> Delegates { get; set; }
            //public List<Method> FunctionDefs { get; set; }
            //public Inheritance Inheritance { get; set; }
            //public List<Module> Modules { get; set; }
            //public List<Preprocessor> Preprocessors { get; set; }
            //public List<Property> Properties { get; set; }
            //public List<Union> Unions { get; set; }
            retClass.Name = cds.Identifier.ValueText;
            if (cds.HasLeadingTrivia)
            {
                SetOuterComments(retClass, cds.GetLeadingTrivia().ToFullString());
            }

            if (cds.HasTrailingTrivia)
            {
                SetInnerComments(retClass, cds.GetTrailingTrivia().ToFullString());
            }
            foreach (SyntaxToken st in cds.Modifiers)
            {
                string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText);
                Encapsulation encap;
                Qualifiers qual;
                if (System.Enum.TryParse<Encapsulation>( modifier, out encap))
                {
                    retClass.Encapsulation.Add(encap);
                }
                else if (System.Enum.TryParse<Qualifiers>(modifier, out qual))
                {
                    retClass.Qualifiers.Add(qual);
                }
            }

            var enums = from aEnu in cds.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnu;
            foreach (EnumDeclarationSyntax eds in enums)
            {
                retClass.Enums.Add(TraverseEnums(eds));
            }

            var structs = from aStruct in cds.ChildNodes().OfType<StructDeclarationSyntax>() select aStruct;
            foreach (StructDeclarationSyntax sds in structs)
            {
                retClass.Structs.Add(TransverseStructs(sds));
            }

            var methods = from aMethod in cds.ChildNodes().OfType<MethodDeclarationSyntax>() select aMethod;
            foreach (MethodDeclarationSyntax mds in methods)
            {
                retClass.Methods.Add(TransverseMethods(mds));
            }

            var Fields = from aField in cds.ChildNodes().OfType<FieldDeclarationSyntax>() select aField;
            foreach (FieldDeclarationSyntax fds in Fields)
            {
                retClass.Fields.Add(TransverseVariables(fds));
            }

            //var properties = from aProperty in cds.ChildNodes().OfType<PropertyDeclarationSyntax>() select aProperty;
            //foreach (PropertyDeclarationSyntax pds in properties)
            //{
            //    //traverse attributes
            //}

            var constructors = from aConstructor in cds.ChildNodes().OfType<ConstructorDeclarationSyntax>() select aConstructor;
            foreach (ConstructorDeclarationSyntax cods in constructors)
            {
                retClass.Constructors.Add(TransverseConstructors(cods));
            }

            var destructors = from aDestructor in cds.ChildNodes().OfType<DestructorDeclarationSyntax>() select aDestructor;
            foreach (DestructorDeclarationSyntax dds in destructors)
            {
                retClass.Destructors.Add(TransverseDestructors(dds));
            }

            var classes = from aClass in cds.ChildNodes().OfType<ClassDeclarationSyntax>() select aClass;
            foreach (ClassDeclarationSyntax cds2 in classes)
            {
                retClass.Classes.Add(TraverseClass(cds2));
            }

            return retClass;
        }