diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2010-05-15 13:37:06 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2010-05-15 13:37:06 +0000 |
commit | 8133161cb622bb6de1f5cc8f128e9b7a8c1a3613 (patch) | |
tree | 56308c857c148a07fcd31e311ccfd970c28a7eb1 | |
parent | 2fe46756aae8b87c77715871ea1c72aae08ed9b2 (diff) | |
download | javassist-8133161cb622bb6de1f5cc8f128e9b7a8c1a3613.tar.gz javassist-8133161cb622bb6de1f5cc8f128e9b7a8c1a3613.zip |
added ClassPool.getOrNull()
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@544 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | src/main/javassist/ClassPool.java | 34 |
1 files changed, 34 insertions, 0 deletions
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 @@ -441,6 +441,40 @@ public class ClassPool { } /** + * Reads a class file from the source and returns a reference + * to the <code>CtClass</code> + * object representing that class file. + * This method is equivalent to <code>get</code> except + * that it returns <code>null</code> when a class file is + * not found and it never throws an exception. + * + * @param classname a fully-qualified class name. + * @return a <code>CtClass</code> object or <code>null</code>. + * @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 <code>CtClass</code> object with the given name. * This is almost equivalent to <code>get(String)</code> except * that classname can be an array-type "descriptor" (an encoded |