예제 #1
0
            public override SyntaxNode?VisitIdentifierName(IdentifierNameSyntax node)
            {
                var isInsideCast  = Helpers.IsInsideCast(node);
                var isValidParent = !Helpers.IsInsideMethod(node).result &&
                                    !Helpers.IsInsideMemberAccessExpression(node).result &&
                                    !isInsideCast.result;

                if (isValidParent && !_isStaticMember(node.ToFullString()))
                {
                    var newIdentifier = node.ToFullString();

                    var rawFunction = string.IsNullOrWhiteSpace(newIdentifier)
                                                ? $"class __Temp {{ private Func<object> __prop => {_contextName}; }}"
                                                : $"class __Temp {{ private Func<object> __prop => {ContextBuilder}{newIdentifier}; }}";

                    var output = ParseCompilationUnit(rawFunction);

                    var o2 = output.DescendantNodes().OfType <ArrowExpressionClauseSyntax>().First().Expression;
                    return(o2);
                }
                else
                {
                    return(base.VisitIdentifierName(node));
                }
            }
예제 #2
0
        public override void VisitIdentifierName(IdentifierNameSyntax node)
        {
            if (debug)
            {
                Console.WriteLine(node.ToFullString());
            }
            var nl = OurLine.NewLine(LineKind.Decl, "IdentifierName");

            nl.Source = node.ToFullString();
            OurLine.AddEssentialInfo(ref nl, "name:" + node.Identifier.ToString());
            nl.ParentKind = node.Parent.RawKind;
            nl.RawKind    = node.RawKind;
            LogCommand(nl);
            base.VisitIdentifierName(node);
        }
 public override void VisitIdentifierName(IdentifierNameSyntax node)
 {
     if (node.ToFullString().ToLower().Contains("serializer"))
     {
         Types.Add(node);
     }
 }
예제 #4
0
        public static string FromDDBTableModel(TableDescription ddbTable)
        {
            var className = GetClassName(ddbTable);
            var code      = CompilationUnit();

            code = code.AddUsings(DynamoUsingToken.NormalizeWhitespace());
            var classDeclaration = ClassDeclaration(className)
                                   .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
                                   .AddModifiers(SyntaxFactory.Token(SyntaxKind.PartialKeyword))
                                   .AddAttributeLists(
                AttributeList(
                    SingletonSeparatedList <AttributeSyntax>(
                        TableNameAttribute(ddbTable.TableName)
                        )
                    )
                );
            var properties = new List <MemberDeclarationSyntax>();

            foreach (var ks in ddbTable.KeySchema)
            {
                var attr = ddbTable.AttributeDefinitions.Single(ad => ad.AttributeName == ks.AttributeName);

                // if (prop == null || string.IsNullOrEmpty(prop.Name) || string.IsNullOrEmpty(prop.Type)) continue;
                var property = PropertyDeclaration(ParseTypeName(FindType(attr.AttributeType)), attr.AttributeName)
                               .AddAccessorListAccessors(new AccessorDeclarationSyntax[]
                {
                    AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                    .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),
                    AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                    .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))
                })
                               .NormalizeWhitespace();
                if (ks.KeyType == HashType)
                {
                    System.Console.WriteLine("Adding annotation...");
                    System.Console.WriteLine(HashKeyToken.ToFullString());
                    property = property.AddAttributeLists(
                        AttributeList(SingletonSeparatedList <AttributeSyntax>(
                                          Attribute(HashKeyToken)
                                          )
                                      )
                        .NormalizeWhitespace());
                }
                else if (ks.KeyType == RangeType)
                {
                    property = property.AddAttributeLists(
                        AttributeList(SingletonSeparatedList <AttributeSyntax>(
                                          Attribute(RangeKeyToken)
                                          )
                                      )
                        .NormalizeWhitespace());
                }
                properties.Add(property);
            }

            classDeclaration = classDeclaration.AddMembers(properties.ToArray()).NormalizeWhitespace();
            code             = code.AddMembers(classDeclaration).NormalizeWhitespace();
            System.Console.WriteLine(code.ToFullString());
            return(code.ToFullString());
        }
