From 75808309ed57af237c249b0909f2278ae346b021 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sat, 4 Jan 2025 19:08:03 -0500 Subject: [PATCH] Promote Extract and Move Method in the same package https://github.com/eclipse/vert.x/commit/718782014519034b28f6d3182fd9d340b7b31a74 --- .../gr/uom/java/xmi/diff/UMLModelDiff.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java index d3526c884..5373a4e2f 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java @@ -4392,7 +4392,7 @@ else if(childFieldDeclarationMap != null) { !conflictingExpression(addedOperationInvocation, addedOperation, variableDeclarationMap, childFieldDeclarationMap)) { UMLOperationBodyMapper operationBodyMapper = createMapperForExtractAndMove(addedOperation, mapper, className, addedOperationInvocation, Optional.empty()); - if(extractAndMoveMatchCondition(operationBodyMapper, mapper, addedOperationInvocation)) { + if(extractAndMoveMatchCondition(operationBodyMapper, mapper, addedOperationInvocation) && !skipRefactoring(operationBodyMapper.getMappings())) { if(className.equals(addedOperation.getClassName())) { //extract inside moved or renamed class createExtractAndMoveMethodRefactoring(addedOperation, mapper, addedOperationInvocations, operationBodyMapper); @@ -4455,6 +4455,38 @@ else if(mapping instanceof CompositeStatementObjectMapping && !mapper.getNonMapp } } + private static boolean samePackage(AbstractCodeMapping mapping) { + String filePathBefore = mapping.getFragment1().getLocationInfo().getFilePath().substring(0, mapping.getFragment1().getLocationInfo().getFilePath().lastIndexOf("/")); + String filePathAfter = mapping.getFragment2().getLocationInfo().getFilePath().substring(0, mapping.getFragment2().getLocationInfo().getFilePath().lastIndexOf("/")); + return filePathBefore.equals(filePathAfter); + } + + private boolean skipRefactoring(Set mappings) { + boolean skip = false; + Set refactoringsToBeRemoved = new LinkedHashSet(); + for(Refactoring r : this.refactorings) { + if(r instanceof ExtractOperationRefactoring) { + ExtractOperationRefactoring extract = (ExtractOperationRefactoring)r; + for(AbstractCodeMapping newMapping : mappings) { + boolean newMappingSamePackage = samePackage(newMapping); + for(AbstractCodeMapping oldMapping : extract.getBodyMapper().getMappings()) { + if(newMapping.getFragment1().equals(oldMapping.getFragment1())) { + boolean oldMappingSamePackage = samePackage(oldMapping); + if(newMappingSamePackage && !oldMappingSamePackage) { + refactoringsToBeRemoved.add(r); + } + else if(!newMappingSamePackage && oldMappingSamePackage) { + skip = true; + } + } + } + } + } + } + this.refactorings.removeAll(refactoringsToBeRemoved); + return skip; + } + private void createExtractAndMoveMethodRefactoring(UMLOperation addedOperation, UMLOperationBodyMapper mapper, List addedOperationInvocations, UMLOperationBodyMapper operationBodyMapper) throws RefactoringMinerTimedOutException {