diff --git a/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java b/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java index 1bb40d77..f6469b7c 100644 --- a/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java +++ b/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java @@ -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; @@ -1164,8 +1165,21 @@ else if(cloneInfo.extractUtilityClass) { else { ThrownExceptionVisitor thrownExceptionVisitor = new ThrownExceptionVisitor(); statement1.getStatement().accept(thrownExceptionVisitor); + Set exceptionsCaughtByCatch = new LinkedHashSet(); + 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); } } @@ -1183,8 +1197,21 @@ else if(cloneInfo.extractUtilityClass) { else { ThrownExceptionVisitor thrownExceptionVisitor = new ThrownExceptionVisitor(); statement2.getStatement().accept(thrownExceptionVisitor); + Set exceptionsCaughtByCatch = new LinkedHashSet(); + 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); } }