Skip to content

Commit

Permalink
Support for type declaration moves in tree file diff view
Browse files Browse the repository at this point in the history
(issue #703)
  • Loading branch information
tsantalis committed May 2, 2024
1 parent 2b828fa commit 25959ec
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private void createASTDiffsForMovedDeclarations() {
for(ASTDiff diff : projectASTDiff.getDiffSet()) {
Map<Tree, List<Mapping>> methodDeclarationMappings = new LinkedHashMap<Tree, List<Mapping>>();
Map<Tree, List<Mapping>> fieldDeclarationMappings = new LinkedHashMap<Tree, List<Mapping>>();
Map<Tree, List<Mapping>> typeDeclarationMappings = new LinkedHashMap<Tree, List<Mapping>>();
Map<Tree, Action> actionMap = new LinkedHashMap<Tree, Action>();
ExtendedOnlyRootsClassifier classifier = (ExtendedOnlyRootsClassifier) diff.createRootNodesClassifier();
Map<Tree, Action> map = classifier.getSrcMoveOutTreeMap();
Expand Down Expand Up @@ -117,6 +118,14 @@ private void createASTDiffsForMovedDeclarations() {
}
}
}
if(src.getType().name.equals(Constants.TYPE_DECLARATION) ||
src.getType().name.equals(Constants.ENUM_DECLARATION) ||
src.getType().name.equals(Constants.RECORD_DECLARATION)) {
actionMap.put(src, map.get(src));
List<Mapping> mappings = new ArrayList<Mapping>();
mappings.addAll(getMappingForLeft(diff, src));
typeDeclarationMappings.put(src, mappings);
}
}
//group the mappings based on the pair of src and dst files.
String srcPath = diff.getSrcPath();
Expand Down Expand Up @@ -156,6 +165,24 @@ private void createASTDiffsForMovedDeclarations() {
}
}
}
for(Tree key : typeDeclarationMappings.keySet()) {
if(actionMap.containsKey(key)) {
Action action = actionMap.get(key);
if(action instanceof MoveOut) {
MoveOut moveOut = (MoveOut)action;
String dstPath = moveOut.getDstFile();
Pair<String, String> pair = new Pair<String, String>(srcPath, dstPath);
if(filePairMappings.containsKey(pair)) {
filePairMappings.get(pair).addAll(typeDeclarationMappings.get(key));
}
else {
List<Mapping> mappings = new ArrayList<Mapping>();
mappings.addAll(typeDeclarationMappings.get(key));
filePairMappings.put(pair, mappings);
}
}
}
}
}
for(Pair<String, String> pair : filePairMappings.keySet()) {
Pair<TreeContext, TreeContext> treeContextPairs = findTreeContexts(pair.first, pair.second);
Expand Down

0 comments on commit 25959ec

Please sign in to comment.