Skip to content

fixing formatter issues #8484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

naren2605
Copy link
Contributor

@naren2605 naren2605 commented May 5, 2025

providing fix for issue

  • root cause:
    • a pair {} of braces are injected at the erroneous then part in IfTree
    • improper end position of erroneous block as sp.getStartPosition and sp.getEndPosition always returns begining index for erroneous then statement
    • due to above issues new braces were injected, new lines and indentation has issues which was causing more problems in user experience while formatting long files

@naren2605
Copy link
Contributor Author

requesting @jlahoda , @mbien @dbalek to take a look

@mbien mbien added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label May 5, 2025
@mbien mbien linked an issue May 5, 2025 that may be closed by this pull request
Comment on lines 2568 to 2572
Boolean hasErrThenStatement = Optional.ofNullable(node.getThenStatement())
.filter(it-> it instanceof ExpressionStatementTree)
.map(it -> ((ExpressionStatementTree)it).getExpression())
.map(it-> (it instanceof ErroneousTree))
.orElse(false);
Copy link
Member

Choose a reason for hiding this comment

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

            boolean hasErrThenStatement = node.getThenStatement() instanceof ExpressionStatementTree tree
                                       && tree.getExpression() instanceof ErroneousTree;

easier to read and probably less overhead too

Comment on lines 2575 to 2579
var isPreviousIfTree = false;
var endPositionOfErrThenStatement = endPos;
for (var statment : parentStTree.getStatements()) {
if (isPreviousIfTree) {
var startPositionOfNextErrorStatement = (int) sp.getStartPosition(getCurrentPath().getCompilationUnit(), statment);
Copy link
Member

Choose a reason for hiding this comment

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

lets not use var here. int has 3 chars too - no need for extra obfuscation just to make the IDE draw the type as inline hint wasting space ;)

Makes it also easier to review without checking this out in NetBeans.

var is more interesting for collections with complex generics signatures etc.

Copy link
Member

Choose a reason for hiding this comment

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

+1 Also statment -> statement.

@naren2605 naren2605 requested review from mbien and neilcsmith-net May 5, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting alters content
3 participants