예제 #1
0
        public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
        {
            // get base interfaces
            var interfaces = (node.BaseList?.Types ?? Enumerable.Empty <BaseTypeSyntax>()).ToArray();

            // create the interface
            var interfaceDeclaration = new ApexInterfaceDeclarationSyntax
            {
                Identifier = node.Identifier.ValueText,
                BaseType   = ConvertBaseType(interfaces.FirstOrDefault()),
                Modifiers  = node.Modifiers.Select(m => m.ToString()).ToList(),
            };

            foreach (var attr in node.AttributeLists.EmptyIfNull())
            {
                attr.Accept(this);
                AddAnnotationOrModifier(interfaceDeclaration, ConvertClassAnnotation(LastAnnotation));
            }

            foreach (var member in node.Members.EmptyIfNull())
            {
                member.Accept(this);
                if (LastClassMember != null)
                {
                    interfaceDeclaration.Members.Add(LastClassMember);
                    LastClassMember = null;
                }
            }

            interfaceDeclaration.InnerComments = NoApexComments.Concat(
                Comments.ToList(node.CloseBraceToken.LeadingTrivia)).ToList();
            NoApexComments.Clear();
            LastClassMember = interfaceDeclaration;
        }
예제 #2
0
        private List <string> GetLeadingAndNoApexComments(CSharpSyntaxNode node)
        {
            var result = NoApexComments.Concat(Comments.Leading(node)).ToList();

            NoApexComments.Clear();
            return(result);
        }
예제 #3
0
        private List <string> GetLeadingAndNoApexComments(SyntaxToken token)
        {
            var result = NoApexComments.Concat(Comments.Leading(token)).ToList();

            NoApexComments.Clear();
            return(result);
        }
예제 #4
0
        public override void VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            // get base types
            var baseTypes  = (node.BaseList?.Types ?? Enumerable.Empty <BaseTypeSyntax>()).ToList();
            var baseType   = ConvertBaseType(baseTypes.FirstOrDefault());
            var interfaces = new List <ApexTypeSyntax>();

            if (baseTypes.Count > 1)
            {
                interfaces = ConvertBaseTypes(baseTypes.Skip(1).ToList());
            }

            // assume that types starting with the capital 'I' are interfaces
            if (baseType?.Identifier?.StartsWith("I") ?? false)
            {
                interfaces.Insert(0, baseType);
                baseType = null;
            }

            // create the class
            var classDeclaration = new ApexClassDeclarationSyntax
            {
                Identifier       = node.Identifier.ValueText,
                BaseType         = baseType,
                Interfaces       = interfaces,
                Modifiers        = node.Modifiers.Select(m => m.ToString()).ToList(),
                LeadingComments  = Comments.Leading(node),
                TrailingComments = Comments.Trailing(node),
            };

            foreach (var attr in node.AttributeLists.EmptyIfNull())
            {
                attr.Accept(this);
                AddAnnotationOrModifier(classDeclaration, ConvertClassAnnotation(LastAnnotation));
            }

            // skip members auto-generated by ApexParser
            var members =
                from member in node.Members.EmptyIfNull()
                where member != null && !IsAutoGenerated(member)
                select member;

            foreach (var member in members)
            {
                member.Accept(this);
                if (LastClassMember != null)
                {
                    classDeclaration.Members.Add(LastClassMember);
                    LastClassMember = null;
                }
            }

            classDeclaration.InnerComments = NoApexComments.Concat(
                Comments.ToList(node.CloseBraceToken.LeadingTrivia)).ToList();
            NoApexComments.Clear();
            LastClassMember = classDeclaration;
        }
예제 #5
0
        public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            LastEnumMember = new ApexEnumMemberDeclarationSyntax
            {
                LeadingComments = NoApexComments.ToList(),
                Identifier      = node.Identifier.ValueText,
            };

            NoApexComments.Clear();
        }
