Java printer: a class literal in an annotation value prints by simple name, without an import

クローズ
#169 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java
領域
tooling

調査の方向性

Start by tracing how javaInspector.print2 collects types for imports, then compare that path with how it prints class literals inside annotation values. Reproduce the example with Restricted, NoExternalUse, and Messages; the printed source should either retain the class literal’s qualification or include an import, and compile with javac.

索引モデルが issue の本文から書いたものです。

説明

bug

A class literal in an annotation's value prints by its simple name, and the import computer does not add an import for it, so the printed unit does not compile.

package proj.ann;
public @interface Restricted { Class<?>[] value(); }
package proj.ann.restrictions;
public class NoExternalUse { }
package proj;
import proj.ann.Restricted;

@Restricted(proj.ann.restrictions.NoExternalUse.class)
public class Messages {
    public static String hello() { return "hello"; }
}

javaInspector.print2(cu, null, javaInspector.importComputer(Integer.MAX_VALUE, cu.sourceSet())) prints

package proj;
import proj.ann.Restricted;
@Restricted(NoExternalUse.class)
public class Messages { public static String hello() { return "hello"; } }

and javac rejects it: cannot find symbol: class NoExternalUse. Either the literal keeps its qualification or its type goes to the import computer; it seems the types referenced in annotation values are not collected for imports.

Found re-parsing printed sources of jenkins core: every localizer-generated Messages class carries @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class), and so do many hand-written types. The re-parse drops each of them: 150 of the 276 dropped units in that run (two passes).

maddi 0.9.5-alpha.36.

主要言語
Java
スター
1
フォーク
1
平均マージ
1時間 44分
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CodeLaser/maddi のほかの issue

CodeLaser/maddi の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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