From b68fe24d47e7754d22c67da85b5434d575c72163 Mon Sep 17 00:00:00 2001 From: Kui LIU Date: Mon, 31 Jul 2017 23:16:20 +0200 Subject: [PATCH] Remove multipleStatements modification. --- .../SingleStatementParser.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/lu/uni/serval/FixPatternParser/SingleStatementParser.java b/src/main/java/edu/lu/uni/serval/FixPatternParser/SingleStatementParser.java index 0f56a44..25824b8 100644 --- a/src/main/java/edu/lu/uni/serval/FixPatternParser/SingleStatementParser.java +++ b/src/main/java/edu/lu/uni/serval/FixPatternParser/SingleStatementParser.java @@ -15,6 +15,7 @@ import com.github.gumtreediff.actions.model.Move; import com.github.gumtreediff.actions.model.Update; import com.github.gumtreediff.tree.ITree; +import edu.lu.uni.serval.FixPattern.utils.Checker; import edu.lu.uni.serval.config.Configuration; import edu.lu.uni.serval.diffentry.DiffEntryHunk; import edu.lu.uni.serval.diffentry.DiffEntryReader; @@ -83,10 +84,7 @@ public class SingleStatementParser { startPosition2 = newNode.getPos(); endPosition2 = startPosition2 + newNode.getLength(); - if ("EnhancedForStatement".equals(astNodeType) || "ForStatement".equals(astNodeType) - || "DoStatement".equals(astNodeType) || "WhileStatement".equals(astNodeType) - || "LabeledStatement".equals(astNodeType) || "SynchronizedStatement".equals(astNodeType) - || "IfStatement".equals(astNodeType) || "TryStatement".equals(astNodeType)) { + if (Checker.containsBodyBlock(astNodeType)) { List children = update.getNode().getChildren(); endPosition = getEndPosition(children); List newChildren = newNode.getChildren(); @@ -118,6 +116,7 @@ public class SingleStatementParser { int endLine = prevUnit.getLineNumber(endPosition); int startLine2 = revUnit.getLineNumber(startPosition2); int endLine2 = revUnit.getLineNumber(endPosition2); + if (endLine - startLine >= Configuration.HUNK_SIZE - 2 || endLine2 - startLine2 >= Configuration.HUNK_SIZE - 2 ) continue; //Filter out the modify actions, which are not in the DiffEntry hunks. DiffEntryHunk hunk = matchHunk(startLine, endLine, startLine2, endLine2, actionStr, diffentryHunks); if (hunk == null) { @@ -146,6 +145,12 @@ public class SingleStatementParser { System.out.println(actionSet); continue; } + + // Source Code of patches. + String patchSourceCode = getPatchSourceCode(hunk, startLine, endLine, startLine2, endLine2); + if ("".equals(patchSourceCode)) continue; + + this.patchesSourceCode += Configuration.PATCH_TOKEN +"\n" + revFile.getName() + "\n" + patchSourceCode + "\n"; this.sizes += size + "\n"; this.astEditScripts += astEditScripts + "\n"; // 2. source code: raw tokens @@ -155,15 +160,10 @@ public class SingleStatementParser { // 4. semi-source code: String semiSourceCodeEditScripts = getSemiSourceCodeEditScripts(actionSet); - // this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" + simpleTree.toString() + "\n"; this.tokensOfSourceCode += getTokensDeepFirst(simpleTree).trim() + "\n"; // this.actionSets += Configuration.BUGGY_TREE_TOKEN + "\n" + readActionSet(actionSet, "") + "\n"; // this.originalTree += Configuration.BUGGY_TREE_TOKEN + "\n" + actionSet.getOriginalTree().toString() + "\n"; - - // Source Code of patches. - String patchSourceCode = getPatchSourceCode(hunk, startLine, endLine, startLine2, endLine2); - patchesSourceCode += Configuration.PATCH_TOKEN +"\n" + patchSourceCode + "\n"; } } } @@ -336,6 +336,7 @@ public class SingleStatementParser { if (fixStartLine + fixLineIndex >= startLineNum2 && fixStartLine + fixLineIndex <= endLineNum2) { fixedStatements += line + "\n"; } + fixLines ++; } else { contextLines ++; }