Doxygen 不会生成指向没有显式类名的方法的链接

Doxygen does not generate links to methods without explicit classname

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

在这个例子中 class 我有 2 个相同的静态方法和 1 个同时调用它们的方法;一个只包含方法名称,一个包含 class 名称。当我生成文档时,只有 someStaticMethod2 被 link 编辑为 somecallersomeStaticMethod 没有 link 任何东西。

public class Class1 {

    static void someStaticMethod() {
    }

    static void someStaticMethod2() {
    }

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

}

在我的 Doxygen 配置中,我勾选了我能看到的每个 "extract" 选项,即

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

我看过相关问题,但他们没有答案..

有什么想法吗?
谢谢
汤姆

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

它获取 .cs 输入文件,获取 class 名称并将其添加到 class 中找到的任何静态函数调用,以替换 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 自动执行此操作的真正解决方案。

谢谢
汤姆