【问题标题】:Doxygen does not generate links to methods without explicit classnameDoxygen 不会生成指向没有明确类名的方法的链接
【发布时间】:2015-07-18 15:50:03
【问题描述】:

我正在使用 Doxygen 1.8.9.1 为我的 C# 代码生成一些 html 文档。问题是 Doxygen 似乎不理解对同一类中方法的方法调用,除非您在方法名之前显式键入类名。

在这个示例类中,我有 2 个相同的静态方法和 1 个调用它们的方法;一个只包含方法名,一个包含类名。当我生成文档时,只有someStaticMethod2 链接到somecallersomeStaticMethod 没有链接到任何东西。

public class Class1 {

    static void someStaticMethod() {
    }

    static void someStaticMethod2() {
    }

    void somecaller() {
        someStaticMethod();
        Class1.someStaticMethod2();
    }

}

在我的 Doxygen 配置中,我已经勾选了我可以看到的每个“提取”选项,即

EXTRACT_ALL            = YES
EXTRACT_PRIVATE        = YES
EXTRACT_STATIC         = YES
EXTRACT_LOCAL_CLASSES  = YES
EXTRACT_LOCAL_METHODS  = YES
EXTRACT_ANON_NSPACES   = YES

我查看了相关问题,但没有答案..

有什么想法吗?
谢谢
汤姆

【问题讨论】:

    标签: c# documentation doxygen static-methods call-graph


    【解决方案1】:

    作为一种快速解决方法,我使用 python 制作了这个 Doxygen 输入过滤器。它假定您有一个.cs 源文件,其中一个包含静态方法的主类。它有点杂乱无章,因为它没有进行正确的语法解析,但它对我有用;)

    它采用.cs 输入文件,获取类名并将其添加到类中找到的任何静态函数调用之前,以将someStaticMethod 之类的调用替换为Class1.someStaticMethod

    要使用,只需将其添加到 Doxygen 配置中:
    FILTER_PATTERNS = *.cs=DocPreprocess.bat

    bat 文件只是 python 脚本的包装器,如下所示:

    @echo off
    cd %~dp0
    C:\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\python.exe DocPreprocess.py %1
    

    只需确保 bat 文件位于路径上或 Doxygen 启动文件夹中。

    DocPreprocess.py

    ​​>
    import re
    import sys
    
    original = open(sys.argv[1],"rb").read();
    
    #remove quoted sections and char literal braces
    regex = re.compile('"([^"]*)"', re.IGNORECASE)
    buffer = regex.sub("", original).replace("'{'","").replace("'}'","")
    
    #remove comments 
    newbuffer = ""
    for l in buffer.splitlines():
        code,_,comment = l.partition(r"//")
        newbuffer += code
    
    buffer = " ".join(newbuffer.split())
    
    #get static functions and main class name
    depth = 0
    classname = ""
    classdepth = 0
    funcs = []
    while True:
        nopen = buffer.find("{")
        nclose = buffer.find("}")
        
        if nclose==-1 and nopen>-1: nclose=nopen+1
        if nclose>-1 and nopen==-1: nopen=nclose+1
        if nclose==-1 and nopen==-1: break
        
        if nopen < nclose:
            chunk,_,buffer = buffer.partition("{")
            depth+=1
        else:
            chunk,_,buffer = buffer.partition("}")
            depth-=1
            
        chunk = chunk.strip()
            
        if "public class" in chunk and classname == "":
            classname = chunk.split()[-1]
            classdepth = depth
            
        if classdepth and depth > classdepth and  "static" in chunk and chunk.endswith(")"):
            funcs.append(chunk.rpartition("(")[0].split()[-1])
    
    #replace
    fixed = ""
    for l in original.splitlines():
        words = l.split()
        stripped = l.strip()
        
        if "static" in words[0:3] or stripped.startswith("//") or stripped.startswith("#"): 
            #ignore function defs and comments
            fixed += l + "\n"
            continue
            
        for f in funcs:
            newname = classname+"."+f
            l=l.replace(newname,"[[TEMPTOKEN]]")
            l=l.replace(f,newname)
            l=l.replace("[[TEMPTOKEN]]",newname)
            
        fixed += l + "\n"
        
    #output fixed file to stdout
    print fixed
    

    这只是为了得到我想要的东西,我仍然很想看到一个真正的解决方案,让 Doxygen 自动执行此操作。

    谢谢
    汤姆

    【讨论】:

      猜你喜欢
      • 2012-02-24
      • 1970-01-01
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 2021-06-01
      • 2017-05-31
      相关资源
      最近更新 更多