Java → C# translation: an idiomatic C# printer driven by the modification and nullability analyses
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/100
Hướng nghiên cứu
Start by reading the Kotlin printer, maddi-cst-print-kotlin, and its JavaToKotlinRatchet, KotlinPrintMessage and NullabilityVerdicts seam, since the issue says the C# printer mirrors them. The first step is the new maddi-cst-print-csharp module with its TypePrinter/MethodPrinter/FieldPrinter implementations and a csharp-printing.md design doc. The issue does not define a finished state beyond the six-step plan, so a newcomer should not start here.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Goal
Translate Java to idiomatic C#, automatically: parse with the openjdk front end, print the CST as C# with a new maddi-cst-print-csharp module, and judge the result with the C# compiler. This is the C# counterpart of the Java → Kotlin translation (maddi-cst-print-kotlin, JavaToKotlinRatchet).
This is the printer direction. #111 covers the opposite direction (a Roslyn front end reading C#) and lists a C# printer as out of scope. Nothing here depends on #111's plan: the struct spike, the Predefined refactor and the exporter are front-end work. A Java-parsed CST is JVM-shaped, and the printer starts from that.
What drives it: the analyses
What sets this apart from a syntax converter is that maddi's analyses decide the output:
- Nullability (
NullabilityPassin maddi-mod) decides where?goes on reference types under#nullable enable, and where!,?.or??appear. TheNullabilityVerdictsseam thatmaddi-cst-print-kotlinuses carries over directly. - Modification and immutability decide whether something can be
readonly,init-only orIReadOnlyList<T>/IReadOnlyDictionary<K,V>, whether a class can become arecord, and whether a value type (readonly struct) is safe. Where the analysis proves code doesn't modify something, the C# says so. - Prepwork (
getSetField) collapses getters and setters into C# properties, as it does for Kotlin.
Without verdicts the printer still produces valid C#, just less precise: every reference is nullable-oblivious and every collection mutable.
Automation
The translation has to run without manual editing. It is measured the way J2K is: a ratchet per corpus (fernflower first) that translates the main sources, compiles them with dotnet build / Roslyn, and records syntax errors, semantic errors, compiling files and eventually passing tests. A metric that gets worse fails, and one that gets better must be written into the ratchet file. A shape the printer can't translate gets a named message (as KotlinPrintMessage does), never silently wrong output.
Harder than Kotlin
- No JVM interop. Kotlin can call the JDK and the corpus's original classes; C# can't. JDK references need a BCL mapping or a small runtime shim (
java.util.*,Stringmembers, streams → LINQ, exceptions, boxing). This mapping is the bulk of the work. It also means there is no "compile against the original classes" stage: the whole corpus has to translate first. - Semantic gaps:
- checked exceptions are dropped;
- wildcards (
? extends/? super) on reified generics; - non-static inner classes need an explicit outer reference;
- anonymous classes become nested classes, or lambdas/delegates for functional interfaces;
- enums with fields or bodies become classes;
- Java methods are virtual by default, so C# needs
virtual/override/sealed; >>>, integer andcharconversions, stringswitch, labelledbreak/continue(→goto).
Plan
maddi-cst-print-csharp: printers on the cst-apiTypePrinter/MethodPrinter/FieldPrinterinterfaces, reusingOutputElementandFormatter2; aCommonJavaToCSharptest base; acsharp-printing.mddesign document.- Syntax coverage of every statement and expression form, plus a
JavaToCSharpRatcheton fernflower counting syntax errors. - Structure and the JDK → BCL mapping: semantic errors, then compiling files.
- Nullability verdicts →
#nullable enableoutput, with a ratchet in maddi-mod (likeTestJavaToKotlinFernflowerNullability). - Modification/immutability verdicts →
readonly, read-only collection interfaces, records. - The corpus's tests, translated, passing.
- Ngôn ngữ chính
- Java
- Star
- 1
- Fork
- 1
- Merge trung bình
- 1 giờ 34 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của CodeLaser/maddi
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
CodeLaser/maddi#166 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
build/ci good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Java printer: a class literal in an annotation value prints by simple name, without an importĐang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Java printer: a static interface method called from an implementing class prints unqualifiedĐang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của CodeLaser/maddi
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
AllTheMods/AllTheModium#238 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/stormcrawler#2264 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
commons-app/apps-android-commons#7115 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
objectionary/lints#1596 ·
Maintainer thường phản hồi trong vòng 2 ngày