changes for c
This commit is contained in:
@@ -87,13 +87,13 @@ public class CompareTrees {
|
||||
|
||||
try {
|
||||
|
||||
String[] split = pairName.split("_");
|
||||
String[] split = pairName.split("/");
|
||||
|
||||
|
||||
String i = split[1];
|
||||
String j = split[2];
|
||||
String keyName = split[0];
|
||||
matchKey = keyName + "_" + (String.valueOf(i)) + "_" + String.valueOf(j);
|
||||
matchKey = keyName + "/" + (String.valueOf(i)) + "/" + String.valueOf(j);
|
||||
// jedis.select(0);
|
||||
// Set<String> keys = jedis.keys(matchKey);
|
||||
// if (keys.size() > 0) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EDiffParser extends Parser {
|
||||
// GumTree results
|
||||
boolean isJava =false;
|
||||
List<Action> gumTreeResults = null;
|
||||
if (revFile.getName().endsWith(".c") & prevFile.getName().endsWith(".c")){
|
||||
if (revFile.getName().endsWith(".c") & prevFile.getName().endsWith(".c") || revFile.getName().endsWith(".h") & prevFile.getName().endsWith(".h")){
|
||||
// gumTreeResults = new GumTreeComparer().compareCFilesWithGumTree(prevFile, revFile);
|
||||
|
||||
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile);
|
||||
|
||||
+75
-35
@@ -3,6 +3,7 @@ package edu.lu.uni.serval.fixminer.akka.ediff;
|
||||
|
||||
import com.github.gumtreediff.actions.model.Action;
|
||||
import com.github.gumtreediff.actions.model.*;
|
||||
import com.github.gumtreediff.gen.srcml.NodeMap_new;
|
||||
import com.github.gumtreediff.io.CNodeMap;
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import edu.lu.uni.serval.gumtree.GumTreeComparer;
|
||||
@@ -44,6 +45,9 @@ public class HierarchicalRegrouperForC {
|
||||
*/
|
||||
HierarchicalActionSet actionSet = null;
|
||||
for(Action act : actions){
|
||||
if(act.getNode().getType() == 2){
|
||||
continue;
|
||||
}
|
||||
Action parentAct = findParentAction(act, actions);
|
||||
|
||||
if (parentAct == null) {
|
||||
@@ -73,7 +77,9 @@ public class HierarchicalRegrouperForC {
|
||||
// if (astNodeType.endsWith("TypeDeclaration") || astNodeType.endsWith("FieldDeclaration") || astNodeType.endsWith("EnumDeclaration") ||
|
||||
// astNodeType.endsWith("MethodDeclaration") || astNodeType.endsWith("Statement") ||
|
||||
// astNodeType.endsWith("ConstructorInvocation") || astNodeType.endsWith("CatchClause") || astNodeType.endsWith("SwitchCase")) {
|
||||
if (isStatement(actSet.getNode())) {
|
||||
reActionSets.add(actSet);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -103,8 +109,8 @@ public class HierarchicalRegrouperForC {
|
||||
if (Character.isDigit(nodeType.charAt(0)) || (nodeType.startsWith("-") && Character.isDigit(nodeType.charAt(1)))) {
|
||||
try {
|
||||
int typeInt = Integer.parseInt(nodeType);
|
||||
if (CNodeMap.map.containsKey(typeInt)) {
|
||||
String type = CNodeMap.map.get(Integer.parseInt(nodeType));
|
||||
if (NodeMap_new.map.containsKey(typeInt)) {
|
||||
String type = NodeMap_new.map.get(Integer.parseInt(nodeType));
|
||||
nodeType = type;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -194,15 +200,27 @@ public class HierarchicalRegrouperForC {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Action> newParentActions = new ArrayList<>();
|
||||
private Action findParentAction(Action action, List<Action> actions) {
|
||||
|
||||
|
||||
ITree parent = action.getNode().getParent();
|
||||
if (parent == null) return null;
|
||||
if (action instanceof Addition) {
|
||||
parent = ((Addition) action).getParent(); // parent in the fixed source code tree
|
||||
}
|
||||
|
||||
|
||||
// if (parent.getType() == 55) {
|
||||
// int type = action.getNode().getType();
|
||||
// // Modifier, NormalAnnotation, MarkerAnnotation, SingleMemberAnnotation
|
||||
// if (type != 83 && type != 77 && type != 78 && type != 79
|
||||
// && type != 5 && type != 39 && type != 43 && type != 74 && type != 75
|
||||
// && type != 76 && type != 84 && type != 87 && type != 88 && type != 42) {
|
||||
// // ArrayType, PrimitiveType, SimpleType, ParameterizedType,
|
||||
// // QualifiedType, WildcardType, UnionType, IntersectionType, NameQualifiedType, SimpleName
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
for (Action act : actions) {
|
||||
if (act.getNode().equals(parent)) {
|
||||
if (areRelatedActions(act, action)) {
|
||||
@@ -210,35 +228,55 @@ public class HierarchicalRegrouperForC {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Action act : newParentActions) {
|
||||
if (act.getNode().equals(parent)) {
|
||||
if (areRelatedActions(act, action)) {
|
||||
return act;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ITree tree = action.getNode();
|
||||
Action parentAction = null;
|
||||
if (!isStatement(tree)) {
|
||||
parentAction = new Update(parent, action.getNode().getParent());
|
||||
newParentActions.add(parentAction);
|
||||
|
||||
Action higherParentAct = findParentAction(parentAction, actions);
|
||||
HierarchicalActionSet actionSet = null;
|
||||
if (higherParentAct == null) {
|
||||
actionSet = createActionSet(parentAction, higherParentAct, null);
|
||||
actionSets.add(actionSet);
|
||||
} else {
|
||||
if (!addToAactionSet(parentAction, higherParentAct, actionSets)) {
|
||||
// The index of the parent action in the actions' list is larger than the index of this action.
|
||||
actionSet = createActionSet(parentAction, higherParentAct, null);
|
||||
actionSets.add(actionSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
return parentAction;
|
||||
return null;
|
||||
}
|
||||
|
||||
// List<Action> newParentActions = new ArrayList<>();
|
||||
// //TODO
|
||||
// private Action findParentAction(Action action, List<Action> actions) {
|
||||
//
|
||||
// ITree parent = action.getNode().getParent();
|
||||
// if (parent == null) return null;
|
||||
// if (action instanceof Addition) {
|
||||
// parent = ((Addition) action).getParent(); // parent in the fixed source code tree
|
||||
// }
|
||||
//
|
||||
// for (Action act : actions) {
|
||||
// if (act.getNode().equals(parent)) {
|
||||
// if (areRelatedActions(act, action)) {
|
||||
// return act;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// for (Action act : newParentActions) {
|
||||
// if (act.getNode().equals(parent)) {
|
||||
// if (areRelatedActions(act, action)) {
|
||||
// return act;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ITree tree = action.getNode();
|
||||
// Action parentAction = null;
|
||||
// if (!isStatement(tree)) {
|
||||
// parentAction = new Update(parent, action.getNode().getParent());
|
||||
// newParentActions.add(parentAction);
|
||||
//
|
||||
// Action higherParentAct = findParentAction(parentAction, actions);
|
||||
// HierarchicalActionSet actionSet = null;
|
||||
// if (higherParentAct == null) {
|
||||
// actionSet = createActionSet(parentAction, higherParentAct, null);
|
||||
// actionSets.add(actionSet);
|
||||
// } else {
|
||||
// if (!addToAactionSet(parentAction, higherParentAct, actionSets)) {
|
||||
// // The index of the parent action in the actions' list is larger than the index of this action.
|
||||
// actionSet = createActionSet(parentAction, higherParentAct, null);
|
||||
// actionSets.add(actionSet);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return parentAction;
|
||||
// }
|
||||
|
||||
private boolean isStatement(ITree tree) {
|
||||
int nodeType = tree.getType();
|
||||
@@ -247,7 +285,9 @@ public class HierarchicalRegrouperForC {
|
||||
|| nodeType == 22 || nodeType == 23 || nodeType == 24 || nodeType == 84
|
||||
|| 30 == nodeType || nodeType == 31 || nodeType == 32 || nodeType == 33
|
||||
|| nodeType == 34 || nodeType == 35 || nodeType == 36 || nodeType == 40
|
||||
|| nodeType == 41 || nodeType == 49 || nodeType == 73) {// TODO
|
||||
|| nodeType == 41 || nodeType == 49 || nodeType == 73 || nodeType == 81 || nodeType == 80 || nodeType == 46 || nodeType == 60
|
||||
||nodeType == 62 || nodeType == 64 || nodeType == 45 || nodeType == 85 || nodeType == 86 || nodeType == 59 || nodeType == 27 || nodeType == 25
|
||||
|| nodeType == 26 || nodeType ==93 || nodeType == 37 || nodeType == 38 || nodeType == 39) {// TODO
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package edu.lu.uni.serval.fixminer.akka.ediff;
|
||||
|
||||
import edu.lu.uni.serval.fixminer.akka.ediff.EDiffHunkParser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class HunkParserTest {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws IOException {
|
||||
// String input = "/Users/anil.koyuncu/projects/test/fixminer-core/python/data/gumInputLinux/revFiles/7f52f3_3845d29_drivers#pci#host#pcie-altera.c";
|
||||
|
||||
String root = "/Users/anil.koyuncu/projects/test/fixminer-core/python/data/gumInputLinux/linux/";
|
||||
|
||||
String filename = "8dd302_c4ef85_net#core#dev_ioctl.c";
|
||||
// String filename = "052831_3985e8_include#net#ip_tunnels.h";
|
||||
// String filename = "e76019_28647b_drivers#gpu#drm#i915#i915_drv.h";
|
||||
// 121d52_b03543_drivers#gpu#drm#i915#i915_drv.h
|
||||
// String filename = "4cbe4d_b124f4_include#linux#mlx4#device.h";
|
||||
// String filename = "f70b28_95adb4_arch#arm#kernel#topology.c";
|
||||
// String filename = "7bf7eac_c01daf_include#linux#dax.h";
|
||||
// bd0b9ac_b237721_drivers#irqchip#irq-dw-apb-ictl.c
|
||||
File revFile = new File(root + "revFiles/"+ filename);
|
||||
File prevFile =new File(root + "prevFiles/prev_"+filename);
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
|
||||
parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile);
|
||||
// ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot();
|
||||
// Assert.assertEquals(148, t.getSize());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleJava() throws IOException {
|
||||
|
||||
|
||||
String root = "/Users/anil.koyuncu/projects/test/fixminer-core/python/data/gumInput/spring-amqp/";
|
||||
|
||||
String filename = "5d6e02_e597c5_spring-rabbit#src#main#java#org#springframework#amqp#rabbit#connection#ConnectionFactoryUtils.java";
|
||||
File revFile = new File(root +"/revFiles/"+filename);
|
||||
// File oldFile = new File(root +"first.c");
|
||||
File prevFile = new File(root +"/prevFiles/prev_"+filename);
|
||||
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
|
||||
parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile);
|
||||
// ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot();
|
||||
// Assert.assertEquals(148, t.getSize());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class EnhancedASTDiff {
|
||||
|
||||
List<MessageFile> msgFiles = getMessageFiles(target.toString() + "/"); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/"
|
||||
|
||||
|
||||
msgFiles = msgFiles.subList(0,10000);
|
||||
if (msgFiles == null)
|
||||
continue;
|
||||
allMessageFiles.addAll(msgFiles);
|
||||
@@ -125,7 +125,7 @@ public class EnhancedASTDiff {
|
||||
// for (File revFile : collect) {
|
||||
String fileName = revFile.getName();
|
||||
File prevFile = new File(gumTreeInput + "prevFiles/prev_" + fileName);// previous file
|
||||
fileName = fileName.replace(".java", ".txt");
|
||||
fileName = fileName + ".txt";
|
||||
File diffentryFile = new File(gumTreeInput + "DiffEntries/" + fileName); // DiffEntry file
|
||||
|
||||
MessageFile msgFile = new MessageFile(revFile, prevFile, diffentryFile);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package edu.lu.uni.serval.utils;
|
||||
|
||||
import com.github.gumtreediff.actions.model.*;
|
||||
import com.github.gumtreediff.gen.srcml.NodeMap_new;
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
import com.github.gumtreediff.tree.TreeUtils;
|
||||
@@ -81,7 +82,8 @@ public class EDiffHelper {
|
||||
String astNodeType = actionSet.getAstNodeType();
|
||||
|
||||
String label = actionSet.getAction().toString();
|
||||
List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
log.error("More than 1");
|
||||
@@ -124,7 +126,8 @@ public class EDiffHelper {
|
||||
Action action = actionSet.getAction();
|
||||
if (action instanceof Update){
|
||||
astNodeType = actionSet.getAstNodeType();
|
||||
List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
log.error("More than 1");
|
||||
@@ -136,7 +139,8 @@ public class EDiffHelper {
|
||||
newType = ((Move)action).getParent().getType();
|
||||
}else if(action instanceof Delete){
|
||||
astNodeType = actionSet.getAstNodeType();
|
||||
List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
log.error("More than 1");
|
||||
@@ -179,7 +183,8 @@ public class EDiffHelper {
|
||||
int newType = 0;
|
||||
|
||||
String astNodeType = actionSet.getAstNodeType();
|
||||
List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
log.error("More than 1");
|
||||
|
||||
Reference in New Issue
Block a user