-
Notifications
You must be signed in to change notification settings - Fork 35
Add CodeFuse queries as example #6
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// script | ||
use coref::go::* | ||
|
||
pub fn default_db() -> GoDB { | ||
return GoDB::load("coref_go_src.db") | ||
} | ||
|
||
pub fn output_(methodText: string, commentText: string, signature: string) -> bool { | ||
let (db = default_db()) { | ||
// Check if there exists a Function object 'func' | ||
for (func in Function(db)) { | ||
// Get the name of the function and assign it to the variable 'methodText' | ||
if (methodText = func.getText()) { | ||
// Get the associated comment string for the function and assign it to the variable 'commentText' | ||
if (commentText = func.getAssociatedCommentString()) { | ||
// Get the function type signature and assign it to the variable 'signature' | ||
if (signature = func.getFunctionTypeSignature()) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
output(output_()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,303 @@ | ||
// script | ||
use coref::java::* | ||
|
||
pub fn default_db() -> JavaDB { | ||
return JavaDB::load("coref_java_src.db") | ||
} | ||
|
||
//过滤用关键字,可修改 | ||
pub fn KEYWORDS(k: string) -> bool { | ||
[{"PLEASE DO NOT MODIFY THIS FILE MANUALLY"}, | ||
{"This method was generated by MyBatis Generator"}, | ||
{"Generated by the protocol buffer compiler."}, | ||
{"@mbg.generated"}, | ||
{"Autogenerated by Thrift Compiler"}, | ||
{"@author smartf-generate"}, | ||
{"Ibatis implementation for"}, | ||
{"This class was generated by MyBatis Generator"}, | ||
{"This file was automatically generated"}, | ||
{"Generated By:JavaCC: Do not edit this line."}, | ||
{"This class was generated by Ali-Generator"}, | ||
{"This field was generated by MyBatis Generator."} | ||
] | ||
} | ||
|
||
//过滤用文件夹名,可修改 | ||
pub fn FOLDERNAMES(n: string) -> bool { | ||
[ | ||
{"/daointerface/"}, | ||
{"/dataobject/"}, | ||
{"/ibatis/"}, | ||
{"/mybatis/domain/"}, | ||
{"/mybatis/mapper/"}, | ||
{"/mybatis/model/"}, | ||
{"/dal/"}, | ||
{"/dao/"}, | ||
{"/entity/"} | ||
] | ||
} | ||
|
||
//用关键字进行过滤 | ||
pub fn filterByKeyWords(f: string) -> bool { | ||
let (db = default_db()) { | ||
for (n in string::__undetermined_all__(), | ||
k in string::__undetermined_all__()) { | ||
for (i in ElementParent(db), | ||
c in JavadocComment(db)) { | ||
if (n = c.getText()) { | ||
if (KEYWORDS(k)) { | ||
if (n.contains(k)) { | ||
if (i = c.getDocumentableElement()) { | ||
if (f = c.getLocation().getFile().getRelativePath()) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//用文件夹名进行过滤 | ||
pub fn filterByFolderNames(d: File) -> bool { | ||
for (m in string::__undetermined_all__(), | ||
n in string::__undetermined_all__()) { | ||
if (n = d.getRelativePath()) { | ||
if (FOLDERNAMES(m)) { | ||
if (n.contains(m)) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//用注解 @Generated("org.mybatis.generator.api.MyBatisGenerator") 进行过滤 | ||
pub fn filterByAnnotation(f: string) -> bool { | ||
let (db = default_db()) { | ||
for (a in Annotation(db)) { | ||
if (f = a.getLocation().getFile().getRelativePath()) { | ||
if (a.getName() = "javax.annotation.Generated") { | ||
for (auto_tmp1 in a.getAnnotationArgument()) { | ||
if (auto_tmp1.getAnnotationArgumentValue() = "\"org.mybatis.generator.api.MyBatisGenerator\"") { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//过滤得到的自动生成文件名 | ||
pub fn getAutoGeneratedFiles(n: string) -> bool { | ||
let (db = default_db()) { | ||
for (f in File(db)) { | ||
if (n = f.getRelativePath()) { | ||
if (filterByFolderNames(f)) { | ||
if (filterByAnnotation(n)) { | ||
return true | ||
} | ||
if (filterByKeyWords(n)) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
schema PublicVisitedElement extends Callable { | ||
|
||
} | ||
|
||
//定义分母 | ||
impl PublicVisitedElement { | ||
|
||
@data_constraint | ||
@inline | ||
pub fn __all__(db: JavaDB) -> *PublicVisitedElement { | ||
for (tmp in Callable(db)) { | ||
yield PublicVisitedElement { | ||
id : tmp.id | ||
} | ||
} | ||
} | ||
|
||
//返回在上方的单行注释 | ||
pub fn getPossibleAboveComment(self) -> Comment { | ||
for (c in Comment(__all_data__)) { | ||
if (self.key_eq(c.getParent())) { | ||
for (auto_tmp1 in self.getModifier()) { | ||
if (auto_tmp1.getLocation().getStartLineNumber() > c.getLocation().getStartLineNumber()) { | ||
return c | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn getDefinitionBody(self) -> string { | ||
for (definitionBody in string::__undetermined_all__()) { | ||
for (m in Method(__all_data__)) { | ||
if (self.key_eq(m)) { | ||
if (definitionBody = m.getDefinitionBody()) { | ||
return definitionBody | ||
} | ||
} | ||
} | ||
for (c in Constructor(__all_data__)) { | ||
if (self.key_eq(c)) { | ||
if (definitionBody = c.getDefinitionBody()) { | ||
return definitionBody | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//找到注释与JavaDoc注释连在一起的情况,用于排除 | ||
pub fn commentConnectDocComment(c: Comment) -> bool { | ||
let (db = default_db()) { | ||
for (i in int::__undetermined_all__(), | ||
m in int::__undetermined_all__(), | ||
l in int::__undetermined_all__()) { | ||
for (j in JavadocComment(db)) { | ||
if (getJavadocCommentLocInfo(j, i, m)) { | ||
if (l = m - 1) { | ||
if (getCommentLocInfo(c, i, l)) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//找到注释所在文件和行号信息 | ||
pub fn getCommentLocInfo(e: Comment, i: int, j: int) -> bool { | ||
let (db = default_db()) { | ||
if (i = e.getLocation().getFile().element_hash_id) { | ||
if (j = e.getLocation().getStartLineNumber()) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
|
||
//找到公共访问元素的所属文件和行号信息 | ||
pub fn getPublicElementLocInfo(e: PublicVisitedElement, i: int, j: int) -> bool { | ||
let (db = default_db()) { | ||
if (i = e.getLocation().getFile().element_hash_id) { | ||
if (j = e.getLocation().getStartLineNumber()) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
|
||
//找到Javadoc注释所在文件和行号信息 | ||
pub fn getJavadocCommentLocInfo(e: JavadocComment, i: int, j: int) -> bool { | ||
let (db = default_db()) { | ||
for (n in int::__undetermined_all__()) { | ||
if (i = e.getLocation().getFile().element_hash_id) { | ||
FunJim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (n = e.getLocation().getStartLineNumber()) { | ||
if (j = n - 1) { | ||
return true | ||
} | ||
} | ||
if (n = e.getLocation().getEndLineNumber()) { | ||
if (j = n + 1) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//找到JavaDoc注释的owner为空的情况 | ||
pub fn connectDoc(j: JavadocComment, e: PublicVisitedElement) -> bool { | ||
let (db = default_db()) { | ||
for (i in int::__undetermined_all__(), | ||
m in int::__undetermined_all__()) { | ||
if (getJavadocCommentLocInfo(j, i, m)) { | ||
if (getPublicElementLocInfo(e, i, m)) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn hasComment(e: PublicVisitedElement, tmp_j: int) -> bool { | ||
let (db = default_db()) { | ||
for (j in JavadocComment(db)) { | ||
if (j.element_hash_id = tmp_j) { | ||
if (e.key_eq(j.getDocumentableElement())) { | ||
return true | ||
} | ||
if (connectDoc(j, e)) { | ||
return true | ||
} | ||
} | ||
} | ||
for (j in Comment(db)) { | ||
if (j = e.getPossibleAboveComment() && | ||
j.element_hash_id = tmp_j) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn getCommentInfo(j: int, cContext: string) -> bool { | ||
for (d in JavadocComment(__all_data__)) { | ||
if (d.element_hash_id = j) { | ||
if (cContext = d.getText()) { | ||
return true | ||
} | ||
} | ||
} | ||
for (d in Comment(__all_data__)) { | ||
if (d.element_hash_id = j) { | ||
if (cContext = d.getText()) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn output_(signature: string, methodText: string, commentText: string) -> bool { | ||
let (db = default_db()) { | ||
for (j in int::__undetermined_all__()) { | ||
for (e in PublicVisitedElement(db), | ||
i in Identifier(db), | ||
filePath in string::__undetermined_all__()) { | ||
if (signature = e.getSignature()) { | ||
if (filePath = e.getLocation().getFile().getRelativePath()) { | ||
if (!getAutoGeneratedFiles(filePath)) { | ||
if (e.key_eq(i.getParent())) { | ||
if (hasComment(e, j)) { | ||
if (getCommentInfo(j, commentText)) { | ||
if (methodText = e.getDefinitionBody()) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
output(output_()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.