1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 03:53:21 +02:00

- updated to catch possible exceptions

This commit is contained in:
Alena Laskavaia 2010-03-29 15:34:44 +00:00
parent 0794acbd0f
commit 4967787769

View file

@ -8,9 +8,9 @@
* Contributors: * Contributors:
* Alena Laskavaia - initial API and implementation * Alena Laskavaia - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers; package org.eclipse.cdt.codan.internal.checkers;
import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@ -41,7 +41,6 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
// traverse the ast using the visitor pattern. // traverse the ast using the visitor pattern.
ast.accept(new OnCatch()); ast.accept(new OnCatch());
} }
class OnCatch extends ASTVisitor { class OnCatch extends ASTVisitor {
OnCatch() { OnCatch() {
shouldVisitStatements = true; shouldVisitStatements = true;
@ -49,6 +48,7 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
public int visit(IASTStatement stmt) { public int visit(IASTStatement stmt) {
if (stmt instanceof ICPPASTTryBlockStatement) { if (stmt instanceof ICPPASTTryBlockStatement) {
try {
ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt; ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt;
ICPPASTCatchHandler[] catchHandlers = tblock.getCatchHandlers(); ICPPASTCatchHandler[] catchHandlers = tblock.getCatchHandlers();
next: for (int i = 0; i < catchHandlers.length; i++) { next: for (int i = 0; i < catchHandlers.length; i++) {
@ -63,17 +63,21 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
// unwind typedef chain // unwind typedef chain
while (typeName instanceof ITypedef) { while (typeName instanceof ITypedef) {
IType t = ((ITypedef) typeName).getType(); IType t = ((ITypedef) typeName).getType();
if (t instanceof IBasicType) continue next; if (t instanceof IBasicType)
if (t instanceof IBinding) typeName = (IBinding) t; continue next;
else break; if (t instanceof IBinding)
typeName = (IBinding) t;
else
break;
} }
reportProblem(ER_ID, decl); reportProblem(ER_ID, decl);
} }
} }
} }
} }
} catch (Exception e) {
CodanCheckersActivator.log(e);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
@ -92,13 +96,13 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
IASTPointerOperator[] pointerOperators = d.getPointerOperators(); IASTPointerOperator[] pointerOperators = d.getPointerOperators();
for (int j = 0; j < pointerOperators.length; j++) { for (int j = 0; j < pointerOperators.length; j++) {
IASTPointerOperator po = pointerOperators[j]; IASTPointerOperator po = pointerOperators[j];
if (po instanceof ICPPASTReferenceOperator) { return true; } if (po instanceof ICPPASTReferenceOperator) {
return true;
}
} }
} }
} }
return false; return false;
} }
} }
} }