Update
This commit is contained in:
@@ -11,5 +11,6 @@ OUTPUT/
|
||||
*.csv
|
||||
*.pdf
|
||||
Dataset/
|
||||
src/main/java/edu/lu/uni/serval/FixPatternParser/TestParser.java
|
||||
# Package Files #
|
||||
*.jar
|
||||
|
||||
@@ -121,7 +121,7 @@ public class HunkParser {
|
||||
this.astEditScripts += astEditScripts + "\n";
|
||||
|
||||
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" + simpleTree.toString() + "\n";
|
||||
this.tokensOfSourceCode += getTokensDeepFirst(simpleTree).trim() + "\n";
|
||||
this.tokensOfSourceCode += Tokenizer.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";
|
||||
|
||||
@@ -138,54 +138,6 @@ public class HunkParser {
|
||||
return str;
|
||||
}
|
||||
|
||||
private String getTokensDeepFirst(SimpleTree simpleTree) {
|
||||
String tokens = "";
|
||||
List<SimpleTree> children = simpleTree.getChildren();
|
||||
String astNodeType = simpleTree.getNodeType();
|
||||
if ("AssertStatement".equals(astNodeType) || "DoStatement".equals(astNodeType)
|
||||
|| "ForStatement".equals(astNodeType) || "IfStatement".equals(astNodeType)
|
||||
|| "ReturnStatement".equals(astNodeType) || "SwitchStatement".equals(astNodeType)
|
||||
|| "SynchronizedStatement".equals(astNodeType) || "ThrowStatement".equals(astNodeType)
|
||||
|| "TryStatement".equals(astNodeType) || "WhileStatement".equals(astNodeType)) {
|
||||
String label = simpleTree.getLabel();
|
||||
label = label.substring(0, label.lastIndexOf("S")).toLowerCase();
|
||||
tokens += label + " ";
|
||||
} else if ("EnhancedForStatement".equals(astNodeType)) {
|
||||
tokens += "for ";
|
||||
} else if ("CatchClause".equals(astNodeType)) {
|
||||
tokens += "catch ";
|
||||
} else if ("SwitchCase".equals(astNodeType)) {
|
||||
tokens += "case ";
|
||||
} else if ("SuperConstructorInvocation".equals(astNodeType)) {
|
||||
tokens += "super ";
|
||||
} else if ("ConstructorInvocation".equals(astNodeType)) {
|
||||
tokens += "this ";
|
||||
} else if ("FinallyBody".equals(astNodeType)) {
|
||||
tokens += "finally ";
|
||||
}
|
||||
|
||||
if (children.isEmpty()) {
|
||||
if ("StringLiteral".equals(astNodeType)) {
|
||||
tokens += astNodeType + " stringLiteral ";
|
||||
} else if ("CharacterLiteral".equals(astNodeType)) {
|
||||
tokens += astNodeType + " charLiteral ";
|
||||
} else if ("ArrayInitializer".equals(astNodeType)) {
|
||||
tokens += astNodeType + " arrayInitializer ";
|
||||
} else {
|
||||
tokens += astNodeType + " " + simpleTree.getLabel() + " ";
|
||||
}
|
||||
} else {
|
||||
if ("ArrayInitializer".equals(astNodeType)) {
|
||||
tokens += astNodeType + " arrayInitializer ";
|
||||
} else {
|
||||
for (SimpleTree child : children) {
|
||||
tokens += getTokensDeepFirst(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private String getSemiSourceCodeEditScripts(HierarchicalActionSet actionSet) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
||||
@@ -161,7 +161,7 @@ public class SingleStatementParser {
|
||||
String semiSourceCodeEditScripts = getSemiSourceCodeEditScripts(actionSet);
|
||||
|
||||
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" + simpleTree.toString() + "\n";
|
||||
this.tokensOfSourceCode += getTokensDeepFirst(simpleTree).trim() + "\n";
|
||||
this.tokensOfSourceCode += Tokenizer.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";
|
||||
}
|
||||
@@ -249,54 +249,6 @@ public class SingleStatementParser {
|
||||
return str;
|
||||
}
|
||||
|
||||
private String getTokensDeepFirst(SimpleTree simpleTree) {
|
||||
String tokens = "";
|
||||
List<SimpleTree> children = simpleTree.getChildren();
|
||||
String astNodeType = simpleTree.getNodeType();
|
||||
if ("AssertStatement".equals(astNodeType) || "DoStatement".equals(astNodeType)
|
||||
|| "ForStatement".equals(astNodeType) || "IfStatement".equals(astNodeType)
|
||||
|| "ReturnStatement".equals(astNodeType) || "SwitchStatement".equals(astNodeType)
|
||||
|| "SynchronizedStatement".equals(astNodeType) || "ThrowStatement".equals(astNodeType)
|
||||
|| "TryStatement".equals(astNodeType) || "WhileStatement".equals(astNodeType)) {
|
||||
String label = simpleTree.getLabel();
|
||||
label = label.substring(0, label.lastIndexOf("S")).toLowerCase();
|
||||
tokens += label + " ";
|
||||
} else if ("EnhancedForStatement".equals(astNodeType)) {
|
||||
tokens += "for ";
|
||||
} else if ("CatchClause".equals(astNodeType)) {
|
||||
tokens += "catch ";
|
||||
} else if ("SwitchCase".equals(astNodeType)) {
|
||||
tokens += "case ";
|
||||
} else if ("SuperConstructorInvocation".equals(astNodeType)) {
|
||||
tokens += "super ";
|
||||
} else if ("ConstructorInvocation".equals(astNodeType)) {
|
||||
tokens += "this ";
|
||||
} else if ("FinallyBody".equals(astNodeType)) {
|
||||
tokens += "finally ";
|
||||
}
|
||||
|
||||
if (children.isEmpty()) {
|
||||
if ("StringLiteral".equals(astNodeType)) {
|
||||
tokens += astNodeType + " stringLiteral ";
|
||||
} else if ("CharacterLiteral".equals(astNodeType)) {
|
||||
tokens += astNodeType + " charLiteral ";
|
||||
} else if ("ArrayInitializer".equals(astNodeType)) {
|
||||
tokens += astNodeType + " arrayInitializer ";
|
||||
} else {
|
||||
tokens += astNodeType + " " + simpleTree.getLabel() + " ";
|
||||
}
|
||||
} else {
|
||||
if ("ArrayInitializer".equals(astNodeType)) {
|
||||
tokens += astNodeType + " arrayInitializer ";
|
||||
} else {
|
||||
for (SimpleTree child : children) {
|
||||
tokens += getTokensDeepFirst(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private String getSemiSourceCodeEditScripts(HierarchicalActionSet actionSet) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
||||
@@ -12,11 +12,11 @@ import edu.lu.uni.serval.utils.FileHelper;
|
||||
public class TestParser {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String testDataPath = "../../gumtree/gen.jdt/Dataset/"; //DiffEntries prevFiles revFiles
|
||||
String testDataPath = "Dataset/"; //DiffEntries prevFiles revFiles
|
||||
File inputFileDirector = new File(testDataPath);
|
||||
File[] files = inputFileDirector.listFiles(); // project folders
|
||||
|
||||
FileHelper.deleteDirectory("OUTPUT/GumTreeResults_Exp/");
|
||||
FileHelper.deleteDirectory("OUTPUT/GumTreeResults_Exp2/");
|
||||
FileHelper.deleteDirectory("OUTPUT/GumTreeResults_Exp_ASTNode/");
|
||||
FileHelper.deleteDirectory("OUTPUT/GumTreeResults_Exp_RawCode/");
|
||||
|
||||
@@ -26,6 +26,7 @@ public class TestParser {
|
||||
StringBuilder actionSets = new StringBuilder();
|
||||
StringBuilder tokens = new StringBuilder();
|
||||
StringBuilder sizes = new StringBuilder();
|
||||
StringBuilder patches = new StringBuilder();
|
||||
|
||||
for (File file : files) {
|
||||
String projectFolder = file.getPath();
|
||||
@@ -36,8 +37,12 @@ public class TestParser {
|
||||
if (revFile.getName().endsWith(".java")) {
|
||||
File prevFile = new File(projectFolder + "/prevFiles/prev_" + revFile.getName());// previous file
|
||||
File diffentryFile = new File(projectFolder + "/DiffEntries/" + revFile.getName().replace(".java", ".txt")); // DiffEntry file
|
||||
if (revFile.getName().equals("e47d34src#java#org#apache#commons#io#FileCleaner.java")) { // if 的范围
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
Parser parser = new Parser();
|
||||
SingleStatementParser parser = new SingleStatementParser();
|
||||
// HunkParser parser = new HunkParser();
|
||||
try {
|
||||
parser.parseFixPatterns(prevFile, revFile, diffentryFile);
|
||||
|
||||
@@ -47,6 +52,7 @@ public class TestParser {
|
||||
actionSets.append(parser.getActionSets());
|
||||
tokens.append(parser.getTokensOfSourceCode());
|
||||
sizes.append(parser.getSizes());
|
||||
patches.append(parser.getPatchesSourceCode());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
@@ -54,6 +60,7 @@ public class TestParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
// break;
|
||||
}
|
||||
FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp/EditScripts.list", astEditScripts, false);
|
||||
FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp/OriginalTrees.list", originalTrees, false);
|
||||
@@ -61,5 +68,13 @@ public class TestParser {
|
||||
FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp/ActionSets.list", actionSets, false);
|
||||
FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp/Tokens.list", tokens, false);
|
||||
FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp/Sizes.list", sizes, false);
|
||||
FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp/Patches.list", patches, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/EditScripts.list", astEditScripts, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/OriginalTrees.list", originalTrees, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/BuggyTrees.list", buggyTrees, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/ActionSets.list", actionSets, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/Tokens.list", tokens, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/Sizes.list", sizes, false);
|
||||
// FileHelper.outputToFile("OUTPUT/GumTreeResults_Exp2/Patches.list", patches, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package edu.lu.uni.serval.FixPatternParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import edu.lu.uni.serval.gumtree.regroup.SimpleTree;
|
||||
|
||||
public class Tokenizer {
|
||||
|
||||
public static String getTokensDeepFirst(SimpleTree simpleTree) {
|
||||
String tokens = "";
|
||||
List<SimpleTree> children = simpleTree.getChildren();
|
||||
String astNodeType = simpleTree.getNodeType();
|
||||
if ("AssertStatement".equals(astNodeType) || "DoStatement".equals(astNodeType)
|
||||
|| "ForStatement".equals(astNodeType) || "IfStatement".equals(astNodeType)
|
||||
|| "ReturnStatement".equals(astNodeType) || "SwitchStatement".equals(astNodeType)
|
||||
|| "SynchronizedStatement".equals(astNodeType) || "ThrowStatement".equals(astNodeType)
|
||||
|| "TryStatement".equals(astNodeType) || "WhileStatement".equals(astNodeType)) {
|
||||
String label = simpleTree.getLabel();
|
||||
label = label.substring(0, label.lastIndexOf("S")).toLowerCase();
|
||||
tokens += label + " ";
|
||||
} else if ("EnhancedForStatement".equals(astNodeType)) {
|
||||
tokens += "for ";
|
||||
} else if ("CatchClause".equals(astNodeType)) {
|
||||
tokens += "catch ";
|
||||
} else if ("SwitchCase".equals(astNodeType)) {
|
||||
tokens += "case ";
|
||||
} else if ("SuperConstructorInvocation".equals(astNodeType)) {
|
||||
tokens += "super ";
|
||||
} else if ("ConstructorInvocation".equals(astNodeType)) {
|
||||
tokens += "this ";
|
||||
} else if ("FinallyBody".equals(astNodeType)) {
|
||||
tokens += "finally ";
|
||||
}
|
||||
|
||||
if (children.isEmpty()) {
|
||||
if ("StringLiteral".equals(astNodeType)) {
|
||||
tokens += astNodeType + " stringLiteral ";
|
||||
} else if ("CharacterLiteral".equals(astNodeType)) {
|
||||
tokens += astNodeType + " charLiteral ";
|
||||
} else if ("ArrayInitializer".equals(astNodeType)) {
|
||||
tokens += astNodeType + " arrayInitializer ";
|
||||
} else {
|
||||
tokens += astNodeType + " " + simpleTree.getLabel() + " ";
|
||||
}
|
||||
} else {
|
||||
if ("ArrayInitializer".equals(astNodeType)) {
|
||||
tokens += astNodeType + " arrayInitializer ";
|
||||
} else {
|
||||
for (SimpleTree child : children) {
|
||||
tokens += getTokensDeepFirst(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user