Skip to content

Commit

Permalink
Enable detection of renamed attributes in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 25, 2024
1 parent e056cff commit fd8f16b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1791,9 +1791,21 @@ else if(!PrefixSuffixUtils.normalize(replacement.getBefore()).equals(PrefixSuffi
candidate.setOriginalVariableDeclaration(v1.getKey());
if(v2 != null)
candidate.setRenamedVariableDeclaration(v2.getKey());
if(!existsConflictingExtractVariableRefactoring(candidate)) {
ExtractVariableRefactoring conflictingExtractVariableRefactoring = existsConflictingExtractVariableRefactoring(candidate);
if(conflictingExtractVariableRefactoring == null) {
this.candidateAttributeRenames.add(candidate);
}
else {
for(LeafMapping mapping : conflictingExtractVariableRefactoring.getSubExpressionMappings()) {
if(mapping.getFragment1().getString().equals(replacement.getBefore()) &&
!mapping.getFragment1().getString().equals(mapping.getFragment2().getString())) {
CandidateAttributeRefactoring newCandidate = new CandidateAttributeRefactoring(
replacement.getBefore(), mapping.getFragment2().getString(), operation1, operation2,
replacementOccurrenceMap.get(replacement));
this.candidateAttributeRenames.add(newCandidate);
}
}
}
}
}
}
Expand Down Expand Up @@ -2869,16 +2881,16 @@ private boolean existsConflictingParameterRenameInOperationDiff(SplitVariableRef
return false;
}

private boolean existsConflictingExtractVariableRefactoring(CandidateAttributeRefactoring ref) {
private ExtractVariableRefactoring existsConflictingExtractVariableRefactoring(CandidateAttributeRefactoring ref) {
for(Refactoring refactoring : refactorings) {
if(refactoring instanceof ExtractVariableRefactoring) {
ExtractVariableRefactoring extractVariableRef = (ExtractVariableRefactoring)refactoring;
if(extractVariableRef.getVariableDeclaration().equals(ref.getRenamedVariableDeclaration())) {
return true;
return extractVariableRef;
}
}
}
return false;
return null;
}

private boolean existsConflictingExtractVariableRefactoring(RenameVariableRefactoring ref) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLAbstractClassDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,14 @@ private boolean inconsistentAttributeRename(Replacement pattern, Map<String, Set
}
int counter = 0;
int allCases = 0;
String topLevelClassName = null;
if(!originalClass.isTopLevel() && !nextClass.isTopLevel()) {
String originalTopLevelClass = originalClass.getPackageName();
String nextTopLevelClass = nextClass.getPackageName();
if(originalTopLevelClass.equals(nextTopLevelClass) && originalTopLevelClass.contains(".")) {
topLevelClassName = originalTopLevelClass.substring(originalTopLevelClass.lastIndexOf(".") + 1, originalTopLevelClass.length());
}
}
for(UMLOperationBodyMapper mapper : this.operationBodyMapperList) {
List<String> allVariables1 = mapper.getContainer1().getAllVariables();
List<String> allVariables2 = mapper.getContainer2().getAllVariables();
Expand All @@ -1567,9 +1575,15 @@ private boolean inconsistentAttributeRename(Replacement pattern, Map<String, Set
boolean variables1contains = (allVariables1.contains(pattern.getBefore()) &&
!mapper.getContainer1().getParameterNameList().contains(pattern.getBefore())) ||
allVariables1.contains(JAVA.THIS_DOT+pattern.getBefore());
if(!variables1contains && topLevelClassName != null) {
variables1contains = allVariables1.contains(topLevelClassName + "." + JAVA.THIS_DOT+pattern.getBefore());
}
boolean variables2Contains = (allVariables2.contains(pattern.getAfter()) &&
!mapper.getContainer2().getParameterNameList().contains(pattern.getAfter())) ||
allVariables2.contains(JAVA.THIS_DOT+pattern.getAfter());
if(!variables2Contains && topLevelClassName != null) {
variables2Contains = allVariables2.contains(topLevelClassName + "." + JAVA.THIS_DOT+pattern.getAfter());
}
if(variables1contains && !variables2Contains) {
boolean skip = false;
for(AbstractCodeMapping mapping : mapper.getMappings()) {
Expand Down

0 comments on commit fd8f16b

Please sign in to comment.