예제 #6
0
        public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            var method = new ApexConstructorDeclarationSyntax
            {
                LeadingComments  = NoApexComments.Concat(Comments.Leading(node)).ToList(),
                Identifier       = node.Identifier.ValueText,
                Modifiers        = node.Modifiers.Select(m => m.ToString()).ToList(),
                TrailingComments = Comments.Trailing(node),
            };

            NoApexComments.Clear();
            foreach (var attr in node.AttributeLists.EmptyIfNull())
            {
                attr.Accept(this);
                AddAnnotationOrModifier(method, ConvertMethodAnnotation(LastAnnotation));
            }

            foreach (var param in node.ParameterList?.Parameters.EmptyIfNull())
            {
                param.Accept(this);
                method.Parameters.Add(LastParameter);
            }

            if (node.Body != null)
            {
                node.Body.Accept(this);
                method.Body   = LastStatement as ApexBlockSyntax;
                LastStatement = null;

                if (!method.TrailingComments.IsNullOrEmpty())
                {
                    method.Body.TrailingComments = method.TrailingComments.ToList();
                    method.TrailingComments.Clear();
                }
            }

            if (method.Modifiers.All(m => m != "static"))
            {
                LastClassMember = method;
            }
            else
            {
                // static constructors are converted to the class initializers
                LastClassMember = new ApexClassInitializerSyntax
                {
                    Modifiers        = method.Modifiers,
                    Annotations      = method.Annotations,
                    Body             = method.Body,
                    LeadingComments  = method.LeadingComments,
                    TrailingComments = method.TrailingComments,
                };
            }
        }
예제 #7
0
        public override void VisitBlock(BlockSyntax node)
        {
            var block = new ApexBlockSyntax();

            foreach (var stmt in node.Statements.EmptyIfNull())
            {
                stmt.Accept(this);
                if (LastStatement != null)
                {
                    block.Statements.Add(LastStatement);
                    LastStatement = null;
                }
            }

            block.InnerComments = NoApexComments.ToList();
            NoApexComments.Clear();
            LastStatement = LastBlock = block;
        }
예제 #8
0
        public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
        {
            var enumeration = new ApexEnumDeclarationSyntax
            {
                Identifier = node.Identifier.ValueText,
                Modifiers  = node.Modifiers.Select(m => m.ToString()).ToList(),
            };

            foreach (var member in node.Members.EmptyIfNull())
            {
                member.Accept(this);
                enumeration.Members.Add(LastEnumMember);
            }

            enumeration.InnerComments = NoApexComments.Concat(
                Comments.ToList(node.CloseBraceToken.LeadingTrivia)).ToList();
            NoApexComments.Clear();
            LastClassMember = enumeration;
        }
예제 #9
0
        public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            var field = new ApexFieldDeclarationSyntax
            {
                LeadingComments  = NoApexComments.Concat(Comments.Leading(node)).ToList(),
                TrailingComments = Comments.Trailing(node),
                Type             = ConvertType(node.Declaration.Type),
                Modifiers        = node.Modifiers.Select(m => m.ToString()).ToList(),
            };

            // readonly modifier converted to final
            var index = field.Modifiers.IndexOf("readonly");

            if (index >= 0)
            {
                field.Modifiers[index] = ApexKeywords.Final;
            }

            NoApexComments.Clear();
            foreach (var attr in node.AttributeLists.EmptyIfNull())
            {
                attr.Accept(this);
                AddAnnotationOrModifier(field, ConvertFieldAnnotation(LastAnnotation));
            }

            if (node.Declaration != null)
            {
                node.Declaration.Accept(this);
            }

            if (LastVariableDeclaration != null)
            {
                field.Type   = LastVariableDeclaration.Type;
                field.Fields = LastVariableDeclaration.Variables.Select(v => new ApexFieldDeclaratorSyntax
                {
                    Identifier = v.Identifier,
                    Expression = v.Expression,
                }).ToList();
            }

            LastClassMember = field;
        }
예제 #10
0
        public override void VisitBlock(BlockSyntax node)
        {
            var block = new ApexBlockSyntax
            {
                LeadingComments  = GetLeadingAndNoApexComments(node),
                TrailingComments = Comments.Trailing(node),
            };

            foreach (var stmt in node.Statements.EmptyIfNull())
            {
                stmt.Accept(this);
                if (LastStatement != null)
                {
                    block.Statements.Add(LastStatement);
                    LastStatement = null;
                }
            }

            block.InnerComments = GetLeadingAndNoApexComments(node.CloseBraceToken);
            NoApexComments.Clear();
            LastStatement = block;
        }