void CheckIgnoreMacros(Declaration decl, IEnumerable <MacroExpansion> expansions)
 {
     if (expansions.Any(e => MatchDeclType(decl, e) && e.Text.Contains("attribute_deprecated")))
     {
         if (decl.Attributes.All(v => v.Type != typeof(ObsoleteAttribute)))
         {
             var attribute = new Attribute
             {
                 Type = typeof(ObsoleteAttribute)
             };
             if (decl.DebugText != null)
             {
                 var commentLines       = decl.DebugText.Split('\r', '\n');
                 var deprecatedTextLine = commentLines.FirstOrDefault(l => l.Contains("@deprecated"));
                 if (deprecatedTextLine != null)
                 {
                     attribute.Value = "\"" +
                                       deprecatedTextLine.TrimStart('*', ' ').Remove(0, "@deprecated".Length).Trim() +
                                       "\"";
                 }
             }
             decl.Attributes.Add(attribute);
         }
     }
 }
        public static string AsString(this CppSharp.AST.Attribute attr, bool useFullNamespace = false)
        {
            var bldr = new StringBuilder("[");

            if (attr is TargetedAttribute ta && ta.Target != AttributeTarget.Default)
            {
                bldr.Append(ta.Target.ToString().ToLowerInvariant());
                bldr.Append(": ");
            }

            bldr.Append(useFullNamespace ? attr.Type.FullName : attr.Type.Name[0..^ 9]);
Exemple #3
0
        private static void AddObsoleteAttribute(Declaration function)
        {
            StringBuilder obsoleteMessageBuilder = new StringBuilder();

            obsoleteMessageBuilder.Append(HtmlEncoder.HtmlDecode(HtmlEncoder.HtmlEncode(function.Comment.BriefText).Split(
                                                                     Environment.NewLine.ToCharArray()).FirstOrDefault(line => line.Contains("instead") || line.Contains("deprecated"))));
            Attribute annotation = new Attribute();

            annotation.Type  = typeof(ObsoleteAttribute);
            annotation.Value = string.Format("\"{0}\"", obsoleteMessageBuilder);
            function.Attributes.Add(annotation);
        }
Exemple #4
0
        public override bool VisitFunctionDecl(Function function)
        {
            if (AlreadyVisited(function) || function.Name != "obsolete")
            {
                return(false);
            }

            var attribute = new Attribute
            {
                Type  = typeof(ObsoleteAttribute),
                Value = string.Format("\"{0} is obsolete.\"", function.Name)
            };

            function.Attributes.Add(attribute);

            return(base.VisitFunctionDecl(function));
        }
        public static string AsString(this CppSharp.AST.Attribute attr, bool useFullNamespace = false)
        {
            var bldr = new StringBuilder("[");

            if (attr is TargetedAttribute ta && ta.Target != AttributeTarget.Default)
            {
                bldr.Append(ta.Target.ToString( ).ToLowerInvariant( ));
                bldr.Append(": ");
            }

            bldr.Append(useFullNamespace ? attr.Type.FullName : attr.Type.Name.Substring(0, attr.Type.Name.Length - 9 /*Len(Attribute)*/));
            if (!string.IsNullOrWhiteSpace(attr.Value))
            {
                bldr.Append("( ");
                bldr.Append(attr.Value);
                bldr.Append(" )");
            }

            bldr.Append("]");
            return(bldr.ToString( ));
        }
Exemple #6
0
 public override bool VisitFunctionDecl(Function function)
 {
     if (!AlreadyVisited(function) && function.Name == "obsolete")
     {
         Attribute attribute = new Attribute
         {
             Type = typeof(ObsoleteAttribute),
             Value = string.Format("\"{0} is obsolete.\"", function.Name)
         };
         function.Attributes.Add(attribute);
     }
     return base.VisitFunctionDecl(function);
 }
 private static void AddObsoleteAttribute(Declaration function)
 {
     StringBuilder obsoleteMessageBuilder = new StringBuilder();
     obsoleteMessageBuilder.Append(HtmlEncoder.HtmlDecode(HtmlEncoder.HtmlEncode(function.Comment.BriefText).Split(
         Environment.NewLine.ToCharArray()).FirstOrDefault(line => line.Contains("instead") || line.Contains("deprecated"))));
     Attribute annotation = new Attribute();
     annotation.Type = typeof(ObsoleteAttribute);
     annotation.Value = string.Format("\"{0}\"", obsoleteMessageBuilder);
     function.Attributes.Add(annotation);
 }