Skip to content

Use enhanced switch#1505

Open
nfi wants to merge 1 commit into
contiki-ng:masterfrom
nfi:code-cleanup-switch
Open

Use enhanced switch#1505
nfi wants to merge 1 commit into
contiki-ng:masterfrom
nfi:code-cleanup-switch

Conversation

@nfi
Copy link
Copy Markdown
Member

@nfi nfi commented Apr 23, 2025

Code cleanup to avoid warnings with Error Prone 2.38

canvas.setCursor(Cursor.getDefaultCursor());
break;
case SELECTING:
canvas.setCursor(Cursor.getDefaultCursor());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indentation looks strange here, at least when it's in combination with the comment.

srcAddress = UNSPECIFIED_ADDRESS;
break;
case SICSLOWPAN_IPHC_SAM_01: /* 64 bits */
srcAddress = UNSPECIFIED_ADDRESS;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment about strange indentation.

case SICSLOWPAN_IPHC_DAM_01: /* 48 bits FFXX::00XX:XXXX:XXXX */

}
case SICSLOWPAN_IPHC_DAM_01 -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you deliberately removing the comments after the colon? You removed some sizes in the switch dealing with SICSLOWPAN_IPHC_SAM_10 a page or two earlier.

If the comments are bad I think it's better to remove them, just double checking that it wasn't IntelliJ that wiped them for you.

}
break;
case TRANSMISSION_FINISHED: { // Remove radio connection.
case TRANSMISSION_FINISHED -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Guessing the removed // Remove radio connection. wasn't intentional, so the earlier removed comments are probably also mistakes then.

}
case BUFFER1_READ, BUFFER2_READ -> {
// Return bytes from the RAM buffer
buf_num = (state == BUFFER1_READ ? 1 : 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Github makes it hard to follow what happened here, but I'm guessing all lines are re-indented, and then Github decided to snap the diff view on a different place.

You might as well remove the parenthesis in the RHS here if the git blame gets trampled anyways.

logw(WarningType.EXECUTION, "ERROR: Buffer Read past buffer size: " + bufferAddress);
}
case BUFFER1_WRITE, BUFFER2_WRITE -> {
buf_num = (state == BUFFER1_WRITE ? 1 : 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same removing parenthesis comment here.

log("RSSI is not valid");
int RSSITIME = 380;
cpu.scheduleTimeEventMillis(rssiValid, RSSITIME / 1000.0);
// setState(CC1101RadioState.CC1101_STATE_RX);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can remove a bunch of the leading spaces in the comment here.

}
case CC1101_SWORRST -> log("CC1101_SWORRST not implemented");
case CC1101_SNOP -> {
// log("CC1101_SNOP not implemented");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same about removing most of the leading spaces in this comment, and same for the one on line 302.

//break;
case READ_RXFIFO: {
}
//break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can remove this line with the new switch.

break;
}
}
// status |= STATUS_RSSI_VALID;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can remove some of the leading spaces in the comment here too.

updateGPIOConfig();
}
}
// case REG_IOCFG1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the comment should be updated with the -> { and ending } instead of break, so it's ready if someone uncomments it in the future.

yield 0;
}
case RTCPS -> {
logNotImplemented("prescaling coutner");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you're changing the line: coutner -> counter

i = (index - TCCR0) / 2;
if (i >= noCompare) {
case TCCR0, TCCR1, TCCR2, TCCR3, TCCR4, TCCR5, TCCR6 -> {
int i;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can declare this on the next line when defining it.

Copy link
Copy Markdown
Contributor

@pjonsson pjonsson left a comment

Choose a reason for hiding this comment

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

Nothing stood out when reading this, but it was long with lots of changes. I assume you used IntelliJ or some other automatic tool to convert the switch-statements, so things should behave the same way as before the change.

I think the mentioned whitespace/comment stuff might be worth adjusting before merging, but go ahead and merge this after that.

@nfi
Copy link
Copy Markdown
Member Author

nfi commented May 2, 2025

Thanks for the feedback. Yes, I used IntelliJ to convert most of the switch statements (it failed on a few for some reason), but I need to take a closer look at the changes as I missed that some comments have been removed during the conversion. Unfortunately, there were a lot more code changes than I expected when I started to address the Error Prone issues, so an alternative could be to simply disable the relevant checks in Error Prone for now.

@pjonsson
Copy link
Copy Markdown
Contributor

pjonsson commented May 2, 2025

Unfortunately, there were a lot more code changes than I expected when I started to address the Error Prone issues, so an alternative could be to simply disable the relevant checks in Error Prone for now.

Yeah, when I was working more actively on Cooja I didn't do the large enhanced switch changes for this reason. It's possible I missed some simple ones, but most of them triggered quite big diffs.

Long-term, I think enhanced switches are the way forward, but I'm fine with disabling the check now as you suggest and then re-enabling it when we have migrated at our own pace.

@nfi
Copy link
Copy Markdown
Member Author

nfi commented Jul 1, 2025

I made a PR #1515 that disables the check in ErrorProne for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants