Skip to content

Commit

Permalink
WIP: ignoring compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Sep 17, 2022
1 parent c67b98b commit 2bc0460
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public final class ErrorProneTestHelperSourceFormat extends BugChecker
private static final long serialVersionUID = 1L;
private static final String FLAG_AVOID_TEXT_BLOCKS =
"ErrorProneTestHelperSourceFormat:AvoidTextBlocks";
private static final String FLAG_IGNORE_MALFORMED_CODE =
"ErrorProneTestHelperSourceFormat:IgnoreMalformedCode";
private static final Formatter FORMATTER = new Formatter();
private static final Matcher<ExpressionTree> INPUT_SOURCE_ACCEPTING_METHOD =
anyOf(
Expand All @@ -82,6 +84,7 @@ public final class ErrorProneTestHelperSourceFormat extends BugChecker
private static final String DEFAULT_TEXT_BLOCK_INDENTATION = " ".repeat(12);

private final boolean avoidTextBlocks;
private final boolean ignoreMalformedCode;

/** Instantiates the default {@link ErrorProneTestHelperSourceFormat}. */
public ErrorProneTestHelperSourceFormat() {
Expand All @@ -95,6 +98,7 @@ public ErrorProneTestHelperSourceFormat() {
*/
public ErrorProneTestHelperSourceFormat(ErrorProneFlags flags) {
avoidTextBlocks = flags.getBoolean(FLAG_AVOID_TEXT_BLOCKS).orElse(Boolean.FALSE);
ignoreMalformedCode = flags.getBoolean(FLAG_IGNORE_MALFORMED_CODE).orElse(Boolean.FALSE);
}

@Override
Expand Down Expand Up @@ -128,9 +132,11 @@ private Description flagFormattingIssues(
String gjfResult = formatSourceCode(source, retainUnusedImports);
formatted = canUseTextBlocks(state) ? gjfResult : gjfResult.stripTrailing();
} catch (FormatterException e) {
return buildDescription(methodInvocation)
.setMessage(String.format("Source code is malformed: %s", e.getMessage()))
.build();
return ignoreMalformedCode
? Description.NO_MATCH
: buildDescription(methodInvocation)
.setMessage(String.format("Source code is malformed: %s", e.getMessage()))
.build();
}

boolean isFormatted = source.equals(formatted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.condition.JRE;

final class ErrorProneTestHelperSourceFormatTest {
// XXX: Add tests cases for `ErrorProneTestHelperSourceFormat:IgnoreMalformedCode`.
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass());
private final CompilationTestHelper avoidTextBlocksCompilationTestHelper =
Expand Down

0 comments on commit 2bc0460

Please sign in to comment.