Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58d7bc0

Browse files
authored
Merge pull request #6 from codefuse-ai/add-codefuse-queries
2 parents e66830f + 3c48cd0 commit 58d7bc0

11 files changed

+1069
-8
lines changed

‎example/CodeFuse/CommentCodePairsGo.gdl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// script
2+
use coref::go::*
3+
4+
pub fn default_db() -> GoDB {
5+
return GoDB::load("coref_go_src.db")
6+
}
7+
8+
pub fn output_(methodText: string, commentText: string, signature: string) -> bool {
9+
let (db = default_db()) {
10+
// Check if there exists a Function object 'func'
11+
for (func in Function(db)) {
12+
// Get the name of the function and assign it to the variable 'methodText'
13+
if (methodText = func.getText()) {
14+
// Get the associated comment string for the function and assign it to the variable 'commentText'
15+
if (commentText = func.getAssociatedCommentString()) {
16+
// Get the function type signature and assign it to the variable 'signature'
17+
if (signature = func.getFunctionTypeSignature()) {
18+
return true
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}
25+
26+
fn main() {
27+
output(output_())
28+
}
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
// script
2+
use coref::java::*
3+
4+
pub fn default_db() -> JavaDB {
5+
return JavaDB::load("coref_java_src.db")
6+
}
7+
8+
//过滤用关键字,可修改
9+
pub fn KEYWORDS(k: string) -> bool {
10+
[{"PLEASE DO NOT MODIFY THIS FILE MANUALLY"},
11+
{"This method was generated by MyBatis Generator"},
12+
{"Generated by the protocol buffer compiler."},
13+
{"@mbg.generated"},
14+
{"Autogenerated by Thrift Compiler"},
15+
{"@author smartf-generate"},
16+
{"Ibatis implementation for"},
17+
{"This class was generated by MyBatis Generator"},
18+
{"This file was automatically generated"},
19+
{"Generated By:JavaCC: Do not edit this line."},
20+
{"This class was generated by Ali-Generator"},
21+
{"This field was generated by MyBatis Generator."}
22+
]
23+
}
24+
25+
//过滤用文件夹名,可修改
26+
pub fn FOLDERNAMES(n: string) -> bool {
27+
[
28+
{"/daointerface/"},
29+
{"/dataobject/"},
30+
{"/ibatis/"},
31+
{"/mybatis/domain/"},
32+
{"/mybatis/mapper/"},
33+
{"/mybatis/model/"},
34+
{"/dal/"},
35+
{"/dao/"},
36+
{"/entity/"}
37+
]
38+
}
39+
40+
//用关键字进行过滤
41+
pub fn filterByKeyWords(f: string) -> bool {
42+
let (db = default_db()) {
43+
for (n in string::__undetermined_all__(),
44+
k in string::__undetermined_all__()) {
45+
for (i in ElementParent(db),
46+
c in JavadocComment(db)) {
47+
if (n = c.getText()) {
48+
if (KEYWORDS(k)) {
49+
if (n.contains(k)) {
50+
if (i = c.getDocumentableElement()) {
51+
if (f = c.getLocation().getFile().getRelativePath()) {
52+
return true
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
//用文件夹名进行过滤
64+
pub fn filterByFolderNames(d: File) -> bool {
65+
for (m in string::__undetermined_all__(),
66+
n in string::__undetermined_all__()) {
67+
if (n = d.getRelativePath()) {
68+
if (FOLDERNAMES(m)) {
69+
if (n.contains(m)) {
70+
return true
71+
}
72+
}
73+
}
74+
}
75+
}
76+
77+
//用注解 @Generated("org.mybatis.generator.api.MyBatisGenerator") 进行过滤
78+
pub fn filterByAnnotation(f: string) -> bool {
79+
let (db = default_db()) {
80+
for (a in Annotation(db)) {
81+
if (f = a.getLocation().getFile().getRelativePath()) {
82+
if (a.getName() = "javax.annotation.Generated") {
83+
for (auto_tmp1 in a.getAnnotationArgument()) {
84+
if (auto_tmp1.getAnnotationArgumentValue() = "\"org.mybatis.generator.api.MyBatisGenerator\"") {
85+
return true
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
94+
//过滤得到的自动生成文件名
95+
pub fn getAutoGeneratedFiles(n: string) -> bool {
96+
let (db = default_db()) {
97+
for (f in File(db)) {
98+
if (n = f.getRelativePath()) {
99+
if (filterByFolderNames(f)) {
100+
if (filterByAnnotation(n)) {
101+
return true
102+
}
103+
if (filterByKeyWords(n)) {
104+
return true
105+
}
106+
}
107+
}
108+
}
109+
}
110+
}
111+
112+
schema PublicVisitedElement extends Callable {
113+
114+
}
115+
116+
//定义分母
117+
impl PublicVisitedElement {
118+
119+
@data_constraint
120+
@inline
121+
pub fn __all__(db: JavaDB) -> *PublicVisitedElement {
122+
for (tmp in Callable(db)) {
123+
yield PublicVisitedElement {
124+
id: tmp.id
125+
}
126+
}
127+
}
128+
129+
//返回在上方的单行注释
130+
pub fn getPossibleAboveComment(self) -> Comment {
131+
for (c in Comment(__all_data__)) {
132+
if (self.key_eq(c.getParent())) {
133+
for (auto_tmp1 in self.getModifier()) {
134+
if (auto_tmp1.getLocation().getStartLineNumber() > c.getLocation().getStartLineNumber()) {
135+
return c
136+
}
137+
}
138+
}
139+
}
140+
}
141+
142+
pub fn getDefinitionBody(self) -> string {
143+
for (definitionBody in string::__undetermined_all__()) {
144+
for (m in Method(__all_data__)) {
145+
if (self.key_eq(m)) {
146+
if (definitionBody = m.getDefinitionBody()) {
147+
return definitionBody
148+
}
149+
}
150+
}
151+
for (c in Constructor(__all_data__)) {
152+
if (self.key_eq(c)) {
153+
if (definitionBody = c.getDefinitionBody()) {
154+
return definitionBody
155+
}
156+
}
157+
}
158+
}
159+
}
160+
}
161+
162+
//找到注释与JavaDoc注释连在一起的情况,用于排除
163+
pub fn commentConnectDocComment(c: Comment) -> bool {
164+
let (db = default_db()) {
165+
for (i in int::__undetermined_all__(),
166+
m in int::__undetermined_all__(),
167+
l in int::__undetermined_all__()) {
168+
for (j in JavadocComment(db)) {
169+
if (getJavadocCommentLocInfo(j, i, m)) {
170+
if (l = m - 1) {
171+
if (getCommentLocInfo(c, i, l)) {
172+
return true
173+
}
174+
}
175+
}
176+
}
177+
}
178+
}
179+
}
180+
181+
//找到注释所在文件和行号信息
182+
pub fn getCommentLocInfo(e: Comment, i: int, j: int) -> bool {
183+
let (db = default_db()) {
184+
if (i = e.getLocation().getFile().element_hash_id) {
185+
if (j = e.getLocation().getStartLineNumber()) {
186+
return true
187+
}
188+
}
189+
}
190+
}
191+
192+
//找到公共访问元素的所属文件和行号信息
193+
pub fn getPublicElementLocInfo(e: PublicVisitedElement, i: int, j: int) -> bool {
194+
let (db = default_db()) {
195+
if (i = e.getLocation().getFile().element_hash_id) {
196+
if (j = e.getLocation().getStartLineNumber()) {
197+
return true
198+
}
199+
}
200+
}
201+
}
202+
203+
//找到Javadoc注释所在文件和行号信息
204+
pub fn getJavadocCommentLocInfo(e: JavadocComment, i: int, j: int) -> bool {
205+
let (db = default_db()) {
206+
for (n in int::__undetermined_all__()) {
207+
if (i = e.getLocation().getFile().element_hash_id) {
208+
if (n = e.getLocation().getStartLineNumber()) {
209+
if (j = n - 1) {
210+
return true
211+
}
212+
}
213+
if (n = e.getLocation().getEndLineNumber()) {
214+
if (j = n + 1) {
215+
return true
216+
}
217+
}
218+
}
219+
}
220+
}
221+
}
222+
223+
//找到JavaDoc注释的owner为空的情况
224+
pub fn connectDoc(j: JavadocComment, e: PublicVisitedElement) -> bool {
225+
let (db = default_db()) {
226+
for (i in int::__undetermined_all__(),
227+
m in int::__undetermined_all__()) {
228+
if (getJavadocCommentLocInfo(j, i, m)) {
229+
if (getPublicElementLocInfo(e, i, m)) {
230+
return true
231+
}
232+
}
233+
}
234+
}
235+
}
236+
237+
pub fn hasComment(e: PublicVisitedElement, tmp_j: int) -> bool {
238+
let (db = default_db()) {
239+
for (j in JavadocComment(db)) {
240+
if (j.element_hash_id = tmp_j) {
241+
if (e.key_eq(j.getDocumentableElement())) {
242+
return true
243+
}
244+
if (connectDoc(j, e)) {
245+
return true
246+
}
247+
}
248+
}
249+
for (j in Comment(db)) {
250+
if (j = e.getPossibleAboveComment() &&
251+
j.element_hash_id = tmp_j) {
252+
return true
253+
}
254+
}
255+
}
256+
}
257+
258+
pub fn getCommentInfo(j: int, cContext: string) -> bool {
259+
for (d in JavadocComment(__all_data__)) {
260+
if (d.element_hash_id = j) {
261+
if (cContext = d.getText()) {
262+
return true
263+
}
264+
}
265+
}
266+
for (d in Comment(__all_data__)) {
267+
if (d.element_hash_id = j) {
268+
if (cContext = d.getText()) {
269+
return true
270+
}
271+
}
272+
}
273+
}
274+
275+
pub fn output_(signature: string, methodText: string, commentText: string) -> bool {
276+
let (db = default_db()) {
277+
for (j in int::__undetermined_all__()) {
278+
for (e in PublicVisitedElement(db),
279+
i in Identifier(db),
280+
filePath in string::__undetermined_all__()) {
281+
if (signature = e.getSignature()) {
282+
if (filePath = e.getLocation().getFile().getRelativePath()) {
283+
if (!getAutoGeneratedFiles(filePath)) {
284+
if (e.key_eq(i.getParent())) {
285+
if (hasComment(e, j)) {
286+
if (getCommentInfo(j, commentText)) {
287+
if (methodText = e.getDefinitionBody()) {
288+
return true
289+
}
290+
}
291+
}
292+
}
293+
}
294+
}
295+
}
296+
}
297+
}
298+
}
299+
}
300+
301+
fn main() {
302+
output(output_())
303+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /