From e0dfddb46b4a6ab6f65ceb0297a1fdecc7147b85 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 23 Oct 2010 19:37:51 +0000 Subject: [PATCH] Handle parameterized types in invocation services and receivers. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6232 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/client/InvocationDecoder.java | 9 +++++++++ .../threerings/presents/server/InvocationDispatcher.java | 9 +++++++++ src/main/java/com/threerings/presents/tools/GenUtil.java | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/threerings/presents/client/InvocationDecoder.java b/src/main/java/com/threerings/presents/client/InvocationDecoder.java index 12d3e12dd..a19b291ac 100644 --- a/src/main/java/com/threerings/presents/client/InvocationDecoder.java +++ b/src/main/java/com/threerings/presents/client/InvocationDecoder.java @@ -45,4 +45,13 @@ public abstract class InvocationDecoder log.warning("Requested to dispatch unknown method", "receiver", receiver, "methodId", methodId, "args", args); } + + /** + * Performs type casts in a way that works for parameterized types as well as simple types. + */ + @SuppressWarnings("unchecked") + protected T cast (Object value) + { + return (T)value; + } } diff --git a/src/main/java/com/threerings/presents/server/InvocationDispatcher.java b/src/main/java/com/threerings/presents/server/InvocationDispatcher.java index 1c580fccc..02aa1d203 100644 --- a/src/main/java/com/threerings/presents/server/InvocationDispatcher.java +++ b/src/main/java/com/threerings/presents/server/InvocationDispatcher.java @@ -49,4 +49,13 @@ public abstract class InvocationDispatcher log.warning("Requested to dispatch unknown method", "provider", provider, "sourceOid", source.getOid(), "methodId", methodId, "args", args); } + + /** + * Performs type casts in a way that works for parameterized types as well as simple types. + */ + @SuppressWarnings("unchecked") + protected T cast (Object value) + { + return (T)value; + } } diff --git a/src/main/java/com/threerings/presents/tools/GenUtil.java b/src/main/java/com/threerings/presents/tools/GenUtil.java index 56f1bd3ce..7dca518d8 100644 --- a/src/main/java/com/threerings/presents/tools/GenUtil.java +++ b/src/main/java/com/threerings/presents/tools/GenUtil.java @@ -133,8 +133,10 @@ public class GenUtil extends com.samskivert.util.GenUtil return "((Double)" + name + ").doubleValue()"; } else if (Object.class.equals(type)) { return name; // no need to cast object - } else { + } else if (type instanceof Class) { return "(" + simpleName(type) + ")" + name; + } else { + return "this.<" + simpleName(type) + ">cast(" + name + ")"; } }