예제 #5
0
        //Actual code to update tree node
        private async Task <Document> ReplaceNameAsync(Document doc, IdentifierNameSyntax usingNode, CancellationToken c)
        {
            //TODO GO through this code and remove unecessary bits

            //grab the Windows token to replace
            var winToken = usingNode.DescendantTokens().Single(n => n.Text == "Windows");

            //grab leading trivia for first token
            var winLeadTrivia = winToken.LeadingTrivia;
            //grab traling trivia
            var winTrailTrivia = winToken.TrailingTrivia;

            //create a Microsoft token with old trivia
            var micToken = SyntaxFactory.Identifier(winLeadTrivia, SyntaxKind.IdentifierToken, "Microsoft", "Microsoft", winTrailTrivia);

            //Replace node with new
            var newNode = usingNode.ReplaceToken(winToken, micToken);



            // add annotations to format the new token d
            //TODO: TEST IF NECESSARY! - Sometimes removes tabs etc, consider removing entirely
            var formattedNode = newNode.WithAdditionalAnnotations(Formatter.Annotation);

            // replace the old win token with new Microsoft
            var oldRoot = await doc.GetSyntaxRootAsync(c);

            Debug.WriteLine(usingNode.ToFullString());
            Debug.WriteLine(newNode.ToFullString());
            //Try Not using formattedNode
            var newRoot = oldRoot.ReplaceNode(usingNode, newNode);

            // Return a new doc wit htransfromed tree
            return(doc.WithSyntaxRoot(newRoot));
        }
예제 #6
0
            public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
            {
                var isValidParent = !Helpers.IsInsideMethod(node).result&& !Helpers.IsInsideMemberAccessExpression(node).result;

                if (isValidParent)
                {
                    var newIdentifier = node.ToFullString();
                    var output        = ParseCompilationUnit($"class __Temp {{ private Func<object> __prop => {ContextBuilder}{newIdentifier}; }}");

                    var o2 = output.DescendantNodes().OfType <ArrowExpressionClauseSyntax>().First().Expression;
                    return(o2);
                }
                else
                {
                    return(base.VisitIdentifierName(node));
                }
            }
예제 #7
0
            public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
            {
                var e = base.VisitInvocationExpression(node);

                var isParentMemberStatic = node.Expression switch
                {
                    MemberAccessExpressionSyntax ma => _isStaticMember(ma.Expression.ToFullString()),
                    IdentifierNameSyntax ins => _isStaticMember(ins.ToFullString()),
                    _ => false
                };

                var isValidParent = !Helpers.IsInsideMethod(node).result &&
                                    !Helpers.IsInsideMemberAccessExpression(node).result &&
                                    !Helpers.IsInsideMemberAccessExpression(node.Expression).result;

                if (isValidParent && !_isStaticMember(node.Expression.ToFullString()) && !isParentMemberStatic)
                {
                    if (e is InvocationExpressionSyntax newSyntax)
                    {
                        var methodName = newSyntax.Expression.ToFullString();
                        var arguments  = newSyntax.ArgumentList.ToFullString();
                        var output     = ParseCompilationUnit($"class __Temp {{ private Func<object> __prop => {ContextBuilder}{methodName}{arguments}; }}");

                        var o2 = output.DescendantNodes().OfType <ArrowExpressionClauseSyntax>().First().Expression;
                        return(o2);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    return(e);
                }
            }
예제 #8
0
        public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
        {
            if (substitutionNames.ContainsKey(node.Identifier.Text)) // pre-rest on name for performance
            {
                ISymbol identifierSymbol = semanticModel.GetSymbolInfo(node).Symbol;
                if (identifierSymbol != null)
                {
                    ExpressionSyntax constValue;
                    if (substitutions.TryGetValue(identifierSymbol, out constValue))
                    {
#pragma warning disable CS0162 // unreachable
                        if (trace)
                        {
                            Console.WriteLine("CONSTSUBST: {0}: {1} ==> {2}", GetTraceParent(node).ToFullString(), node.ToFullString(), constValue.ToFullString());
                        }
#pragma warning restore CS0162
                        return(constValue.WithTriviaFrom(node));
                    }
                }
            }

            return(base.VisitIdentifierName(node));
        }