From 0d4f8c21f2e341e85d2697b619eaf025131f52e8 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sat, 4 Jan 2025 08:26:59 -0500 Subject: [PATCH] Avoid class pairs with only renamed constructors being matched https://github.com/hibernate/hibernate-search/commit/c4cb8b6876c27cc1364250ce70e8155bdd2c5748 --- src/main/java/gr/uom/java/xmi/UMLAbstractClass.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/gr/uom/java/xmi/UMLAbstractClass.java b/src/main/java/gr/uom/java/xmi/UMLAbstractClass.java index fdb4c5cfb5..7b2459bbe4 100644 --- a/src/main/java/gr/uom/java/xmi/UMLAbstractClass.java +++ b/src/main/java/gr/uom/java/xmi/UMLAbstractClass.java @@ -660,6 +660,7 @@ public MatchResult hasCommonAttributesAndOperations(UMLAbstractClass umlClass) { pattern = new RenamePattern(diff1, diff2); } List commonOperations = new ArrayList(); + List commonConstructors = new ArrayList(); List identicalOperations = new ArrayList(); int totalOperations = 0; int totalDefaultOperations = 0; @@ -686,12 +687,14 @@ 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() && @@ -699,6 +702,7 @@ else if(operation.isConstructor() && !commonPrefix.isEmpty() && !commonSuffix.is containsToken(commonSuffix, tokens1) && containsToken(commonSuffix, tokens2)) { if(pattern != null && umlClass.containsOperationWithTheSameRenamePattern(operation, pattern.reverse())) { commonOperations.add(operation); + commonConstructors.add(operation); } } } @@ -724,12 +728,14 @@ 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() && @@ -737,6 +743,7 @@ else if(operation.isConstructor() && !commonPrefix.isEmpty() && !commonSuffix.is containsToken(commonSuffix, tokens1) && containsToken(commonSuffix, tokens2)) { if(pattern != null && this.containsOperationWithTheSameRenamePattern(operation, pattern)) { commonOperations.add(operation); + commonConstructors.add(operation); } } } @@ -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)) ||