private void InitializeTypeParameters(IHasTypeParameters itemAsT, SyntaxNode node, IDom parent, SemanticModel model) { if (itemAsT == null) { return; } //var symbol = ((IRoslynHasSymbol)itemAsT).Symbol as INamedTypeSymbol; //var interfaces = symbol.Interfaces; var typeParameterList = node.ChildNodes().OfType <TypeParameterListSyntax>().SingleOrDefault(); if (typeParameterList == null) { return; } var typeParameters = typeParameterList.Parameters; foreach (var p in typeParameters) { var newBase = Corporation.Create(p, itemAsT, model).Single() as ITypeParameter; itemAsT.TypeParameters.AddOrMove(newBase); } }
public void LoadStemMembers(IStemContainer newItem, IEnumerable <MemberDeclarationSyntax> memberSyntaxes, IEnumerable <UsingDirectiveSyntax> usingSyntaxes, SemanticModel model) { newItem.StemMembersAll.CreateAndAdd(usingSyntaxes, x => Corporation.Create(x, newItem, model).OfType <IStemMemberAndDetail>()); newItem.StemMembersAll.CreateAndAdd(memberSyntaxes, x => Corporation.Create(x, newItem, model).OfType <IStemMemberAndDetail>()); }
private bool TryTyepofExpression(TypeOfExpressionSyntax typeOfExpression, IDom newItem, SemanticModel model, ref object value, ref LiteralKind literalKind, ref string constantIdentifier) { if (typeOfExpression == null) { return(false); } literalKind = LiteralKind.Type; value = Corporation .Create(typeOfExpression.Type, newItem, model) .FirstOrDefault() as IReferencedType; return(true); }
public void InitializeStatements(IStatementBlock itemAsStatement, SyntaxNode syntaxNode, IDom parent, SemanticModel model) { if (syntaxNode == null) { return; } if (itemAsStatement == null) { return; } var blockSyntax = syntaxNode as BlockSyntax; if (blockSyntax != null) { itemAsStatement.StatementsAll.CreateAndAdd(blockSyntax.Statements, x => Corporation.Create(x, parent, model).Cast <IStatementAndDetail>()); itemAsStatement.HasBlock = true; return; } var statementSyntax = syntaxNode as StatementSyntax; if (statementSyntax != null) { var statements = Corporation.Create(statementSyntax, parent, model).OfType <IStatementAndDetail>(); if (statements.Count() > 1) { throw new NotImplementedException(); } var statement = statements.First(); var statementAsBlockStatement = statement as IBlockStatement; if (statementAsBlockStatement != null) { itemAsStatement.HasBlock = true; foreach (var st in statementAsBlockStatement.Statements) { itemAsStatement.StatementsAll.AddOrMove(st); } } else { itemAsStatement.StatementsAll.AddOrMove(statement); } } }
//public void InitializePublicAnnotations(IDom item, SyntaxNode syntaxNode, IDom parent, SemanticModel model) //{ // var publicAnnotations = GetPublicAnnotations(syntaxNode, item, model); // item.PublicAnnotations.Add(publicAnnotations); //} private void InitializeAttributes(IHasAttributes itemAsHasAttributes, SyntaxNode syntaxNode, IDom parent, SemanticModel model) { if (itemAsHasAttributes == null) { return; } var attributes = new List <IAttribute>(); var attributeLists = syntaxNode.ChildNodes().OfType <AttributeListSyntax>(); foreach (var attributeList in attributeLists) { // Flatten list // Force whitespace if (attributeList != null) { var attr = Corporation.Create(attributeList, itemAsHasAttributes, model).OfType <IAttribute>(); attributes.AddRange(attr); } } itemAsHasAttributes.Attributes.AddOrMoveAttributeRange(attributes); }
private void InitializeBaseList(IHasImplementedInterfaces itemAsT, SyntaxNode node, IDom parent, SemanticModel model) { if (itemAsT == null) { return; } var symbol = ((IRoslynHasSymbol)itemAsT).Symbol as INamedTypeSymbol; var interfaces = symbol.Interfaces; var baseType = symbol.BaseType; var baseList = node.ChildNodes().OfType <BaseListSyntax>().SingleOrDefault(); if (baseList != null) { IEnumerable <BaseTypeSyntax> types = baseList.Types.ToList(); StoreWhitespaceForToken(itemAsT, baseList.ColonToken, LanguagePart.Current, LanguageElement.BaseListPrefix); if (baseType != null) { var baseName = baseType.ToString(); baseName = baseName.Contains(".") ? baseName.SubstringAfterLast(".") : baseName; if (node is ClassDeclarationSyntax && baseName == types.First().ToString()) { var itemAsClass = itemAsT as RDomClass; var syntax = types.First(); if (itemAsClass == null) { throw new InvalidOperationException(); } var newBaseType = Corporation.Create(syntax, itemAsT, model).Single() as IReferencedType; itemAsClass.BaseType = newBaseType; //StoreWhitespace(newBaseType, syntax, // LanguagePart.Current, whitespaceLookupForImplementedInterfaces); types = types.Skip(1); } } foreach (var implementedInterfaceSyntax in types) { var newInterface = Corporation.Create(implementedInterfaceSyntax, itemAsT, model).Single() as IReferencedType; //StoreWhitespace(newInterface, implementedInterfaceSyntax, // LanguagePart.Current, whitespaceLookupForImplementedInterfaces); var whitespace2 = newInterface.Whitespace2Set[LanguageElement.Identifier]; if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace)) { var prevNodeOrToken = implementedInterfaceSyntax.Parent .ChildNodesAndTokens() .PreviousSiblings(implementedInterfaceSyntax) .LastOrDefault(); var sepKind = whitespaceLookupForImplementedInterfaces.Lookup(LanguageElement.Separator); if (prevNodeOrToken.Kind() == sepKind) { var commaToken = prevNodeOrToken.AsToken(); whitespace2.LeadingWhitespace = commaToken.TrailingTrivia.ToString(); } } itemAsT.ImplementedInterfaces.AddOrMove(newInterface); } } }