diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index be84be0c059..7eee8ee0cf5 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -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 null - * @return a {@link List} of {@link Position}s + * @return a modifiable {@link List} of {@link Position}s */ private List 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 positions = new ArrayList<>(); int inactiveCodeStart = -1; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 57fe21a33df..d5a7504ae16 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -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(); + } }