protected override IAnnotatedSyntax ConvertModifiersAndAnnotations(IAnnotatedSyntax ownerNode) { var result = new AnnotatedSyntax { Annotations = (ownerNode?.Annotations).EmptyIfNull().ToList(), }; var isGlobal = false; var isPublic = false; // convert unsupported modifiers into annotations foreach (var modifier in ownerNode.Modifiers) { if (modifier == ApexKeywords.Final) { if (ownerNode is ClassDeclarationSyntax || ownerNode is MethodDeclarationSyntax) { result.Modifiers.Add("sealed"); } else if (ownerNode is FieldDeclarationSyntax) { result.Modifiers.Add("readonly"); } else { result.Annotations.Add(new AnnotationSyntax("Final")); } } else if (modifier == ApexKeywords.Global) { result.Annotations.Add(new AnnotationSyntax("Global")); isGlobal = true; } else if (modifier == ApexKeywords.Virtual && ownerNode is ClassDeclarationSyntax) { result.Annotations.Add(new AnnotationSyntax("Virtual")); } else if (modifier.StartsWith(ApexKeywords.Without)) { result.Annotations.Add(new AnnotationSyntax("WithoutSharing")); } else if (modifier.StartsWith(ApexKeywords.With)) { result.Annotations.Add(new AnnotationSyntax("WithSharing")); } else if (modifier == ApexKeywords.TestMethod) { result.Annotations.Add(new AnnotationSyntax("IsTest")); } else if (modifier == ApexKeywords.Transient) { result.Annotations.Add(new AnnotationSyntax("Transient")); } else if (modifier == ApexKeywords.WebService) { result.Annotations.Add(new AnnotationSyntax("WebService")); } else { result.Modifiers.Add(modifier); if (modifier == ApexKeywords.Public) { isPublic = true; } } } // enforce public modifier for the global symbols if (isGlobal && !isPublic) { result.Modifiers.Insert(0, ApexKeywords.Public); } return(result); }
protected virtual IAnnotatedSyntax ConvertModifiersAndAnnotations(IAnnotatedSyntax node) => node;