Esempio n. 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;
        }
Esempio n. 2
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;
        }