Java printer: in a local class, a line comment before a field swallows the field
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
Research direction
Start from the round trip described in the issue: parse a local class with a line comment before a field, then run JavaInspector.print2 with Formatter2Impl. Find where the printer emits the comment and the following field for class bodies, and check why local classes take a different path from member classes, which print correctly. Done when the local-class example prints the comment on its own line and the field stays intact and compilable, and the member-class output is unchanged.
Written by the indexing model from the issue text.
Description
Problem
In a local class (a class declared inside a method body), a line comment before a field is printed on the same line as the field. The field becomes part of the comment, and the class no longer compiles: every use of the field fails with "cannot find symbol".
int local(List<int[]> in) {
class Entry {
public final int a;
// TODO: a comment before a field
public final List<int[]> b;
Entry(int a, List<int[]> b) { this.a = a; this.b = new ArrayList<>(b); }
}
return new Entry(1, in).a;
}
prints as
class Entry {
final int a;
// TODO: a comment before a field final List<int []> b;
Entry(int a, List<int []> b) { this.a = a; this.b = new ArrayList<>(b); }
}
The same class declared as a nested (member) class prints correctly, with the comment on its own line.
Expected
A line comment always ends its line, wherever it is.
Seen on
A round trip (parse, then JavaInspector.print2 with Formatter2Impl) on maddi 0.9.5-alpha.5. On real code: fernflower's FinallyProcessor, whose local class BlockStackEntry has // TODO: correct handling (merging) of multiple paths before the field lstStoreVars. Possibly related to #49 (comment positions), but there's no moved code here.
- Dominant language
- Java
- Stars
- 1
- Forks
- 1
- Avg merge
- 2h 51m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CodeLaser/maddi
-
build/ci good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Java → C# translation: an idiomatic C# printer driven by the modification and nullability analysesOpenenhancement extension front-end:csharp
Difficulty 5/5 Over a week Newbie friendliness 8/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 40/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
objectionary/eo-graphs#80 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
enhancement good first issue
Difficulty 2/5 Half a day Newbie friendliness 66/100
apache/fineract-consumer-facing#175 ·
Maintainers usually reply within 1 day
-
[BUG] 订单:会员凭订单号即可取消其他会员的待付款订单(取消接口不校验订单归属)Possibly taken @dadiyang claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
macrozheng/mall#1016 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100