Skip to content

godelscript_language文档中给出的一个示例有误 #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Pudrick opened this issue Apr 15, 2025 · 1 comment
Closed

godelscript_language文档中给出的一个示例有误 #106

Pudrick opened this issue Apr 15, 2025 · 1 comment

Comments

@Pudrick
Copy link

Pudrick commented Apr 15, 2025

文档中给出的第一个Java示例,查询未使用方法

// script
use coref::java::*

fn default_java_db() -> JavaDB {
    return JavaDB::load("coref_java_src.db")
}

// find unused methods
fn unused_method(unused: string) -> bool {
    for(c in Callable(default_java_db()), method in Callable(default_java_db()), caller in method.getCaller()) {
        if (c != caller && unused = method.getSignature()) {
            return true
        }
    }
}

fn main() {
    output(unused_method())
}

这里的判断逻辑中methodcaller非空,得到的应该是被使用过的方法。
可以做类似这样的修正

fn unused_method(unused: string) -> bool {
    for(method in Callable(default_java_db())){
        if(0 = method.getCaller().len() && unused = method.getSignature()){
            return true
        }
    }
}

使之返回未使用方法。

@ValKmjolnir
Copy link
Collaborator

应该是文档之前没更新,example 脚本之前有修复过 example/java/UnusedMethod.gdl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants