Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

xiaozhenliu-gg5
Copy link
Contributor

@xiaozhenliu-gg5 xiaozhenliu-gg5 commented Aug 8, 2020

Currently the blockComment is actually special JavaDocComment with only the plain comments. We need a constructor to build file header which is in /* */ format. it's different from /** */ because if we wrap the file header into the current BlockComment, when we run the JavaFormatter against the whole class definition, the format will be messed up to below with extra <p>:

/**
 * Copyright 2020 Google LLC
 *
 * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

The escaper won't be called here, since there won't be any special characters.

String expected = "/*\n" + "* this is a test comment\n" + "*/\n";
commentStatement.accept(writerVisitor);
assertEquals(writerVisitor.write(), expected);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we please add a test for something with "bad formatting" like short lines and new lines in-between, so we can see how/whether that will be formatted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. The formatter will not reformat the short lines (verified in local), below example will just keep it is.
/*
 * this is 
 * a test comment
 */
  1. new lines in between like this is \n\n a test comment will also reserve the new lines by formatter. (which is useful because we have extra new line in the apache license)
/*
 * this is
 *
 * a test comment
 */
  1. long line is also kept as it is. unless it's surrounded by /** */. So when we construct the multi line block comment, the new line is used to be as splitter and we should be carefule about each line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good, could we please add a test that demonstrates these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, short lines/ newLineInbetween were added in the unit test, thanks!

String expected = "/*\n" + "* this is a test comment\n" + "*/\n";
commentStatement.accept(writerVisitor);
assertEquals(writerVisitor.write(), expected);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Good, could we please add a test that demonstrates these cases?

@xiaozhenliu-gg5 xiaozhenliu-gg5 merged commit e415213 into master Aug 15, 2020
@xiaozhenliu-gg5 xiaozhenliu-gg5 deleted the fix-block-comment branch September 14, 2020 22:15
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