From: chiba Date: Sat, 15 May 2010 13:37:06 +0000 (+0000) Subject: added ClassPool.getOrNull() X-Git-Tag: rel_3_17_1_ga~107 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8133161cb622bb6de1f5cc8f128e9b7a8c1a3613;p=javassist.git added ClassPool.getOrNull() git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@544 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- 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