private IRoot LoadFromInternal(SyntaxTree tree, string filePath) { //corporation.CheckContainer(); var compilation = CSharpCompilation.Create("MyCompilation", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), syntaxTrees: new[] { tree }, references: new[] { MetadataReference.CreateFromAssembly(typeof(object).Assembly) }); var model = compilation.GetSemanticModel(tree); var root = corporation.Create(tree.GetCompilationUnitRoot(), null, model).FirstOrDefault() as IRoot; //var root = corporation.CreateFrom<IRoot>(tree.GetCompilationUnitRoot(), null, model).FirstOrDefault(); root.FilePath = filePath; return(root); }
//protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model) //{ // var syntax = syntaxNode as CompilationUnitSyntax; // var newItem = new RDomRoot(syntaxNode, parent, model); // // Root does not call StandardInitialize because the info is attched to the first item // // and particularly, whitespace would be doubled. // //CreateFromWorker.InitializePublicAnnotations(newItem, syntaxNode, parent, model); // newItem.Name = "Root"; // CreateFromWorker.LoadStemMembers(newItem, syntax.Members, syntax.Usings, model); // return newItem; //} //public override IEnumerable<SyntaxNode> BuildSyntax(IDom item) //{ // var itemAsT = item as IRoot; // var node = SyntaxFactory.CompilationUnit(); // var usingsSyntax = itemAsT.UsingDirectives // .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) // .ToList(); // var membersSyntax = itemAsT.StemMembers // .Where(x => !(x is IUsingDirective)) // .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) // .ToList(); // node = node.WithUsings(SyntaxFactory.List(usingsSyntax)); // node = node.WithMembers(SyntaxFactory.List(membersSyntax)); // return node.PrepareForBuildSyntaxOutput(item, OutputContext); //} public IRootGroup CreateFrom(Compilation compilation, bool skipDetail) { var csharpCompilation = compilation as CSharpCompilation; if (csharpCompilation == null) { throw new InvalidOperationException(); } var ret = new RDomRootGroup(compilation, _corporation.FactoryAccess); foreach (var tree in compilation.SyntaxTrees) { var model = compilation.GetSemanticModel(tree); var root = _corporation.Create(tree.GetCompilationUnitRoot(), null, model).FirstOrDefault() as IRoot; ret.Roots.AddOrMove(root); } return(ret); }
private static void InitializeBaseList(EnumDeclarationSyntax syntax, RDomEnum newItem, SemanticModel model, ICSharpCreateFromWorker createFromWorker, RDomCorporation corporation) { var symbol = newItem.Symbol as INamedTypeSymbol; if (symbol != null) { var underlyingNamedTypeSymbol = symbol.EnumUnderlyingType; // TODO: underlying type should be set to Int when there is not type specified,there is always an underlying type and the int default might be language specific if (syntax.BaseList != null) { createFromWorker.StoreWhitespaceForToken(newItem, syntax.BaseList.ColonToken, LanguagePart.Current, LanguageElement.BaseListPrefix); var type = corporation .Create(syntax.BaseList.Types.First(), newItem, model) .FirstOrDefault() as IReferencedType; newItem.UnderlyingType = type; createFromWorker.StoreWhitespace(type, syntax.BaseList, LanguagePart.Current, whitespaceLookup); } } }