1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 579261: Fix formatter exception when formatter comment tags aren't used

Change-Id: Ia704bfd9bd6ff0e171187b78aa6b693a1921902e
This commit is contained in:
Jonah Graham 2022-03-14 17:05:45 -04:00
parent e3f20b8a31
commit db4bc74334
2 changed files with 17 additions and 3 deletions

View file

@ -4932,15 +4932,15 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
* Collect source positions of no-format sections in the given translation unit.
*
* @param translationUnit the {@link IASTTranslationUnit}, may be <code>null</code>
* @return a {@link List} of {@link Position}s
* @return a modifiable {@link List} of {@link Position}s
*/
private List<InactivePosition> collectNoFormatCodePositions(IASTTranslationUnit translationUnit) {
if (translationUnit == null || !this.preferences.use_fomatter_comment_tag) {
return Collections.emptyList();
return new ArrayList<>();
}
String fileName = translationUnit.getFilePath();
if (fileName == null) {
return Collections.emptyList();
return new ArrayList<>();
}
List<InactivePosition> positions = new ArrayList<>();
int inactiveCodeStart = -1;

View file

@ -4803,4 +4803,18 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testLambdaWithoutParens_Bug564273() throws Exception {
assertFormatterResult();
}
//#ifdef AAA
//#define BBB
//#endif
//#ifdef AAA
//#define BBB
//#endif
public void testCodeFormatterTagsOff_Bug579261() throws Exception {
// Tests that when there is an inactive block of code that code formatter doesn't fail when
// tags are disabled
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_COMMENT_TAG, DefaultCodeFormatterConstants.FALSE);
assertFormatterResult();
}
}