public override IEnumerable <SyntaxNode> BuildSyntax(IDom item)
        {
            var itemAsT = item as IAttributeValue;

            var argNameSyntax = SyntaxFactory.IdentifierName(itemAsT.Name);

            argNameSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirst(argNameSyntax, item.Whitespace2Set[LanguageElement.AttributeValueName]);
            argNameSyntax = BuildSyntaxHelpers.AttachWhitespaceToLast(argNameSyntax, item.Whitespace2Set[LanguageElement.AttributeValueName]);

            //var kind = Mappings.SyntaxKindFromLiteralKind(itemAsT.ValueType, itemAsT.Value);
            ExpressionSyntax expr = BuildSyntaxHelpers.BuildArgValueExpression(
                itemAsT.Value, itemAsT.ValueConstantIdentifier, itemAsT.ValueType);
            var node = SyntaxFactory.AttributeArgument(expr);

            if (itemAsT.Style == AttributeValueStyle.Colon)
            {
                var nameColon = SyntaxFactory.NameColon(argNameSyntax);
                nameColon = BuildSyntaxHelpers.AttachWhitespaceToLast(nameColon, item.Whitespace2Set[LanguageElement.AttributeValueEqualsOrColon]);
                node      = node.WithNameColon(nameColon);
            }
            else if (itemAsT.Style == AttributeValueStyle.Equals)
            {
                var nameEquals = SyntaxFactory.NameEquals(argNameSyntax);
                nameEquals = BuildSyntaxHelpers.AttachWhitespaceToLast(nameEquals, item.Whitespace2Set[LanguageElement.AttributeValueEqualsOrColon]);
                node       = node.WithNameEquals(nameEquals);
            }
            node = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(node, item.Whitespace2Set[LanguageElement.AttributeValueValue]);

            return(node.PrepareForBuildSyntaxOutput(item, OutputContext));
        }
Example #2
0
        private SyntaxNode GetConstraintClause(string name, ITypeParameter itemAsT)
        {
            var list = new List <TypeParameterConstraintSyntax>();

            if (itemAsT.HasValueTypeConstraint)
            {
                list.Add(SyntaxFactory.ClassOrStructConstraint(SyntaxKind.StructConstraint));
            }
            else if (itemAsT.HasReferenceTypeConstraint)
            {
                list.Add(SyntaxFactory.ClassOrStructConstraint(SyntaxKind.ClassConstraint));
            }

            foreach (var typeConstraint in itemAsT.ConstraintTypes)
            {
                var typeSyntax = (TypeSyntax)RDom.CSharp
                                 .GetSyntaxNode(typeConstraint);
                var typeConstraintSyntax = SyntaxFactory.TypeConstraint(typeSyntax);
                list.Add(typeConstraintSyntax);
            }

            // New has to be last
            if (itemAsT.HasConstructorConstraint)
            {
                var constructorConstraint = SyntaxFactory.ConstructorConstraint();
                constructorConstraint = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(constructorConstraint, itemAsT.Whitespace2Set[LanguageElement.ConstructorConstraint]);
                list.Add(constructorConstraint);
            }

            var syntax = SyntaxFactory.TypeParameterConstraintClause(name)
                         .WithConstraints(SyntaxFactory.SeparatedList(list));

            syntax = BuildSyntaxHelpers.AttachWhitespace(syntax, itemAsT.Whitespace2Set, WhitespaceLookup, LanguagePart.Constraint);
            return(syntax);
        }
        public override IEnumerable <SyntaxNode> BuildSyntax(IDom item)
        {
            var itemAsT    = item as IAssignmentStatement;
            var leftSyntax = RDom.CSharp.GetSyntaxNode(itemAsT.Left);

            leftSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(leftSyntax,
                                                                           itemAsT.Whitespace2Set[LanguageElement.LeftExpression]);

            var expressionSyntax = RDom.CSharp.GetSyntaxNode(itemAsT.Expression);

            expressionSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(expressionSyntax,
                                                                                 itemAsT.Whitespace2Set[LanguageElement.Expression]);

            var syntaxKind = Mappings.SyntaxKindFromAssignmentOperator(itemAsT.Operator);
            var opToken    = SyntaxFactory.Token(Mappings.SyntaxTokenKindFromAssignmentOperator(itemAsT.Operator));

            opToken = BuildSyntaxHelpers.AttachWhitespaceToToken(opToken, itemAsT.Whitespace2Set[LanguageElement.AssignmentOperator]);

            var assignmentSyntax = SyntaxFactory.AssignmentExpression(syntaxKind,
                                                                      (ExpressionSyntax)leftSyntax,
                                                                      opToken,
                                                                      (ExpressionSyntax)expressionSyntax);

            assignmentSyntax = BuildSyntaxHelpers.AttachWhitespace(assignmentSyntax, itemAsT.Whitespace2Set, WhitespaceLookup);
            var node = SyntaxFactory.ExpressionStatement(assignmentSyntax);

            node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup);
            return(node.PrepareForBuildSyntaxOutput(item, OutputContext));
        }
        public override IEnumerable <SyntaxNode> BuildSyntax(IDom item)
        {
            var itemAsT          = item as IArgument;
            var modifiers        = BuildSyntaxHelpers.BuildModfierSyntax(itemAsT);
            var expressionSyntax = (ExpressionSyntax)RDom.CSharp.GetSyntaxNode(itemAsT.ValueExpression);

            expressionSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(expressionSyntax, itemAsT.Whitespace2Set[LanguageElement.Expression]);
            var node = SyntaxFactory.Argument(expressionSyntax);

            if (itemAsT.IsOut)
            {
                node = node.WithRefOrOutKeyword(SyntaxFactory.Token(SyntaxKind.OutKeyword));
            }
            else if (itemAsT.IsRef)
            {
                node = node.WithRefOrOutKeyword(SyntaxFactory.Token(SyntaxKind.RefKeyword));
            }
            node = BuildSyntaxHelpers.AttachWhitespaceToFirst(node, itemAsT.Whitespace2Set[LanguageElement.OutModifier]);
            node = BuildSyntaxHelpers.AttachWhitespaceToFirst(node, itemAsT.Whitespace2Set[LanguageElement.RefModifier]);

            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));
        }
