Skip to content

Commit

Permalink
Restore mappings for JabRef/jabref#8934 (#715)
Browse files Browse the repository at this point in the history
The commit causes test to fail. Test needs to be updated.
liferay/liferay-portal@59fd9e6
  • Loading branch information
tsantalis committed Jun 2, 2024
1 parent 19d32d5 commit 2fab3c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ProjectASTDiffer
private final ProjectASTDiff projectASTDiff;
private final MovedASTDiffGenerator movedDeclarationGenerator;
private final Map<String, OptimizationData> optimizationDataMap = new HashMap<>();
private final List<Refactoring> processedMoveRefactorings = new ArrayList<Refactoring>();

public ProjectASTDiffer(UMLModelDiff modelDiff, Map<String, String> fileContentsBefore, Map<String, String> fileContentsAfter) throws RefactoringMinerTimedOutException {
this.modelDiff = modelDiff;
Expand Down Expand Up @@ -127,8 +128,9 @@ private List<? extends UMLAbstractClassDiff> getExtraDiffs() {
ReplaceAnonymousWithClassRefactoring replaceAnonymousWithClassRefactoring = (ReplaceAnonymousWithClassRefactoring) modelDiffRefactoring;
extraDiffs.add(replaceAnonymousWithClassRefactoring.getDiff());
}
else if(modelDiffRefactoring.getRefactoringType() == RefactoringType.MOVE_AND_RENAME_OPERATION ||
modelDiffRefactoring.getRefactoringType() == RefactoringType.MOVE_OPERATION)
else if((modelDiffRefactoring.getRefactoringType() == RefactoringType.MOVE_AND_RENAME_OPERATION ||
modelDiffRefactoring.getRefactoringType() == RefactoringType.MOVE_OPERATION) &&
!processedMoveRefactorings.contains(modelDiffRefactoring))
{
MoveOperationRefactoring moveOperationRefactoring = (MoveOperationRefactoring) modelDiffRefactoring;
String srcPath = moveOperationRefactoring.getOriginalOperation().getLocationInfo().getFilePath();
Expand All @@ -142,13 +144,18 @@ else if(modelDiffRefactoring.getRefactoringType() == RefactoringType.MOVE_AND_RE
new ExtendedMultiMappingStore(srcTree,dstTree)));
optimizationData = optimizationDataMap.get(srcPath);
new MethodMatcher(optimizationData, moveOperationRefactoring.getBodyMapper()).match(srcTree, dstTree, mappingStore);
mappingStore.addMapping(treeContextPair.first.getRoot(), treeContextPair.second.getRoot());
ASTDiff diff = new ASTDiff(srcPath, dstPath,
treeContextPair.first, treeContextPair.second,
mappingStore,
new SimplifiedExtendedChawatheScriptGenerator().computeActions(mappingStore));
mappingStore.removeMapping(treeContextPair.first.getRoot(), treeContextPair.second.getRoot());
projectASTDiff.addMoveASTDiff(diff);
ASTDiff append = findAppend(srcPath, dstPath);
if (append != null)
append.getAllMappings().mergeMappings(mappingStore);
else {
mappingStore.addMapping(treeContextPair.first.getRoot(), treeContextPair.second.getRoot());
ASTDiff diff = new ASTDiff(srcPath, dstPath,
treeContextPair.first, treeContextPair.second,
mappingStore,
new SimplifiedExtendedChawatheScriptGenerator().computeActions(mappingStore));
mappingStore.removeMapping(treeContextPair.first.getRoot(), treeContextPair.second.getRoot());
projectASTDiff.addMoveASTDiff(diff);
}
}
}
return extraDiffs;
Expand Down Expand Up @@ -219,7 +226,9 @@ private ASTDiff process(UMLAbstractClassDiff classDiff, Pair<TreeContext, TreeCo
new EnumConstantsMatcher(classDiff.getCommonEnumConstants()).match(srcTree,dstTree,mappingStore);
for(UMLOperationBodyMapper umlOperationBodyMapper : classDiff.getOperationBodyMapperList())
new MethodMatcher(optimizationData, umlOperationBodyMapper).match(srcTree, dstTree, mappingStore);
new ModelDiffRefactoringsForClassDiffMatcher(optimizationData, modelDiff, modelDiffRefactorings, classDiff).match(srcTree,dstTree,mappingStore);
ModelDiffRefactoringsForClassDiffMatcher modelDiffRefactoringsForClassDiffMatcher = new ModelDiffRefactoringsForClassDiffMatcher(optimizationData, modelDiff, modelDiffRefactorings, classDiff);
modelDiffRefactoringsForClassDiffMatcher.match(srcTree,dstTree,mappingStore);
processedMoveRefactorings.addAll(modelDiffRefactoringsForClassDiffMatcher.getProcessedMoveRefactorings());

if (isBaseDiff){
UMLClassBaseDiff baseClassDiff = (UMLClassBaseDiff) classDiff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
import org.refactoringminer.astDiff.models.OptimizationData;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -19,15 +20,22 @@ public class ModelDiffRefactoringsForClassDiffMatcher extends OptimizationAwareM
private final UMLModelDiff modelDiff;
private final List<Refactoring> modelDiffRefactorings;
private final UMLAbstractClassDiff classDiff;
private final List<Refactoring> processedMoveRefactorings;

// private final List<Refactoring> modelDiffRefactorings;
public ModelDiffRefactoringsForClassDiffMatcher(OptimizationData optimizationData, UMLModelDiff modelDiff, List<Refactoring> modelDiffRefactorings, UMLAbstractClassDiff classDiff) {
super(optimizationData);
this.modelDiff = modelDiff;
this.modelDiffRefactorings = modelDiffRefactorings; //This is just for performance boost
this.classDiff = classDiff;
this.processedMoveRefactorings = new ArrayList<Refactoring>();
}
@Override

public List<Refactoring> getProcessedMoveRefactorings() {
return processedMoveRefactorings;
}

@Override
public void match(Tree srcTree, Tree dstTree, ExtendedMultiMappingStore mappingStore) {
processModelDiffRefactorings(classDiff, mappingStore);
processMovedAttributes(classDiff,mappingStore);
Expand All @@ -46,6 +54,7 @@ private void processModelDiffRefactorings(UMLAbstractClassDiff classDiff, Extend
Tree srcTotalTree = modelDiff.getParentModel().getTreeContextMap().get(srcPath).getRoot();
Tree dstTotalTree = modelDiff.getChildModel().getTreeContextMap().get(dstPath).getRoot();
new MethodMatcher(optimizationData, moveOperationRefactoring.getBodyMapper()).match(srcTotalTree, dstTotalTree, mappingStore);
this.processedMoveRefactorings.add(moveOperationRefactoring);
}
} else if (refactoring instanceof MoveAttributeRefactoring) {
if (afterRefactoringClasses.contains(classDiff.getNextClass().getName()) ||
Expand All @@ -56,19 +65,22 @@ private void processModelDiffRefactorings(UMLAbstractClassDiff classDiff, Extend
Tree srcTotalTree = modelDiff.getParentModel().getTreeContextMap().get(srcPath).getRoot();
Tree dstTotalTree = modelDiff.getChildModel().getTreeContextMap().get(dstPath).getRoot();
new FieldDeclarationMatcher(moveAttributeRefactoring.getOriginalAttribute(), moveAttributeRefactoring.getMovedAttribute()).match(srcTotalTree, dstTotalTree, mappingStore);
this.processedMoveRefactorings.add(moveAttributeRefactoring);
}
} else if (refactoring.getRefactoringType().equals(RefactoringType.EXTRACT_AND_MOVE_OPERATION)) {
if (afterRefactoringClasses.contains(classDiff.getNextClass().getName()) ||
beforeRefactoringClasses.contains(classDiff.getOriginalClass().getName())) {
ExtractOperationRefactoring extractOperationRefactoring = (ExtractOperationRefactoring) refactoring;
findTreeFromMapperAndProcessBodyMapper(extractOperationRefactoring.getBodyMapper(), mappingStore);
this.processedMoveRefactorings.add(extractOperationRefactoring);
}
}
else if (refactoring.getRefactoringType().equals(RefactoringType.MOVE_AND_INLINE_OPERATION)) {
if (afterRefactoringClasses.contains(classDiff.getNextClass().getName()) ||
beforeRefactoringClasses.contains(classDiff.getOriginalClass().getName())) {
InlineOperationRefactoring inlineOperationRefactoring = (InlineOperationRefactoring) refactoring;
findTreeFromMapperAndProcessBodyMapper(inlineOperationRefactoring.getBodyMapper(), mappingStore);
this.processedMoveRefactorings.add(inlineOperationRefactoring);
}
}

Expand Down

0 comments on commit 2fab3c3

Please sign in to comment.