From 8133161cb622bb6de1f5cc8f128e9b7a8c1a3613 Mon Sep 17 00:00:00 2001 From: chiba Date: Sat, 15 May 2010 13:37:06 +0000 Subject: [PATCH] added ClassPool.getOrNull() git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@544 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/ClassPool.java | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 13f8b71b..78c90c4e 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -440,6 +440,40 @@ public class ClassPool { } } + /** + * Reads a class file from the source and returns a reference + * to the CtClass + * object representing that class file. + * This method is equivalent to get except + * that it returns null when a class file is + * not found and it never throws an exception. + * + * @param classname a fully-qualified class name. + * @return a CtClass object or null. + * @see #get(String) + * @see #find(String) + * @since 3.13 + */ + public CtClass getOrNull(String classname) { + CtClass clazz = null; + if (classname == null) + clazz = null; + else + try { + /* ClassPool.get0() never throws an exception + but its subclass may implement get0 that + may throw an exception. + */ + clazz = get0(classname, true); + } + catch (NotFoundException e){} + + if (clazz != null) + clazz.incGetCounter(); + + return clazz; + } + /** * Returns a CtClass object with the given name. * This is almost equivalent to get(String) except -- 2.39.5