github / github/codeql

Java: Add TypeAccess predicate for finding out if access is fully qualified

オープン
#3,649 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
Java question
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

**Description of the issue**
Would it be possible to add a predicate to `TypeAccess` or create a subclass1, e.g. `ClassOrInterfaceTypeAccess`, with a predicate which allows detecting if the type access is fully qualified, e.g. `List list = new java.util.ArrayList<>();`?

The main use case would be to detect cases where there is no need to fully qualify a type, either because the simple name is already available or because an import could be added.

Though maybe the use case for such a predicate would be too specific and does not justify this?

Note that it is currently possible to find this out in an error-prone way by checking if the length in the source (as reported by `getLocation`) matches the expected simple name length. See a not very well working example implementation [here](https://github.com/Marcono1234/codeql-java-queries/blob/master/not-working/fully-qualified-name-instead-of-simple-name.ql).

----
1: Separate class is probably needed because `TypeAccess` also covers primitives and they are always fully qualified according to [JLS](https://docs.oracle.com/javase/specs/jls/se14/html/jls-6.html#jls-6.7) so adding the predicate to `TypeAccess` would not be that useful because you would always have to check that the type is not a primitive when using that predicate.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。