Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #830

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Dev #830

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void computeMovedDiffsEditScripts() {

private void makeASTDiff(List<? extends UMLAbstractClassDiff> umlClassBaseDiffList, boolean mergeFlag){
for (UMLAbstractClassDiff classDiff : umlClassBaseDiffList) {
Collection<ASTDiff> appends = findAppends(projectASTDiff.getDiffSet(), classDiff.getOriginalClass().getSourceFile(), classDiff.getNextClass().getSourceFile());
Collection<ASTDiff> appends = findAppends(projectASTDiff.getDiffSet(), classDiff.getOriginalClass().getSourceFile(), classDiff.getNextClass().getSourceFile(), false);
boolean decision = (!appends.isEmpty()) || mergeFlag;
ASTDiff classASTDiff = process(classDiff, findTreeContexts(modelDiff, classDiff), decision, appends);
if (!appends.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,28 @@ else if (refactoring.getRefactoringType().equals(RefactoringType.MOVE_AND_INLINE
}

private void findDiffsAndApplyMatcher(String srcPath, String dstPath, OptimizationAwareMatcher matcher) {
Collection<ASTDiff> diffs = findAppends(diffSet, srcPath, dstPath);
Collection<ASTDiff> diffs = findAppends(diffSet, srcPath, dstPath, false);
if (diffs.isEmpty()) {
//This means that the there is no astDiff associated with the refactoring,
//It could be a case of move from a deleted file to an added file which neither of them have an equivalent file in the other side.
//In this case, we should create a new ASTDiff and apply the matcher on it.
Pair<TreeContext, TreeContext> treeContextPair = findTreeContexts(modelDiff, srcPath, dstPath);
Tree srcTree = treeContextPair.first.getRoot();
Tree dstTree = treeContextPair.second.getRoot();
ExtendedMultiMappingStore mappingStore = new ExtendedMultiMappingStore(srcTree, dstTree);
ASTDiff diff = new ASTDiff(srcPath, dstPath,
Collection<ASTDiff> appends = findAppends(newlyGeneratedDiffsOptimizationMap.keySet(), srcPath, dstPath, true);
if (appends.isEmpty()) {
Pair<TreeContext, TreeContext> treeContextPair = findTreeContexts(modelDiff, srcPath, dstPath);
Tree srcTree = treeContextPair.first.getRoot();
Tree dstTree = treeContextPair.second.getRoot();
ExtendedMultiMappingStore mappingStore = new ExtendedMultiMappingStore(srcTree, dstTree);
ASTDiff diff = new ASTDiff(srcPath, dstPath,
treeContextPair.first, treeContextPair.second,
mappingStore);
newlyGeneratedDiffsOptimizationMap.putIfAbsent(diff, new OptimizationData(new ArrayList<>(), new ExtendedMultiMappingStore(srcTree,dstTree)));
newlyGeneratedDiffsOptimizationMap.get(diff);
setOptimizationAndMatch(matcher, diff, newlyGeneratedDiffsOptimizationMap.get(diff), srcTree, dstTree);
newlyGeneratedDiffsOptimizationMap.putIfAbsent(diff, new OptimizationData(new ArrayList<>(), new ExtendedMultiMappingStore(srcTree,dstTree)));
setOptimizationAndMatch(matcher, diff, newlyGeneratedDiffsOptimizationMap.get(diff), srcTree, dstTree);
}
else {
for (ASTDiff append : appends) {
setOptimizationAndMatch(matcher, append, newlyGeneratedDiffsOptimizationMap.get(append), append.src.getRoot(), append.dst.getRoot());
}
}
}
for (ASTDiff diff : diffs) {
Tree srcTotalTree = modelDiff.getParentModel().getTreeContextMap().get(srcPath).getRoot();
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/refactoringminer/astDiff/utils/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ public static Pair<Tree, Tree> findPairOfType(Tree srcOperationNode, Tree dstOpe
return null;
}

public static Collection<ASTDiff> findAppends(Collection<ASTDiff> diffs, String originalSourceFile, String nextSourceFile) {
public static Collection<ASTDiff> findAppends(Collection<ASTDiff> diffs, String originalSourceFile, String nextSourceFile, boolean both) {
Collection<ASTDiff> appends = new LinkedHashSet<>();
for (ASTDiff existing : diffs) {
if (existing.getSrcPath().equals(originalSourceFile))
appends.add(existing);
else if (existing.getDstPath().equals(nextSourceFile))
appends.add(existing);
if (both) {
if (existing.getSrcPath().equals(originalSourceFile) && existing.getDstPath().equals(nextSourceFile)) {
appends.add(existing);
break;
}
}
else {
if (existing.getSrcPath().equals(originalSourceFile))
appends.add(existing);
else if (existing.getDstPath().equals(nextSourceFile))
appends.add(existing);
}
}
return appends;
}
Expand Down
Loading