From: Finn B. <bc...@us...> - 2001-08-14 19:43:16
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv19155 Modified Files: PyJavaClass.java Added Files: PyIgnoreMethodTag.java Log Message: Add support for the PyIgnoreMethodTag exception. java methods which have this exception in their throws clause will not be available from python. --- NEW FILE: PyIgnoreMethodTag.java --- package org.python.core; /** * A tagging exception. It is never actually thrown but used * only to mark java methods that should not be visible from * jython. */ public class PyIgnoreMethodTag extends RuntimeException { } Index: PyJavaClass.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaClass.java,v retrieving revision 2.35 retrieving revision 2.36 diff -C2 -d -r2.35 -r2.36 *** PyJavaClass.java 2001/03/04 17:52:39 2.35 --- PyJavaClass.java 2001/08/14 19:43:14 2.36 *************** *** 386,389 **** --- 386,399 ---- } + private boolean ignoreMethod(Method method) { + Class[] exceptions = method.getExceptionTypes(); + for (int j = 0; j < exceptions.length; j++) { + if (exceptions[j] == PyIgnoreMethodTag.class) { + return true; + } + } + return false; + } + /* Add all methods declared by this class */ private void setMethods(Class c, Method[] methods) { *************** *** 393,396 **** --- 403,408 ---- if (dc != c) continue; + if (ignoreMethod(method)) + continue; addMethod(method); } *************** *** 501,504 **** --- 513,518 ---- Method method = meths[i]; + if (ignoreMethod(method)) + continue; if (method.getDeclaringClass() != c || Modifier.isStatic(method.getModifiers())) *************** *** 637,640 **** --- 651,664 ---- } + private boolean ignoreConstructor(Constructor method) { + Class[] exceptions = method.getExceptionTypes(); + for (int j = 0; j < exceptions.length; j++) { + if (exceptions[j] == PyIgnoreMethodTag.class) { + return true; + } + } + return false; + } + private void setConstructors(Class c) { if (Modifier.isInterface(c.getModifiers())) { *************** *** 642,650 **** } else { Constructor[] constructors = getAccessibleConstructors(c); ! if (constructors.length > 0) { ! __init__ = new PyReflectedConstructor(constructors[0]); ! for (int i=1; i < constructors.length; i++) { __init__.addConstructor(constructors[i]); } __dict__.__setitem__("__init__", __init__); } --- 666,680 ---- } else { Constructor[] constructors = getAccessibleConstructors(c); ! for (int i = 0; i < constructors.length; i++) { ! if (ignoreConstructor(constructors[i])) { ! continue; ! } ! if (__init__ == null) { ! __init__ = new PyReflectedConstructor(constructors[i]); ! } else { __init__.addConstructor(constructors[i]); } + } + if (__init__ != null) { __dict__.__setitem__("__init__", __init__); } |