Skip to content

Conversation

@Godin
Copy link
Member

@Godin Godin commented May 25, 2024

Fixes #1557

@Godin Godin force-pushed the k2_enum_entries branch from f57d802 to 24b9de9 Compare May 31, 2024 08:04
@Godin Godin marked this pull request as ready for review June 7, 2024 21:18
@Godin Godin requested a review from leveretka June 7, 2024 21:18
Copy link
Collaborator

@leveretka leveretka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, thanks for fixing it!

I just have a small suggestion to improve readability.


public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if (!"java/lang/Enum".equals(context.getSuperClassName())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the convention here, but as a code reader, I'd prefer to see a single if without negations in the conditions to reduce a cognitive load. Since the body of the if is just one line, this is an acceptable level of nesting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a strict convention about this and both styles can be found, but seems that the early-returns style is prevalent:

single if in

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if (ENUM_TYPE.equals(context.getSuperClassName())
&& CONSTRUCTOR_NAME.equals(methodNode.name)
&& CONSTRUCTOR_DESC.equals(methodNode.desc)
&& new Matcher().match(methodNode)) {
output.ignore(methodNode.instructions.getFirst(),
methodNode.instructions.getLast());
}
}

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if ((methodNode.access & Opcodes.ACC_PRIVATE) != 0
&& CONSTRUCTOR_NAME.equals(methodNode.name)
&& CONSTRUCTOR_DESC.equals(methodNode.desc) && new Matcher()
.match(methodNode, context.getSuperClassName())) {
output.ignore(methodNode.instructions.getFirst(),
methodNode.instructions.getLast());
}
}

early returns in

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if ((methodNode.access & Opcodes.ACC_BRIDGE) == 0) {
return;
}
output.ignore(methodNode.instructions.getFirst(),
methodNode.instructions.getLast());
}

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if (!KotlinGeneratedFilter.isKotlinClass(context)) {
return;
}
if (!context.getClassAnnotations().contains("Lkotlin/jvm/JvmInline;")) {
return;
}
if ((methodNode.access & Opcodes.ACC_STATIC) != 0) {
return;
}
output.ignore(methodNode.instructions.getFirst(),
methodNode.instructions.getLast());
}

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if (context.getSourceFileName() == null) {
// probably full debug information is missing
// disabled filtering as all methods might be erroneously skipped
return;
}
if (!isKotlinClass(context)) {
return;
}
if (hasLineNumber(methodNode)) {
return;
}
output.ignore(methodNode.instructions.getFirst(),
methodNode.instructions.getLast());
}

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if (!KotlinGeneratedFilter.isKotlinClass(context)) {
return;
}
new Matcher().match(methodNode, output);
}

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if ((methodNode.access & Opcodes.ACC_SYNTHETIC) == 0) {
return;
}
if (!KotlinGeneratedFilter.isKotlinClass(context)) {
return;
}
if (isDefaultArgumentsMethod(methodNode)) {
new Matcher().match(methodNode, output, false);
} else if (isDefaultArgumentsConstructor(methodNode)) {
new Matcher().match(methodNode, output, true);
}
}

new ExhaustiveSwitchFilter(), //
new RecordPatternFilter(), //
new AnnotationGeneratedFilter(), new KotlinGeneratedFilter(),
new KotlinEnumFilter(), //
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a // here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise Eclipse JDT Formatter will join lines and the change will look like

                                new AnnotationGeneratedFilter(), new KotlinGeneratedFilter(),
-                               new KotlinLateinitFilter(), new KotlinWhenFilter(),
-                               new KotlinWhenStringFilter(),
+                               new KotlinEnumFilter(), new KotlinLateinitFilter(),
+                               new KotlinWhenFilter(), new KotlinWhenStringFilter(),
                                new KotlinUnsafeCastOperatorFilter(),

@leveretka leveretka self-requested a review July 8, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Investigate why Kotlin K2 compiler produces line numbers in the enums getEntries method

2 participants