Skip to content

Commit

Permalink
fix brace style check for catch and finally block
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyccs committed Dec 21, 2015
1 parent 4e48bb0 commit dc697d3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ public void enterInterfaceBody(JavaParser.InterfaceBodyContext ctx) {
public void enterStatement(JavaParser.StatementContext ctx) {
braceStyleListener.enterStatement(ctx);
}

@Override
public void enterCatchClause(JavaParser.CatchClauseContext ctx) {
braceStyleListener.enterCatchClause(ctx);
}

@Override
public void enterFinallyBlock(JavaParser.FinallyBlockContext ctx) {
braceStyleListener.enterFinallyBlock(ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,30 @@ public void enterStatement(JavaParser.StatementContext ctx) {

@Override
public void enterBlock(JavaParser.BlockContext ctx) {
if (ctx.getParent() instanceof JavaParser.CatchClauseContext
|| ctx.getParent() instanceof JavaParser.FinallyBlockContext) {
return;
}

int parentLine = ctx.getParent().getParent().getStart().getLine();
int line = ctx.getStart().getLine();
detectBraceStyle(ctx, parentLine, line);
}

@Override
public void enterCatchClause(JavaParser.CatchClauseContext ctx) {
int parentLine = ctx.getStart().getLine();
int line = ctx.getRuleContext(JavaParser.BlockContext.class, 0).getStart().getLine();
detectBraceStyle(ctx, parentLine, line);
}

@Override
public void enterFinallyBlock(JavaParser.FinallyBlockContext ctx) {
int parentLine = ctx.getStart().getLine();
int line = ctx.getRuleContext(JavaParser.BlockContext.class, 0).getStart().getLine();
detectBraceStyle(ctx, parentLine, line);
}

@Override
public void enterClassBody(JavaParser.ClassBodyContext ctx) {
// TODO: this is not the best way.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,56 @@ public void braceStyle12() throws IOException, StyleCheckerException {
StyleReport report = checker.checkSourceCode(testCode, testConfig);
assertEquals(0, report.getReportContents().size());
}

@Test
@TestCode(
detail = "kRStyleTryCatchFinally",
fileName = "src/test/resources/stylechecker/BraceKRStyleTryCatchFinally.java")
@TestConfig(
detail = "krStyleConfig",
fileName = "src/test/resources/stylechecker/BraceKRStyle.json")
public void braceStyle13() throws IOException, StyleCheckerException {
StyleChecker checker = new StyleChecker();
StyleReport report = checker.checkSourceCode(testCode, testConfig);
assertEquals(0, report.getReportContents().size());
}

@Test
@TestCode(
detail = "kRStyleTryCatchFinally",
fileName = "src/test/resources/stylechecker/BraceKRStyleTryCatchFinally.java")
@TestConfig(
detail = "nonKrStyleConfig",
fileName = "src/test/resources/stylechecker/BraceNonKRStyle.json")
public void braceStyle14() throws IOException, StyleCheckerException {
StyleChecker checker = new StyleChecker();
StyleReport report = checker.checkSourceCode(testCode, testConfig);
assertEquals(5, report.getReportContents().size());
}

@Test
@TestCode(
detail = "nonKRStyleTryCatchFinally",
fileName = "src/test/resources/stylechecker/BraceNonKRStyleTryCatchFinally.java")
@TestConfig(
detail = "nonKrStyleConfig",
fileName = "src/test/resources/stylechecker/BraceNonKRStyle.json")
public void braceStyle15() throws IOException, StyleCheckerException {
StyleChecker checker = new StyleChecker();
StyleReport report = checker.checkSourceCode(testCode, testConfig);
assertEquals(0, report.getReportContents().size());
}

@Test
@TestCode(
detail = "nonKRStyleTryCatchFinally",
fileName = "src/test/resources/stylechecker/BraceNonKRStyleTryCatchFinally.java")
@TestConfig(
detail = "krStyleConfig",
fileName = "src/test/resources/stylechecker/BraceKRStyle.json")
public void braceStyle16() throws IOException, StyleCheckerException {
StyleChecker checker = new StyleChecker();
StyleReport report = checker.checkSourceCode(testCode, testConfig);
assertEquals(5, report.getReportContents().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sqatntu.stylechecker;

public class Logger {
public void camelCase() {
try {

} catch (Exception e) {

} finally {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sqatntu.stylechecker;

public class Logger
{
public void camelCase()
{
try
{

}
catch (Exception e)
{

}
finally
{

}
}
}

0 comments on commit dc697d3

Please sign in to comment.