Example #5
0
        public TypeSyntax GetVariableTypeSyntax(bool isImplicitlyTyped, IReferencedType type)
        {
            TypeSyntax typeSyntax;

            if (isImplicitlyTyped)
            {
                typeSyntax = SyntaxFactory.ParseTypeName("var");
                typeSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(typeSyntax, type.Whitespace2Set.First());
            }
            else
            {
                typeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(type).First();
            }
            return(typeSyntax);

            //if (itemAsVariable.IsImplicitlyTyped)
            //{ return SyntaxFactory.IdentifierName("var"); }

            //var type = itemAsVariable.Type;
            //if (itemAsVariable.IsAliased)
            //{
            //    var typeName = Mappings.AliasFromSystemType(type.Name);
            //    return SyntaxFactory.IdentifierName(typeName);
            //}
            //return (TypeSyntax)(RDomCSharp.Factory.BuildSyntax(type));
        }
Example #6
0
        private ExpressionSyntax GetCondition(IHasCondition itemAsT)
        {
            var expression = (ExpressionSyntax)RDom.CSharp.GetSyntaxNode(itemAsT.Condition);

            expression = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(expression,
                                                                           itemAsT.Whitespace2Set[LanguageElement.Expression]);
            return(expression);
        }
Example #7
0
        public override IEnumerable <SyntaxNode> BuildSyntax(IDom item)
        {
            var itemAsT          = item as IInvocationStatement;
            var expressionSyntax = RDom.CSharp.GetSyntaxNode(itemAsT.Invocation);
            var node             = SyntaxFactory.ExpressionStatement((ExpressionSyntax)expressionSyntax);

            node = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(node,
                                                                     itemAsT.Whitespace2Set[LanguageElement.Expression]);
            return(node.PrepareForBuildSyntaxOutput(item, OutputContext));
        }
Example #8
0
        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));
        }
        private ArgumentSyntax GetArgumentSyntax(IArgument arg)
        {
            var expressionSyntax = (ExpressionSyntax)RDom.CSharp.GetSyntaxNode(arg.ValueExpression);

            expressionSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(expressionSyntax, arg.Whitespace2Set[LanguageElement.Expression]);
            var argSyntax = SyntaxFactory.Argument(expressionSyntax);

            argSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirst(argSyntax, arg.Whitespace2Set[LanguageElement.ConstructorInitializerArgument]);
            return(argSyntax);
            //argSyntax = BuildSyntaxHelpers.AttachWhitespace(argSyntax, arg.Whitespace2Set, WhitespaceLookup);
            //argSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirst(argSyntax, arg.Whitespace2Set[LanguageElement.ConstructorInitializerArgument]);
            //argSyntax = BuildSyntaxHelpers.AttachWhitespaceToLast(argSyntax, arg.Whitespace2Set[LanguageElement.ParameterLastToken]);
            //return (ArgumentSyntax)argSyntax.PrepareForBuildSyntaxOutput(arg).First();
        }
        private IEnumerable <SyntaxNode> BuildSyntaxLocal(IVariableDeclaration itemAsT, TypeSyntax typeSyntax)
        {
            var node = SyntaxFactory.VariableDeclarator(itemAsT.Name);

            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);
                //equalsValueClause = BuildSyntaxHelpers.AttachWhitespace(equalsValueClause, itemAsT.Whitespace2Set, WhitespaceLookup);
                node = node.WithInitializer(equalsValueClause);
            }

            node = BuildSyntaxHelpers.AttachWhitespace(node, itemAsT.Whitespace2Set, WhitespaceLookup);
            // Not a statement, so should not call PrepareForBuildSyntaxOutput
            return(new SyntaxNode[] { node });
        }
Example #11
0
        protected override SyntaxNode AdjustWhitespace(SyntaxNode node, RDomForStatement item, WhitespaceKindLookup WhitespaceLookup)
        {
            var itemAsT = item as RDomForStatement;
            var syntax  = node as ForStatementSyntax;

            //var origToken = syntax.FirstSemicolonToken;
            //var newToken = BuildSyntaxHelpers.AttachWhitespaceToToken(origToken ,
            //               item.Whitespace2Set[LanguagePart.Variable, LanguageElement.EndOfLine]);
            //syntax = syntax.ReplaceToken(origToken, newToken);

            var origNode = syntax.Incrementors.First();
            var newNode  = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(origNode,
                                                                             item.Whitespace2Set[LanguagePart.Iterator, LanguageElement.Identifier]);

            syntax = syntax.ReplaceNode(origNode, newNode);
            //origToken = syntax.SecondSemicolonToken;
            //newToken = BuildSyntaxHelpers.AttachWhitespaceToToken(origToken,
            //           item.Whitespace2Set[LanguagePart.Variable, LanguageElement.EndOfLine]);
            //syntax = syntax.ReplaceToken(origToken, newToken);

            return(syntax);
        }