> For the complete documentation index, see [llms.txt](https://gitbook.youngseaz.com/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.youngseaz.com/notes/00-wang-luo-an-quan/an-quan-gong-ju/codeql/02-java-codeql-gui-ze-bian-xie.md).

# 02 Java codeql规则编写

## 官方文档

官方文档见 [CodeQL library for Java/Kotlin](https://codeql.github.com/codeql-standard-libraries/java/index.html)，文档描述了全量 codeql 使用的 Java/Kotlin API

## 规则编写

### 查询规则

基本查询语句 `select xxx`, xxx 为变量，返回 xxx

codeql 典型查询结构如下

```
from /* ... variable declarations ... */
where /* ... logical formulas ... */
select /* ... expressions ... */
```

demo 如下，首先 from 语句声明类型为 Method 的变量 m ，where 语句判断方法 m 是否被名为 GetMapping 的注解标记，select 语句返回

```
import java

from Method m
where m.getAnAnnotation().getType().hasName("GetMapping")
select m
```

常用的查询 API

| 类名   | 方法及功能 |
| ---- | ----- |
| Call | get   |

* call
  * s


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.youngseaz.com/notes/00-wang-luo-an-quan/an-quan-gong-ju/codeql/02-java-codeql-gui-ze-bian-xie.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
