From ef1a5f0b59e4f83e9427d93eb0b93c025636366b Mon Sep 17 00:00:00 2001 From: Albert Shi Date: Tue, 2 May 2023 17:26:27 -0400 Subject: [PATCH] Fix incorrectly detected INDENTATION atoms https://github.com/SERG-Delft/atoms-of-confusion-detector/issues/54 --- src/main/kotlin/github/GithubUtil.kt | 2 +- src/main/kotlin/input/Cli.kt | 1 - src/main/kotlin/parsing/detectors/IndentationDetector.kt | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/github/GithubUtil.kt b/src/main/kotlin/github/GithubUtil.kt index dfc3e2e..5928a8b 100644 --- a/src/main/kotlin/github/GithubUtil.kt +++ b/src/main/kotlin/github/GithubUtil.kt @@ -6,11 +6,11 @@ import github.exceptions.InvalidPrUrlException import github.exceptions.NonexistentPRException import github.exceptions.UsageLimitException import input.Settings +import java.net.URI import org.antlr.v4.runtime.CharStreams import org.json.simple.JSONObject import org.json.simple.parser.JSONParser import parsing.ParsedFile -import java.net.URI // for now its like this until a proper error handling system is in place @SuppressWarnings("RethrowCaughtException", "ThrowsCount", "MagicNumber") diff --git a/src/main/kotlin/input/Cli.kt b/src/main/kotlin/input/Cli.kt index 41254ae..59a2a7a 100644 --- a/src/main/kotlin/input/Cli.kt +++ b/src/main/kotlin/input/Cli.kt @@ -251,7 +251,6 @@ class PRCommand : AtomsCommand("Analyze the provided github pull request for ato // get the filenames of the .java files that were modified in the pr val fromFiles = parsedDiff.fromFileNames.filter { it.endsWith(".java") } val toFiles = parsedDiff.toFileNames.filter { it.endsWith(".java") } - val fromGraph = runDetector(fromFiles, pr.fromCommit, resultsDir, "from") val toGraph = runDetector(toFiles, pr.toCommit, resultsDir, "to") diff --git a/src/main/kotlin/parsing/detectors/IndentationDetector.kt b/src/main/kotlin/parsing/detectors/IndentationDetector.kt index eac4b0d..f1bd3cb 100644 --- a/src/main/kotlin/parsing/detectors/IndentationDetector.kt +++ b/src/main/kotlin/parsing/detectors/IndentationDetector.kt @@ -10,7 +10,10 @@ class IndentationDetector(listener: AtomsListener, graph: ConfusionGraph) : Dete override fun detect(ctx: JavaParser.StatIfElseContext) { checkNextSiblingHasSameIndentation(ctx) - val startingIndentOfIf = ctx.IF().symbol.charPositionInLine + var startingIndentOfIf = ctx.IF().symbol.charPositionInLine + if (ctx.parent is JavaParser.StatIfElseContext) { + startingIndentOfIf = (ctx.parent as JavaParser.StatIfElseContext).ifBody.stop.charPositionInLine + } if (ctx.ifBody is JavaParser.StatBlockContext) { val closingBracket = (ctx.ifBody as JavaParser.StatBlockContext).block().RBRACE().symbol val indentOfClosingBracket =