コード例 #1
0
        public JsFile GetJsFileFromCodeSnippet(string codeSnippet, SupportedLanguage language)
        {
            var file = new JsFile();

            var snippetParser = new SnippetParser(language);

            var jsFile = new JsFile
            {
                FullPath = string.Empty
            };

            var parsedNode = snippetParser.Parse(codeSnippet);

            if (parsedNode.Children.Count > 0)
            {
                var visitor = new AstVisitor
                {
                    Model = jsFile
                };

                parsedNode.AcceptVisitor(visitor, null);

                file = visitor.Model;
                return file;
            }

            return null;
        }
コード例 #2
0
        public JsFile GetJsFileFromCodeFile(string path, SupportedLanguage language)
        {
            TextReader textReader = File.OpenText(path);

            var file = new JsFile();

            using (var parser = ParserFactory.CreateParser(language, textReader))
            {
                var jsFile = new JsFile
                {
                    FullPath = path
                };

                parser.Parse();

                if (parser.Errors.Count <= 0)
                {
                    var visitor = new AstVisitor
                    {
                        Model = jsFile
                    };

                    parser.CompilationUnit.AcceptVisitor(visitor, null);

                    file = visitor.Model;
                    return file;
                }
            }

            return null;
        }
コード例 #3
0
        public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            Contract.Requires(typeDeclaration != null);

            // Is this a class but not a test fixture?
            if (IsClass(typeDeclaration) && !HasTestFixtureAttribute(typeDeclaration))
            {
                var parent = new JsClass()
                {
                    Name = typeDeclaration.Name,
                    Properties = new List<JsProperty>()
                };

                if (typeDeclaration.Attributes.Count > 0)
                {
                    foreach (var attribute in typeDeclaration.Attributes)
                    {
                        var jsAttributes = new List<JsAttribute>();
                        var a = attribute.Attributes[0];

                        jsAttributes.Add(new JsAttribute()
                        {
                            Name = a.Name
                        });

                        parent.Attributes = jsAttributes;
                    }
                }

                if (Model == null) Model = new JsFile();

                if (Model.Files == null) Model.Files = new List<JsClass>();

                Model.Files.Add(parent);

                CurrentParent = parent;
            }

            // Visit children (E.g. MethodDeclarion objects)
            typeDeclaration.AcceptChildren(this, data);

            return null;
        }
コード例 #4
0
        public static ViewModel MapViewModelFromJsFile(JsFile jsFile)
        {
            var viewModel = new ViewModel
                {
                    FullPath = jsFile.FullPath,
                    Classes = new ObservableCollection<JsClassViewModel>(),
                    CamelCase = true
                };

            foreach (var file in jsFile.Files)
            {
                var jsClass = new JsClassViewModel(viewModel)
                    {
                        Name = file.Name,
                        Properties = new ObservableCollection<JsPropertyViewModel>(),
                        Ignore = false,
                        Enable = false
                    };

                file.Properties.ForEach(p => jsClass.Properties.Add(new JsPropertyViewModel(jsClass)
                    {
                        Ignore = p.Ignore,
                        Name = p.Name,
                        OfType = p.OfType,
                        IsArray = p.IsArray,
                        IsObservable = p.IsObservable
                    }));

                viewModel.Classes.Add(jsClass);
            }

            return viewModel;
        }