aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/runtime
diff options
context:
space:
mode:
authorpatriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-22 13:47:06 +0000
committerpatriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-22 13:47:06 +0000
commit069bceaf72fd0d6ffad14ce4e3e00ca91a280bde (patch)
treeb8230a15d3061c64d5a64bf9efa654d0d6311ff2 /src/main/javassist/runtime
parentf610083ba0adbcb3fe92a504015fb26fb5a42530 (diff)
downloadjavassist-069bceaf72fd0d6ffad14ce4e3e00ca91a280bde.tar.gz
javassist-069bceaf72fd0d6ffad14ce4e3e00ca91a280bde.zip
This commit was generated by cvs2svn to compensate for changes in r2, which
included commits to RCS files with non-trunk default branches. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@6 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/runtime')
-rw-r--r--src/main/javassist/runtime/Cflow.java62
-rw-r--r--src/main/javassist/runtime/Desc.java167
2 files changed, 229 insertions, 0 deletions
diff --git a/src/main/javassist/runtime/Cflow.java b/src/main/javassist/runtime/Cflow.java
new file mode 100644
index 00000000..693da245
--- /dev/null
+++ b/src/main/javassist/runtime/Cflow.java
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the Javassist toolkit.
+ *
+ * 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. You may obtain a copy of the License at
+ * either http://www.mozilla.org/MPL/.
+ *
+ * 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.
+ *
+ * The Original Code is Javassist.
+ *
+ * The Initial Developer of the Original Code is Shigeru Chiba. Portions
+ * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
+ * All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * The development of this software is supported in part by the PRESTO
+ * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ */
+
+package javassist.runtime;
+
+/**
+ * A support class for implementing <code>$cflow</code>.
+ * This support class is required at runtime
+ * only if <code>$cflow</code> is used.
+ *
+ * @see javassist.CtBehavior#useCflow(String)
+ */
+public class Cflow extends ThreadLocal {
+ private static class Depth {
+ private int depth;
+ Depth() { depth = 0; }
+ int get() { return depth; }
+ void inc() { ++depth; }
+ void dec() { --depth; }
+ }
+
+ protected synchronized Object initialValue() {
+ return new Depth();
+ }
+
+ /**
+ * Increments the counter.
+ */
+ public void enter() { ((Depth)get()).inc(); }
+
+ /**
+ * Decrements the counter.
+ */
+ public void exit() { ((Depth)get()).dec(); }
+
+ /**
+ * Returns the value of the counter.
+ */
+ public int value() { return ((Depth)get()).get(); }
+}
diff --git a/src/main/javassist/runtime/Desc.java b/src/main/javassist/runtime/Desc.java
new file mode 100644
index 00000000..0bf49bf2
--- /dev/null
+++ b/src/main/javassist/runtime/Desc.java
@@ -0,0 +1,167 @@
+/*
+ * This file is part of the Javassist toolkit.
+ *
+ * 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. You may obtain a copy of the License at
+ * either http://www.mozilla.org/MPL/.
+ *
+ * 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.
+ *
+ * The Original Code is Javassist.
+ *
+ * The Initial Developer of the Original Code is Shigeru Chiba. Portions
+ * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
+ * All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * The development of this software is supported in part by the PRESTO
+ * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ */
+
+package javassist.runtime;
+
+/**
+ * A support class for implementing <code>$sig</code> and
+ * <code>$type</code>.
+ * This support class is required at runtime
+ * only if <code>$sig</code> or <code>$type</code> is used.
+ */
+public class Desc {
+
+ /**
+ * Specifies how a <code>java.lang.Class</code> object is loaded.
+ *
+ * <p>If true, it is loaded by:
+ * <ul><pre>Thread.currentThread().getContextClassLoader().loadClass()</pre></ul>
+ * <p>If false, it is loaded by <code>Class.forName()</code>.
+ * The default value is false.
+ */
+ public static boolean useContextClassLoader = false;
+
+ private static Class getClassObject(String name)
+ throws ClassNotFoundException
+ {
+ if (useContextClassLoader)
+ return Thread.currentThread().getContextClassLoader()
+ .loadClass(name);
+ else
+ return Class.forName(name);
+ }
+
+ /**
+ * Interprets the given class name.
+ * It is used for implementing <code>$class</code>.
+ */
+ public static Class getClazz(String name) {
+ try {
+ return getClassObject(name);
+ }
+ catch (ClassNotFoundException e) {
+ throw new RuntimeException("$class: internal error");
+ }
+ }
+
+ /**
+ * Interprets the given type descriptor representing a method
+ * signature. It is used for implementing <code>$sig</code>.
+ */
+ public static Class[] getParams(String desc) {
+ if (desc.charAt(0) != '(')
+ throw new RuntimeException("$sig: internal error");
+
+ return getType(desc, desc.length(), 1, 0);
+ }
+
+ /**
+ * Interprets the given type descriptor.
+ * It is used for implementing <code>$type</code>.
+ */
+ public static Class getType(String desc) {
+ Class[] result = getType(desc, desc.length(), 0, 0);
+ if (result == null || result.length != 1)
+ throw new RuntimeException("$type: internal error");
+
+ return result[0];
+ }
+
+ private static Class[] getType(String desc, int descLen,
+ int start, int num) {
+ Class clazz;
+ if (start >= descLen)
+ return new Class[num];
+
+ char c = desc.charAt(start);
+ switch (c) {
+ case 'Z' :
+ clazz = Boolean.TYPE;
+ break;
+ case 'C' :
+ clazz = Character.TYPE;
+ break;
+ case 'B' :
+ clazz = Byte.TYPE;
+ break;
+ case 'S' :
+ clazz = Short.TYPE;
+ break;
+ case 'I' :
+ clazz = Integer.TYPE;
+ break;
+ case 'J' :
+ clazz = Long.TYPE;
+ break;
+ case 'F' :
+ clazz = Float.TYPE;
+ break;
+ case 'D' :
+ clazz = Double.TYPE;
+ break;
+ case 'V' :
+ clazz = Void.TYPE;
+ break;
+ case 'L' :
+ case '[' :
+ return getClassType(desc, descLen, start, num);
+ default :
+ return new Class[num];
+ }
+
+ Class[] result = getType(desc, descLen, start + 1, num + 1);
+ result[num] = clazz;
+ return result;
+ }
+
+ private static Class[] getClassType(String desc, int descLen,
+ int start, int num) {
+ int end = start;
+ while (desc.charAt(end) == '[')
+ ++end;
+
+ if (desc.charAt(end) == 'L') {
+ end = desc.indexOf(';', end);
+ if (end < 0)
+ throw new IndexOutOfBoundsException("bad descriptor");
+ }
+
+ String cname;
+ if (desc.charAt(start) == 'L')
+ cname = desc.substring(start + 1, end);
+ else
+ cname = desc.substring(start, end + 1);
+
+ Class[] result = getType(desc, descLen, end + 1, num + 1);
+ try {
+ result[num] = getClassObject(cname.replace('/', '.'));
+ }
+ catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+}