Skip to content

Commit

Permalink
Avoid class pairs with only renamed constructors being matched
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 4, 2025
1 parent 7030c18 commit 0d4f8c2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/gr/uom/java/xmi/UMLAbstractClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ public MatchResult hasCommonAttributesAndOperations(UMLAbstractClass umlClass) {
pattern = new RenamePattern(diff1, diff2);
}
List<UMLOperation> commonOperations = new ArrayList<UMLOperation>();
List<UMLOperation> commonConstructors = new ArrayList<UMLOperation>();
List<UMLOperation> identicalOperations = new ArrayList<UMLOperation>();
int totalOperations = 0;
int totalDefaultOperations = 0;
Expand All @@ -686,19 +687,22 @@ else if(operation.isConstructor() && commonPrefix.equals(commonSuffix) && common
if(umlClass.containsOperationWithTheSameSignatureIgnoringChangedTypes(operation) ||
(pattern != null && umlClass.containsOperationWithTheSameRenamePattern(operation, pattern.reverse()))) {
commonOperations.add(operation);
commonConstructors.add(operation);
}
}
else if(operation.isConstructor() && commonPrefix.isEmpty() && commonSuffix.equals(this.name)) {
if(umlClass.containsOperationWithTheSameSignatureIgnoringChangedTypes(operation) ||
(pattern != null && umlClass.containsOperationWithTheSameRenamePattern(operation, pattern.reverse()))) {
commonOperations.add(operation);
commonConstructors.add(operation);
}
}
else if(operation.isConstructor() && !commonPrefix.isEmpty() && !commonSuffix.isEmpty() &&
containsToken(commonPrefix, tokens1) && containsToken(commonPrefix, tokens2) &&
containsToken(commonSuffix, tokens1) && containsToken(commonSuffix, tokens2)) {
if(pattern != null && umlClass.containsOperationWithTheSameRenamePattern(operation, pattern.reverse())) {
commonOperations.add(operation);
commonConstructors.add(operation);
}
}
}
Expand All @@ -724,19 +728,22 @@ else if(operation.isConstructor() && commonPrefix.equals(commonSuffix) && common
if(this.containsOperationWithTheSameSignatureIgnoringChangedTypes(operation) ||
(pattern != null && this.containsOperationWithTheSameRenamePattern(operation, pattern))) {
commonOperations.add(operation);
commonConstructors.add(operation);
}
}
else if(operation.isConstructor() && commonPrefix.isEmpty() && commonSuffix.equals(this.name)) {
if(this.containsOperationWithTheSameSignatureIgnoringChangedTypes(operation) ||
(pattern != null && this.containsOperationWithTheSameRenamePattern(operation, pattern))) {
commonOperations.add(operation);
commonConstructors.add(operation);
}
}
else if(operation.isConstructor() && !commonPrefix.isEmpty() && !commonSuffix.isEmpty() &&
containsToken(commonPrefix, tokens1) && containsToken(commonPrefix, tokens2) &&
containsToken(commonSuffix, tokens1) && containsToken(commonSuffix, tokens2)) {
if(pattern != null && this.containsOperationWithTheSameRenamePattern(operation, pattern)) {
commonOperations.add(operation);
commonConstructors.add(operation);
}
}
}
Expand Down Expand Up @@ -835,6 +842,12 @@ else if(commonOperations.size() >= Math.floor((totalOperations-totalDefaultOpera
return new MatchResult(commonOperations.size(), commonAttributes.size(), identicalOperations.size(), totalOperations, totalAttributes, true);
}
}
boolean allAttributesMatched = commonAttributes.size() == totalAttributes && totalAttributes > 0;
boolean containsName = this.getNonQualifiedName().contains(umlClass.getNonQualifiedName()) || umlClass.getNonQualifiedName().contains(this.getNonQualifiedName());
if(commonConstructors.size() == commonOperations.size() && commonConstructors.size() > 0 && !allAttributesMatched && !containsName) {
//return false match result if only constructors have been matched
return new MatchResult(commonOperations.size(), commonAttributes.size(), identicalOperations.size(), totalOperations, totalAttributes, false);
}
int abstractOperationsToBeDeducted = this.isAbstract() != umlClass.isAbstract() ? totalAbstractOperations : 0;
if((commonOperations.size() > Math.floor(totalOperations/2.0) && (commonAttributes.size() > 2 || totalAttributes == 0)) ||
(commonOperations.size() > Math.floor(totalOperations/3.0*2.0) && (commonAttributes.size() >= 2 || totalAttributes == 0)) ||
Expand Down

0 comments on commit 0d4f8c2

Please sign in to comment.