public BuildAttributeSyntax ( AttributeCollection attributes ) : SyntaxList |
||
attributes | AttributeCollection | |
Résultat | SyntaxList |
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IEvent; var nameSyntax = SyntaxFactory.Identifier(itemAsT.Name); var typeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(itemAsT.Type).First(); var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); var variableNode = SyntaxFactory.VariableDeclarator(nameSyntax); var variableNodes = SyntaxFactory.SeparatedList(new VariableDeclaratorSyntax[] { variableNode }); var eventNode = SyntaxFactory.VariableDeclaration(typeSyntax, variableNodes); eventNode = BuildSyntaxHelpers.AttachWhitespace(eventNode, itemAsT.Whitespace2Set, WhitespaceLookup); var node = SyntaxFactory.EventFieldDeclaration(eventNode) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IEnumMember; Guardian.Assert.IsNotNull(itemAsT, nameof(itemAsT)); var identifier = SyntaxFactory.Identifier(itemAsT.Name); var node = SyntaxFactory.EnumMemberDeclaration(identifier); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } if (itemAsT.Expression != null) { if (itemAsT.Expression.InitialExpressionLanguage != ExpectedLanguages.CSharp) { throw new InvalidOperationException(); } var exprSyntax = SyntaxFactory.ParseExpression(itemAsT.Expression.InitialExpressionString); var equalsValueSyntax = SyntaxFactory.EqualsValueClause(exprSyntax); equalsValueSyntax = BuildSyntaxHelpers.AttachWhitespace(equalsValueSyntax, item.Whitespace2Set, WhitespaceLookup); node = node.WithEqualsValue(equalsValueSyntax); } node = BuildSyntaxHelpers.AttachWhitespace(node, item.Whitespace2Set, WhitespaceLookup); //node = BuildSyntaxHelpers.AttachWhitespaceToFirst(node, item.Whitespace2Set[LanguageElement.EnumValueFirstToken]); //node = BuildSyntaxHelpers.AttachWhitespaceToLast(node, item.Whitespace2Set[LanguageElement.EnumValueLastToken]); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IConversionOperator; var kind = itemAsT.IsImplicit ? SyntaxKind.ImplicitKeyword : SyntaxKind.ExplicitKeyword; var opToken = SyntaxFactory.Token(kind); var typeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(itemAsT.Type).First(); var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); var node = SyntaxFactory.ConversionOperatorDeclaration(opToken, typeSyntax) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } //node = node.WithLeadingTrivia(BuildSyntaxHelpers.LeadingTrivia(item)); var parameterList = itemAsT.Parameters .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) .OfType <ParameterSyntax>() .ToList(); var parameterListSyntax = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameterList)); parameterListSyntax = BuildSyntaxHelpers.AttachWhitespace(parameterListSyntax, itemAsT.Whitespace2Set, WhitespaceLookup); node = node.WithParameterList(parameterListSyntax); node = node.WithBody((BlockSyntax)RoslynCSharpUtilities.BuildStatement(itemAsT.Statements, itemAsT, WhitespaceLookup)); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IParameter; Guardian.Assert.IsNotNull(itemAsT, nameof(itemAsT)); var nameSyntax = SyntaxFactory.Identifier(itemAsT.Name); var syntaxType = (TypeSyntax)(RDom.CSharp.GetSyntaxNode(itemAsT.Type)); syntaxType = BuildSyntaxHelpers.RemoveLeadingSpaces(syntaxType); var node = SyntaxFactory.Parameter(nameSyntax) .WithType(syntaxType); if (itemAsT.DefaultValueType != LiteralKind.Unknown) { var defaultValueExpression = BuildSyntaxHelpers.BuildArgValueExpression( itemAsT.DefaultValue, itemAsT.DefaultConstantIdentifier, itemAsT.DefaultValueType); var defaultClause = SyntaxFactory.EqualsValueClause(defaultValueExpression); defaultClause = BuildSyntaxHelpers.AttachWhitespace(defaultClause, item.Whitespace2Set, WhitespaceLookup); node = node.WithDefault(defaultClause); } var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } var modifiers = SyntaxFactory.TokenList(); if (itemAsT.IsOut) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.OutKeyword)); } if (itemAsT.IsRef) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.RefKeyword)); } if (itemAsT.IsParamArray) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.ParamsKeyword)); } if (modifiers.Any()) { node = node.WithModifiers(modifiers); } node = BuildSyntaxHelpers.AttachWhitespace(node, item.Whitespace2Set, WhitespaceLookup); node = BuildSyntaxHelpers.AttachWhitespaceToFirst(node, item.Whitespace2Set[LanguageElement.ParameterFirstToken]); node = BuildSyntaxHelpers.AttachWhitespaceToLast(node, item.Whitespace2Set[LanguageElement.ParameterLastToken]); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IClass; Guardian.Assert.IsNotNull(itemAsT, nameof(itemAsT)); var modifiers = item.BuildModfierSyntax(); if (itemAsT.IsAbstract) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.AbstractKeyword)); } if (itemAsT.IsSealed) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.SealedKeyword)); } if (itemAsT.IsPartial) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.PartialKeyword)); } var identifier = SyntaxFactory.Identifier(itemAsT.Name); var node = SyntaxFactory.ClassDeclaration(identifier) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, item.Whitespace2Set, whitespaceLookup); var baseList = BuildSyntaxHelpers.GetBaseList(itemAsT); if (baseList != null) { node = node.WithBaseList(baseList); } var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } var membersSyntax = itemAsT.Members .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) .ToList(); node = node.WithMembers(SyntaxFactory.List(membersSyntax)); node = BuildSyntaxHelpers.BuildTypeParameterSyntax( itemAsT, node, whitespaceLookup, (x, p) => x.WithTypeParameterList(p), (x, c) => x.WithConstraintClauses(c)); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IConstructor; var parent = item.Parent as IClass; SyntaxToken nameSyntax; if (parent == null) { nameSyntax = SyntaxFactory.Identifier("unknown_name"); } else { nameSyntax = SyntaxFactory.Identifier(parent.Name); } var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); var node = SyntaxFactory.ConstructorDeclaration(nameSyntax) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } var parameterList = itemAsT.Parameters .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) .OfType <ParameterSyntax>() .ToList(); var parameterListSyntax = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameterList)); parameterListSyntax = BuildSyntaxHelpers.AttachWhitespace(parameterListSyntax, itemAsT.Whitespace2Set, WhitespaceLookup); node = node.WithParameterList(parameterListSyntax); //node = node.WithLeadingTrivia(BuildSyntaxHelpers.LeadingTrivia(item)); node = node.WithBody((BlockSyntax)RoslynCSharpUtilities.BuildStatement(itemAsT.Statements, itemAsT, WhitespaceLookup)); var initializer = BuildInitializer(itemAsT); if (initializer != null) { initializer = BuildSyntaxHelpers.AttachWhitespace(initializer, itemAsT.Whitespace2Set, WhitespaceLookup, LanguagePart.Initializer); node = node.WithInitializer(initializer); } return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IField; var nameSyntax = SyntaxFactory.Identifier(itemAsT.Name); var returnTypeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(itemAsT.ReturnType).First(); var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); if (itemAsT.IsReadOnly) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)); } if (itemAsT.IsConstant) { modifiers = modifiers.Remove(modifiers.Where(x => x.Kind() == SyntaxKind.StaticKeyword).First()); modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.ConstKeyword)); } if (itemAsT.IsVolatile) { modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.VolatileKeyword)); } var declaratorNode = SyntaxFactory.VariableDeclarator(nameSyntax); if (itemAsT.Initializer != null) { var expressionSyntax = (ExpressionSyntax)RDom.CSharp.GetSyntaxNode(itemAsT.Initializer); expressionSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(expressionSyntax, itemAsT.Whitespace2Set[LanguageElement.Expression]); var equalsToken = SyntaxFactory.Token(SyntaxKind.EqualsToken); equalsToken = BuildSyntaxHelpers.AttachWhitespaceToToken(equalsToken, itemAsT.Whitespace2Set[LanguageElement.EqualsAssignmentOperator]); var equalsValueClause = SyntaxFactory.EqualsValueClause(equalsToken, expressionSyntax); declaratorNode = declaratorNode.WithInitializer(equalsValueClause); } declaratorNode = BuildSyntaxHelpers.AttachWhitespace(declaratorNode, itemAsT.Whitespace2Set, WhitespaceLookup); var variableNode = SyntaxFactory.VariableDeclaration(returnTypeSyntax) .WithVariables( SyntaxFactory.SingletonSeparatedList(declaratorNode)); //variableNode = BuildSyntaxHelpers.AttachWhitespace(variableNode, itemAsField.Whitespace2Set, WhitespaceLookup); var node = SyntaxFactory.FieldDeclaration(variableNode) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IProperty; var nameSyntax = SyntaxFactory.Identifier(itemAsT.Name); var returnType = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(itemAsT.ReturnType).First(); var node = SyntaxFactory.PropertyDeclaration(returnType, nameSyntax); var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); node = node.WithModifiers(modifiers); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } var accessors = SyntaxFactory.List <AccessorDeclarationSyntax>(); var getAccessorSyntax = RDom.CSharp.GetSyntaxGroup(itemAsT.GetAccessor).FirstOrDefault(); if (getAccessorSyntax != null) { accessors = accessors.Add((AccessorDeclarationSyntax)getAccessorSyntax); } var setAccessorSyntax = RDom.CSharp.GetSyntaxGroup(itemAsT.SetAccessor).FirstOrDefault(); if (setAccessorSyntax != null) { accessors = accessors.Add((AccessorDeclarationSyntax)setAccessorSyntax); } var accessorList = SyntaxFactory.AccessorList(accessors); accessorList = BuildSyntaxHelpers.AttachWhitespace(accessorList, itemAsT.Whitespace2Set, WhitespaceLookup); if (accessors.Any()) { node = node.WithAccessorList(accessorList); } node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IAccessor; var parentProperty = item.Parent as RDomProperty; // .NET specific if (itemAsT == null || parentProperty == null) { throw new InvalidOperationException(); } var kind = (itemAsT.AccessorType == AccessorType.Get) ? SyntaxKind.GetAccessorDeclaration : SyntaxKind.SetAccessorDeclaration; AccessorDeclarationSyntax node; if (itemAsT.Statements.Any() || !parentProperty.CanBeAutoProperty) { var statementBlock = (BlockSyntax)RoslynCSharpUtilities.BuildStatement(itemAsT.Statements, itemAsT, WhitespaceLookup); node = SyntaxFactory.AccessorDeclaration(kind, statementBlock); } else { node = SyntaxFactory.AccessorDeclaration(kind).WithSemicolonToken( SyntaxFactory.Token( SyntaxKind.SemicolonToken)); } if (itemAsT.AccessModifier != parentProperty.AccessModifier) { var modifiers = item.BuildModfierSyntax(); node = node.WithModifiers(modifiers); } node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributeList = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributeList.Any()) { node = node.WithAttributeLists(attributeList); } return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IEnum; Guardian.Assert.IsNotNull(itemAsT, nameof(itemAsT)); var modifiers = item.BuildModfierSyntax(); var identifier = SyntaxFactory.Identifier(itemAsT.Name); var node = SyntaxFactory.EnumDeclaration(identifier) .WithModifiers(modifiers); var baseList = GetBaseList(itemAsT); if (baseList != null) { node = node.WithBaseList(baseList); } var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } var memberList = itemAsT.Members .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) .OfType <EnumMemberDeclarationSyntax>() .ToList(); if (memberList.Any()) { var memberListSyntax = SyntaxFactory.SeparatedList(memberList); node = node.WithMembers(memberListSyntax); } node = BuildSyntaxHelpers.AttachWhitespace(node, item.Whitespace2Set, whitespaceLookup); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IDestructor; var nameSyntax = SyntaxFactory.Identifier(itemAsT.Name); var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); var node = SyntaxFactory.DestructorDeclaration(nameSyntax) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } //node = node.WithLeadingTrivia(BuildSyntaxHelpers.LeadingTrivia(item)); node = node.WithBody((BlockSyntax)RoslynCSharpUtilities.BuildStatement(itemAsT.Statements, itemAsT, WhitespaceLookup)); return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }
public override IEnumerable <SyntaxNode> BuildSyntax(IDom item) { var itemAsT = item as IMethod; var nameSyntax = SyntaxFactory.Identifier(itemAsT.Name); var returnTypeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(itemAsT.ReturnType).First(); var modifiers = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT); var node = SyntaxFactory.MethodDeclaration(returnTypeSyntax, nameSyntax) .WithModifiers(modifiers); node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup); var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes); if (attributes.Any()) { node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes)); } var parameterList = itemAsT.Parameters .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) .OfType <ParameterSyntax>() .ToList(); if (itemAsT.IsExtensionMethod) { // this this is a normal list, ref semantics var firstParam = parameterList.FirstOrDefault(); parameterList.Remove(firstParam); if (firstParam == null) { throw new InvalidOperationException("Extension methods must have at least one parameter"); } // I'm cheating a bit here. Since the This keyword is an indicator of extension state on the method // I'm hardcoding a single space. I don't see the complexity of dealing with this as worth it unless // there's gnashing of teeth over this single space. The use of "this" on the parameter is not universal // and VB marks the method. var thisModifier = SyntaxFactory.Token(SyntaxKind.ThisKeyword) .WithTrailingTrivia(SyntaxFactory.ParseTrailingTrivia(" ")); var paramModifiers = firstParam.Modifiers.Insert(0, thisModifier); firstParam = firstParam.WithModifiers(paramModifiers); parameterList.Insert(0, firstParam); } var parameterListSyntax = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameterList)); parameterListSyntax = BuildSyntaxHelpers.AttachWhitespace(parameterListSyntax, itemAsT.Whitespace2Set, WhitespaceLookup); node = node.WithParameterList(parameterListSyntax); node = node.WithBody((BlockSyntax)RoslynCSharpUtilities.BuildStatement(itemAsT.Statements, itemAsT, WhitespaceLookup)); // This works oddly because it uncollapses the list // This code is largely repeated in interface and class factories, but is very hard to refactor because of shallow Roslyn (Microsoft) architecture var typeParamsAndConstraints = itemAsT.TypeParameters .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x)) .ToList(); node = BuildSyntaxHelpers.BuildTypeParameterSyntax( itemAsT, node, WhitespaceLookup, (x, p) => x.WithTypeParameterList(p), (x, c) => x.WithConstraintClauses(c)); //var typeParameterSyntaxList = BuildSyntaxHelpers.GetTypeParameterSyntaxList( // typeParamsAndConstraints, itemAsT.Whitespace2Set, WhitespaceLookup); //if (typeParameterSyntaxList != null) //{ // node = node.WithTypeParameterList(typeParameterSyntaxList); // var clauses = BuildSyntaxHelpers.GetTypeParameterConstraintList( // typeParamsAndConstraints, itemAsT.Whitespace2Set, WhitespaceLookup); // if (clauses.Any()) // { node = node.WithConstraintClauses(clauses); } //} return(node.PrepareForBuildSyntaxOutput(item, OutputContext)); }