diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-01-11 06:45:57 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-01-11 06:45:57 +0000 |
commit | 774508d17c92daa8c469ad80525de2f8655e4019 (patch) | |
tree | c5bda1997f4065bb936ca44f3592754fc7dd9473 /src/main/javassist/util/proxy/RuntimeSupport.java | |
parent | 52a455616e4077b5b61823cb4765c02fc6866f9a (diff) | |
download | javassist-774508d17c92daa8c469ad80525de2f8655e4019.tar.gz javassist-774508d17c92daa8c469ad80525de2f8655e4019.zip |
updated copyright notices
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@234 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/util/proxy/RuntimeSupport.java')
-rw-r--r-- | src/main/javassist/util/proxy/RuntimeSupport.java | 314 |
1 files changed, 157 insertions, 157 deletions
diff --git a/src/main/javassist/util/proxy/RuntimeSupport.java b/src/main/javassist/util/proxy/RuntimeSupport.java index 837ed6ca..3e469699 100644 --- a/src/main/javassist/util/proxy/RuntimeSupport.java +++ b/src/main/javassist/util/proxy/RuntimeSupport.java @@ -1,157 +1,157 @@ -/*
- * Javassist, a Java-bytecode translator toolkit.
- * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. Alternatively, the contents of this file may be used under
- * the terms of the GNU Lesser General Public License Version 2.1 or later.
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- */
-
-package javassist.util.proxy;
-
-import java.lang.reflect.Method;
-
-/**
- * Runtime support routines that the classes generated by ProxyFactory use.
- *
- * @see ProxyFactory
- */
-public class RuntimeSupport {
- /**
- * Finds a method with the given name and descriptor.
- * It searches only the class of self.
- *
- * @throws RuntimeException if the method is not found.
- */
- public static Method findMethod(Object self, String name, String desc) {
- Method m = findMethod2(self.getClass(), name, desc);
- if (m == null)
- error(self, name, desc);
-
- return m;
- }
-
- /**
- * Finds a method that has the given name and descriptor and is declared
- * in the super class.
- *
- * @throws RuntimeException if the method is not found.
- */
- public static Method findSuperMethod(Object self, String name, String desc) {
- Class clazz = self.getClass();
- Method m = findSuperMethod2(clazz.getSuperclass(), name, desc);
- if (m == null)
- m = searchInterfaces(clazz, name, desc);
-
- if (m == null)
- error(self, name, desc);
-
- return m;
- }
-
- private static void error(Object self, String name, String desc) {
- throw new RuntimeException("not found " + name + ":" + desc
- + " in " + self.getClass().getName());
- }
-
- private static Method findSuperMethod2(Class clazz, String name, String desc) {
- Method m = findMethod2(clazz, name, desc);
- if (m != null)
- return m;
-
- Class superClass = clazz.getSuperclass();
- if (superClass != null) {
- m = findSuperMethod2(superClass, name, desc);
- if (m != null)
- return m;
- }
-
- return searchInterfaces(clazz, name, desc);
- }
-
- private static Method searchInterfaces(Class clazz, String name, String desc) {
- Method m = null;
- Class[] interfaces = clazz.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- m = findSuperMethod2(interfaces[i], name, desc);
- if (m != null)
- return m;
- }
-
- return m;
- }
-
- private static Method findMethod2(Class clazz, String name, String desc) {
- Method[] methods = clazz.getDeclaredMethods();
- int n = methods.length;
- for (int i = 0; i < n; i++)
- if (methods[i].getName().equals(name)
- && makeDescriptor(methods[i]).equals(desc))
- return methods[i];
-
- return null;
- }
-
- /**
- * Makes a descriptor for a given method.
- */
- public static String makeDescriptor(Method m) {
- Class[] params = m.getParameterTypes();
- return makeDescriptor(params, m.getReturnType());
- }
-
- /**
- * Makes a descriptor for a given method.
- *
- * @param params parameter types.
- * @param retType return type.
- */
- public static String makeDescriptor(Class[] params, Class retType) {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append('(');
- for (int i = 0; i < params.length; i++)
- makeDesc(sbuf, params[i]);
-
- sbuf.append(')');
- makeDesc(sbuf, retType);
- return sbuf.toString();
- }
-
- private static void makeDesc(StringBuffer sbuf, Class type) {
- if (type.isArray()) {
- sbuf.append('[');
- makeDesc(sbuf, type.getComponentType());
- }
- else if (type.isPrimitive()) {
- if (type == Void.TYPE)
- sbuf.append('V');
- else if (type == Integer.TYPE)
- sbuf.append('I');
- else if (type == Byte.TYPE)
- sbuf.append('B');
- else if (type == Long.TYPE)
- sbuf.append('J');
- else if (type == Double.TYPE)
- sbuf.append('D');
- else if (type == Float.TYPE)
- sbuf.append('F');
- else if (type == Character.TYPE)
- sbuf.append('C');
- else if (type == Short.TYPE)
- sbuf.append('S');
- else if (type == Boolean.TYPE)
- sbuf.append('Z');
- else
- throw new RuntimeException("bad type: " + type.getName());
- }
- else
- sbuf.append('L').append(type.getName().replace('.', '/'))
- .append(';');
- }
-}
+/* + * Javassist, a Java-bytecode translator toolkit. + * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved. + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. Alternatively, the contents of this file may be used under + * the terms of the GNU Lesser General Public License Version 2.1 or later. + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + */ + +package javassist.util.proxy; + +import java.lang.reflect.Method; + +/** + * Runtime support routines that the classes generated by ProxyFactory use. + * + * @see ProxyFactory + */ +public class RuntimeSupport { + /** + * Finds a method with the given name and descriptor. + * It searches only the class of self. + * + * @throws RuntimeException if the method is not found. + */ + public static Method findMethod(Object self, String name, String desc) { + Method m = findMethod2(self.getClass(), name, desc); + if (m == null) + error(self, name, desc); + + return m; + } + + /** + * Finds a method that has the given name and descriptor and is declared + * in the super class. + * + * @throws RuntimeException if the method is not found. + */ + public static Method findSuperMethod(Object self, String name, String desc) { + Class clazz = self.getClass(); + Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); + if (m == null) + m = searchInterfaces(clazz, name, desc); + + if (m == null) + error(self, name, desc); + + return m; + } + + private static void error(Object self, String name, String desc) { + throw new RuntimeException("not found " + name + ":" + desc + + " in " + self.getClass().getName()); + } + + private static Method findSuperMethod2(Class clazz, String name, String desc) { + Method m = findMethod2(clazz, name, desc); + if (m != null) + return m; + + Class superClass = clazz.getSuperclass(); + if (superClass != null) { + m = findSuperMethod2(superClass, name, desc); + if (m != null) + return m; + } + + return searchInterfaces(clazz, name, desc); + } + + private static Method searchInterfaces(Class clazz, String name, String desc) { + Method m = null; + Class[] interfaces = clazz.getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + m = findSuperMethod2(interfaces[i], name, desc); + if (m != null) + return m; + } + + return m; + } + + private static Method findMethod2(Class clazz, String name, String desc) { + Method[] methods = clazz.getDeclaredMethods(); + int n = methods.length; + for (int i = 0; i < n; i++) + if (methods[i].getName().equals(name) + && makeDescriptor(methods[i]).equals(desc)) + return methods[i]; + + return null; + } + + /** + * Makes a descriptor for a given method. + */ + public static String makeDescriptor(Method m) { + Class[] params = m.getParameterTypes(); + return makeDescriptor(params, m.getReturnType()); + } + + /** + * Makes a descriptor for a given method. + * + * @param params parameter types. + * @param retType return type. + */ + public static String makeDescriptor(Class[] params, Class retType) { + StringBuffer sbuf = new StringBuffer(); + sbuf.append('('); + for (int i = 0; i < params.length; i++) + makeDesc(sbuf, params[i]); + + sbuf.append(')'); + makeDesc(sbuf, retType); + return sbuf.toString(); + } + + private static void makeDesc(StringBuffer sbuf, Class type) { + if (type.isArray()) { + sbuf.append('['); + makeDesc(sbuf, type.getComponentType()); + } + else if (type.isPrimitive()) { + if (type == Void.TYPE) + sbuf.append('V'); + else if (type == Integer.TYPE) + sbuf.append('I'); + else if (type == Byte.TYPE) + sbuf.append('B'); + else if (type == Long.TYPE) + sbuf.append('J'); + else if (type == Double.TYPE) + sbuf.append('D'); + else if (type == Float.TYPE) + sbuf.append('F'); + else if (type == Character.TYPE) + sbuf.append('C'); + else if (type == Short.TYPE) + sbuf.append('S'); + else if (type == Boolean.TYPE) + sbuf.append('Z'); + else + throw new RuntimeException("bad type: " + type.getName()); + } + else + sbuf.append('L').append(type.getName().replace('.', '/')) + .append(';'); + } +} |