Skip to content

Commit

Permalink
Improved the matching of statements nested under catch blocks
Browse files Browse the repository at this point in the history
bennidi/mbassador@744c029
src/main/java/net/engio/mbassy/dispatch/ReflectiveHandlerInvocation.java
  • Loading branch information
tsantalis committed Sep 20, 2024
1 parent 1202c57 commit 4fb5333
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/gr/uom/java/xmi/decomposition/LeafMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ else if(distance1 > distance2 && thisReplacementTypes.size() > otherReplacementT
else if(typeIntersection2 > 0 && typeIntersection1 == 0 && this.getFragment1().getTypes().size() > 0 && this.getFragment2().getTypes().size() > 0 && identicalTypeIntersection1 == 0 && identicalTypeIntersection2 == 0) {
return 1;
}
boolean nestedUnderCatchBlockOfSameType1 = this.nestedUnderCatchBlockOfSameExceptionType();
boolean nestedUnderCatchBlockOfSameType2 = o.nestedUnderCatchBlockOfSameExceptionType();
if(nestedUnderCatchBlockOfSameType1 && !nestedUnderCatchBlockOfSameType2) {
return -1;
}
else if(!nestedUnderCatchBlockOfSameType1 && nestedUnderCatchBlockOfSameType2) {
return 1;
}
return Double.compare(distance1, distance2);
}
else {
Expand Down Expand Up @@ -1086,4 +1094,19 @@ public Set<String> callChainIntersection() {
AbstractCall invocation2 = this.getFragment2().invocationCoveringEntireFragment();
return invocation1.callChainIntersection(invocation2);
}

private boolean nestedUnderCatchBlockOfSameExceptionType() {
CompositeStatementObject comp1 = getFragment1().getParent();
CompositeStatementObject comp2 = getFragment2().getParent();
if(comp1 != null && comp2 != null &&
comp1.getLocationInfo().getCodeElementType().equals(CodeElementType.CATCH_CLAUSE) &&
comp2.getLocationInfo().getCodeElementType().equals(CodeElementType.CATCH_CLAUSE)) {
List<VariableDeclaration> exceptionDeclarations1 = comp1.getVariableDeclarations();
List<VariableDeclaration> exceptionDeclarations2 = comp2.getVariableDeclarations();
if(exceptionDeclarations1.toString().equals(exceptionDeclarations2.toString()) && exceptionDeclarations1.size() > 0) {
return true;
}
}
return false;
}
}

0 comments on commit 4fb5333

Please sign in to comment.