github / github/codeql

Java: Make `Annotatable` abstract / refine `Annotation.getAnnotatedElement()`

未關閉
#8,647 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

Currently `Annotatable` is a regular CodeQL class which extends `Element`. This makes it cover a lot of entity types which are not actually annotatable, such as all expressions, statements (only some statements are annotatable) and files. This is probably not a big issue, but it prevents for example the CodeQL compiler from detecting incompatible casts.

A related issue is how `Annotation.getAnnotatedElement()` is defined (and that it currently has `Element` as result type). At the moment it erroneously has `Annotation` and `ArrayInit` as result when they contain nested annotations, e.g. `@Outer(@Innter)`, or `@Outer({@Inner(1), @Inner(2)})`.
Example query:
```codeql
import java

from Annotatable a
where not (
a instanceof FieldDeclaration
or a instanceof Member
or a instanceof Package
or a instanceof RefType
or a instanceof TypeAccess
or a instanceof Variable
)
select a, a.getPrimaryQlClasses(), a.getAnAnnotation()
```
[Query Console link](https://lgtm.com/query/6189668047736089840/)

If you give me a hint what the desired solution to this is, I can try to give it a go, unless you want to fix this yourselves of course.

貢獻指南

開啟貢獻指南

研究方向

Start with the Java library definitions of Annotatable and Annotation.getAnnotatedElement(), then run the example query from the issue to inspect the current results. Determine the intended set of annotatable element types and the correct result type for nested annotations; done means incompatible casts can be detected and nested annotations no longer produce Annotation or ArrayInit as annotated elements.

由索引模型根據 Issue 內容生成。

評估

領域
compilers
Issue 類型
重構
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
30/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。