Skip to content

Commit

Permalink
Support tracking for leaf statements when parent method is refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jul 4, 2024
1 parent aa368b3 commit d19041a
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/main/java/org/codetracker/BlockTrackerChangeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public boolean checkForExtractionOrInline(ArrayDeque<Block> blocks, Version curr
ExtractOperationRefactoring extractOperationRefactoring = (ExtractOperationRefactoring) refactoring;
Method extractedMethod = Method.of(extractOperationRefactoring.getExtractedOperation(), currentVersion);
if (equalMethod.test(extractedMethod)) {
CompositeStatementObject matchedBlockFromSourceMethod = null;
AbstractCodeFragment matchedBlockFromSourceMethod = null;
UMLOperationBodyMapper bodyMapper = extractOperationRefactoring.getBodyMapper();
for (AbstractCodeMapping mapping : bodyMapper.getMappings()) {
if (mapping instanceof CompositeStatementObjectMapping) {
Expand All @@ -149,6 +149,19 @@ public boolean checkForExtractionOrInline(ArrayDeque<Block> blocks, Version curr
break;
}
}
else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof StatementObject && mapping.getFragment2() instanceof StatementObject) {
Block matchedBlockInsideExtractedMethodBody = Block.of((StatementObject) mapping.getFragment2(), bodyMapper.getContainer2(), currentVersion);
if (matchedBlockInsideExtractedMethodBody.equalIdentifierIgnoringVersion(rightBlock)) {
matchedBlockFromSourceMethod = mapping.getFragment1();
Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), bodyMapper.getContainer1(), parentVersion);
List<String> stringRepresentationBefore = blockBefore.getComposite().stringRepresentation();
List<String> stringRepresentationAfter = matchedBlockInsideExtractedMethodBody.getComposite().stringRepresentation();
if (!stringRepresentationBefore.equals(stringRepresentationAfter)) {
blockChangeHistory.addChange(blockBefore, matchedBlockInsideExtractedMethodBody, ChangeFactory.forBlock(Change.Type.BODY_CHANGE));
}
break;
}
}
}
Block blockBefore = Block.of(rightBlock.getComposite(), rightBlock.getOperation(), parentVersion);
if (matchedBlockFromSourceMethod == null) {
Expand Down Expand Up @@ -187,6 +200,16 @@ public boolean checkForExtractionOrInline(ArrayDeque<Block> blocks, Version curr
return true;
}
}
else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof StatementObject && mapping.getFragment2() instanceof StatementObject) {
Block matchedBlockInsideInlinedMethodBody = Block.of((StatementObject) mapping.getFragment2(), bodyMapper.getContainer2(), currentVersion);
if (matchedBlockInsideInlinedMethodBody.equalIdentifierIgnoringVersion(rightBlock)) {
Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), bodyMapper.getContainer1(), parentVersion);
blockChangeHistory.handleAdd(blockBefore, matchedBlockInsideInlinedMethodBody, inlineOperationRefactoring.toString());
blocks.add(blockBefore);
blockChangeHistory.connectRelatedNodes();
return true;
}
}
}
}
break;
Expand Down Expand Up @@ -218,6 +241,26 @@ public boolean checkForExtractionOrInline(ArrayDeque<Block> blocks, Version curr
mergeMatches++;
}
}
else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof StatementObject && mapping.getFragment2() instanceof StatementObject) {
Block matchedBlockInsideMergedMethodBody = Block.of((StatementObject) mapping.getFragment2(), bodyMapper.getContainer2(), currentVersion);
if (matchedBlockInsideMergedMethodBody.equalIdentifierIgnoringVersion(rightBlock)) {
// implementation for introduced
/*
Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), bodyMapper.getContainer1(), parentVersion);
blockChangeHistory.handleAdd(blockBefore, matchedBlockInsideMergedMethodBody, mergeOperationRefactoring.toString());
blocks.add(blockBefore);
blockChangeHistory.connectRelatedNodes();
return true;
*/
Set<Refactoring> mapperRefactorings = bodyMapper.getRefactoringsAfterPostProcessing();
//Check if refactored
if (isBlockRefactored(mapperRefactorings, blocks, currentVersion, parentVersion, rightBlock::equalIdentifierIgnoringVersion))
mergeMatches++;
// check if it is in the matched
if (isMatched(bodyMapper, blocks, currentVersion, parentVersion, rightBlock::equalIdentifierIgnoringVersion))
mergeMatches++;
}
}
}
}
if(mergeMatches > 0) {
Expand Down Expand Up @@ -253,6 +296,26 @@ public boolean checkForExtractionOrInline(ArrayDeque<Block> blocks, Version curr
return true;
}
}
else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof StatementObject && mapping.getFragment2() instanceof StatementObject) {
Block matchedBlockInsideSplitMethodBody = Block.of((StatementObject) mapping.getFragment2(), bodyMapper.getContainer2(), currentVersion);
if (matchedBlockInsideSplitMethodBody.equalIdentifierIgnoringVersion(rightBlock)) {
// implementation for introduced
/*
Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), bodyMapper.getContainer1(), parentVersion);
blockChangeHistory.handleAdd(blockBefore, matchedBlockInsideMergedMethodBody, mergeOperationRefactoring.toString());
blocks.add(blockBefore);
blockChangeHistory.connectRelatedNodes();
return true;
*/
Set<Refactoring> mapperRefactorings = bodyMapper.getRefactoringsAfterPostProcessing();
//Check if refactored
if (isBlockRefactored(mapperRefactorings, blocks, currentVersion, parentVersion, rightBlock::equalIdentifierIgnoringVersion))
return true;
// check if it is in the matched
if (isMatched(bodyMapper, blocks, currentVersion, parentVersion, rightBlock::equalIdentifierIgnoringVersion))
return true;
}
}
}
}
}
Expand Down Expand Up @@ -559,7 +622,7 @@ else if (tryBefore.getFinallyClause() != null && tryAfter.getFinallyClause() ==
matches++;
}
}
else if (mapping instanceof LeafMapping && mapping.getFragment2() instanceof StatementObject) {
else if (mapping instanceof LeafMapping && mapping.getFragment1() instanceof StatementObject && mapping.getFragment2() instanceof StatementObject) {
Block blockAfter = Block.of((StatementObject) mapping.getFragment2(), umlOperationBodyMapper.getContainer2(), currentVersion);
if (blockAfter != null && equalOperator.test(blockAfter)) {
Block blockBefore = Block.of((StatementObject) mapping.getFragment1(), umlOperationBodyMapper.getContainer1(), parentVersion);
Expand Down

0 comments on commit d19041a

Please sign in to comment.