Skip to content

Commit

Permalink
Fix for issue #87
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 2, 2025
1 parent 4327bd4 commit 395f359
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gr.uom.java.ast.ASTInformationGenerator;
import gr.uom.java.ast.ASTReader;
import gr.uom.java.ast.AbstractMethodDeclaration;
import gr.uom.java.ast.AnonymousClassDeclarationObject;
import gr.uom.java.ast.ClassObject;
import gr.uom.java.ast.MethodObject;
import gr.uom.java.ast.decomposition.AbstractExpression;
Expand Down Expand Up @@ -1164,8 +1165,21 @@ else if(cloneInfo.extractUtilityClass) {
else {
ThrownExceptionVisitor thrownExceptionVisitor = new ThrownExceptionVisitor();
statement1.getStatement().accept(thrownExceptionVisitor);
Set<String> exceptionsCaughtByCatch = new LinkedHashSet<String>();
for(AnonymousClassDeclarationObject anonymous : statement1.getAnonymousClassDeclarations()) {
for(MethodObject method : anonymous.getMethodList()) {
if(method.getMethodBody() != null) {
for(TryStatementObject tryStatement : method.getMethodBody().getTryStatements()) {
for(CatchClauseObject catchClause : tryStatement.getCatchClauses()) {
exceptionsCaughtByCatch.addAll(catchClause.getExceptionTypes());
}
}
}
}
}
for(ITypeBinding thrownException : thrownExceptionVisitor.getTypeBindings()) {
if(pdgNode1.getThrownExceptionTypes().contains(thrownException.getQualifiedName())) {
if(pdgNode1.getThrownExceptionTypes().contains(thrownException.getQualifiedName()) &&
!exceptionsCaughtByCatch.contains(thrownException.getQualifiedName())) {
addTypeBinding(thrownException, thrownExceptionTypeBindings);
}
}
Expand All @@ -1183,8 +1197,21 @@ else if(cloneInfo.extractUtilityClass) {
else {
ThrownExceptionVisitor thrownExceptionVisitor = new ThrownExceptionVisitor();
statement2.getStatement().accept(thrownExceptionVisitor);
Set<String> exceptionsCaughtByCatch = new LinkedHashSet<String>();
for(AnonymousClassDeclarationObject anonymous : statement2.getAnonymousClassDeclarations()) {
for(MethodObject method : anonymous.getMethodList()) {
if(method.getMethodBody() != null) {
for(TryStatementObject tryStatement : method.getMethodBody().getTryStatements()) {
for(CatchClauseObject catchClause : tryStatement.getCatchClauses()) {
exceptionsCaughtByCatch.addAll(catchClause.getExceptionTypes());
}
}
}
}
}
for(ITypeBinding thrownException : thrownExceptionVisitor.getTypeBindings()) {
if(pdgNode2.getThrownExceptionTypes().contains(thrownException.getQualifiedName())) {
if(pdgNode2.getThrownExceptionTypes().contains(thrownException.getQualifiedName()) &&
!exceptionsCaughtByCatch.contains(thrownException.getQualifiedName())) {
addTypeBinding(thrownException, thrownExceptionTypeBindings);
}
}
Expand Down

0 comments on commit 395f359

Please sign in to comment.