JSR-356 Promoting ReflectUtils to websocket-common

This commit is contained in:
Joakim Erdfelt 2013-07-16 10:43:27 -07:00
parent 05c5342752
commit fb00eb55cd
10 changed files with 41 additions and 11 deletions

View File

@ -27,8 +27,8 @@ import javax.websocket.MessageHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
import org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata;
import org.eclipse.jetty.websocket.jsr356.utils.ReflectUtils;
/**
* Factory for {@link MessageHandlerMetadata}

View File

@ -33,7 +33,7 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.events.annotated.AbstractMethodAnnotationScanner;
import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
import org.eclipse.jetty.websocket.jsr356.utils.ReflectUtils;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
public class AnnotatedEndpointScanner<T extends Annotation, C extends EndpointConfig> extends AbstractMethodAnnotationScanner<AnnotatedEndpointMetadata<T, C>>
{

View File

@ -24,10 +24,10 @@ import javax.websocket.Decoder;
import javax.websocket.Encoder;
import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
import org.eclipse.jetty.websocket.jsr356.EncoderFactory;
import org.eclipse.jetty.websocket.jsr356.InitException;
import org.eclipse.jetty.websocket.jsr356.JsrSession;
import org.eclipse.jetty.websocket.jsr356.utils.ReflectUtils;
public class OnMessageCallable extends JsrCallable
{

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.jsr356.annotations;
import org.eclipse.jetty.websocket.jsr356.utils.ReflectUtils;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
public class Param
{

View File

@ -25,8 +25,8 @@ import javax.websocket.Decoder;
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
import org.eclipse.jetty.websocket.jsr356.MessageType;
import org.eclipse.jetty.websocket.jsr356.utils.ReflectUtils;
public class DecoderMetadataSet extends CoderMetadataSet<Decoder, DecoderMetadata>
{

View File

@ -25,8 +25,8 @@ import javax.websocket.Encoder;
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
import org.eclipse.jetty.websocket.jsr356.MessageType;
import org.eclipse.jetty.websocket.jsr356.utils.ReflectUtils;
public class EncoderMetadataSet extends CoderMetadataSet<Encoder, EncoderMetadata>
{

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.jsr356.utils;
import static org.hamcrest.Matchers.*;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
import org.junit.Assert;
import org.junit.Test;

View File

@ -24,6 +24,8 @@ import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
public class TypeTree
{
public static void dumpTree(String indent, Type type)

View File

@ -25,6 +25,7 @@ import java.util.Objects;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
/**
* A Callable Method
@ -71,8 +72,31 @@ public class CallableMethod
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
String err = String.format("Cannot call method %s on %s with args: %s",method,pojo,args);
throw new WebSocketException(err,e);
StringBuilder err = new StringBuilder();
err.append("Cannot call method ");
err.append(ReflectUtils.toString(pojo,method));
err.append(" with args: [");
boolean delim = false;
for (Object arg : args)
{
if (delim)
{
err.append(", ");
}
if (arg == null)
{
err.append("<null>");
}
else
{
err.append(arg.getClass().getName());
}
delim = true;
}
err.append("]");
throw new WebSocketException(err.toString(),e);
}
}

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.jsr356.utils;
package org.eclipse.jetty.websocket.common.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@ -344,8 +344,7 @@ public class ReflectUtils
public static String toString(Class<?> pojo, Method method)
{
StringBuilder str = new StringBuilder();
str.append(pojo.getName());
str.append(" ");
// method modifiers
int mod = method.getModifiers() & Modifier.methodModifiers();
if (mod != 0)
@ -357,6 +356,10 @@ public class ReflectUtils
Type retType = method.getGenericReturnType();
appendTypeName(str,retType,false).append(' ');
// class name
str.append(pojo.getName());
str.append("#");
// method name
str.append(method.getName());