Kotlin printer: apply for construct-then-configure sequences (#140 follow-up)

オープン
#165 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, kotlin
領域
compilers, tooling

調査の方向性

Start by reading the Kotlin printer and its CST name-resolution checks, then inspect how it represents construction, configuring calls, and the local’s final use. Implementing this rewrite requires preserving Kotlin name binding and the stated single-use cases. Measure apply counts and line counts on langchain4j and jenkins, and confirm compile counts stay unchanged across the five corpora.

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

説明

Follow-up of #140 (idiom scorecard: apply 0 in langchain4j's output).

Today. The Kotlin printer never emits apply. also appears only as the mechanical .also { x = it } for Java's assignment as a value.

Shape (Java → Kotlin):

Config c = new Config();
c.setName(name);
c.setTimeout(30);
return c;
return Config().apply {
    setName(name)        // or name = name, once getX()/setX() print as properties
    setTimeout(30)
}

The same holds where the last statement is an assignment this.config = c, or c is passed on once.

What decides it (corrected 2026-10-23, see the evaluation below):

  • Every statement between construction and the last use calls a method on the new object, with arguments that do not mention it.
  • The new object does not escape before the last configuring call; that is the modification and independence analyses' job. Wrong: T().apply { a(); b() } runs the same calls in the same order as the Java statements, so escape changes nothing. The analyses do not decide this rewrite.
  • Name resolution, which the printer checks with the CST it already has:
    • Inside the block, unqualified names resolve to T's members first. An argument size() or name that meant the enclosing class's would silently rebind.
    • An outer this must become this@Outer.
  • The local is not used afterwards except for the single return / assignment / argument the apply replaces, or it stays a val x = T().apply { … }.

Not: with/run. They are taste, and a reviewer won't miss them.

Measure. apply count and line count on langchain4j and jenkins; compile counts unchanged across the five corpora.

🤖 Generated with Claude Code

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

環境構築

はじめの一歩

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

CodeLaser/maddi のほかの issue

CodeLaser/maddi の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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