Skip to content

Commit

Permalink
Use StringUtil.simpleClassName(..) instead of Class.getSimpleName() w…
Browse files Browse the repository at this point in the history
…here necessary

- Class.getSimpleName() doesn't render anonymous classes very well
- + some minor cleanup
  • Loading branch information
trustin committed Nov 4, 2013
1 parent 0d1567d commit 54db9ec
Show file tree
Hide file tree
Showing 34 changed files with 64 additions and 44 deletions.
5 changes: 3 additions & 2 deletions buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -1086,11 +1087,11 @@ public int compareTo(ByteBuf that) {
@Override
public String toString() {
if (refCnt() == 0) {
return getClass().getSimpleName() + "(freed)";
return StringUtil.simpleClassName(this) + "(freed)";
}

StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(ridx: ");
buf.append(readerIndex);
buf.append(", widx: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.buffer;

import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.StringUtil;

/**
* Default implementation of a {@link ByteBufHolder} that holds it's data in a {@link ByteBuf}.
Expand Down Expand Up @@ -79,6 +80,6 @@ public boolean release(int decrement) {

@Override
public String toString() {
return getClass().getSimpleName() + '(' + content().toString() + ')';
return StringUtil.simpleClassName(this) + '(' + content().toString() + ')';
}
}
3 changes: 2 additions & 1 deletion buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;

import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -64,7 +65,7 @@ private EmptyByteBuf(ByteBufAllocator alloc, ByteOrder order) {

this.alloc = alloc;
this.order = order;
str = getClass().getSimpleName() + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE");
str = StringUtil.simpleClassName(this) + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.buffer;

import io.netty.util.ResourceLeak;
import io.netty.util.internal.StringUtil;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -40,7 +41,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
public ReadOnlyByteBufferBuf(ByteBufAllocator allocator, ByteBuffer buffer) {
super(buffer.remaining());
if (!buffer.isReadOnly()) {
throw new IllegalArgumentException("must be a readonly buffer: " + buffer.getClass().getSimpleName());
throw new IllegalArgumentException("must be a readonly buffer: " + StringUtil.simpleClassName(buffer));
}

this.allocator = allocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.handler.codec.http;

import io.netty.buffer.ByteBuf;
import io.netty.util.internal.StringUtil;

/**
* The default {@link HttpContent} implementation.
Expand Down Expand Up @@ -78,6 +79,6 @@ public boolean release(int decrement) {

@Override
public String toString() {
return getClass().getSimpleName() + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')';
return StringUtil.simpleClassName(this) + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public HttpVersion getProtocolVersion() {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(version: ");
buf.append(getProtocolVersion().text());
buf.append(", keepAlive: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public HttpRequest setProtocolVersion(HttpVersion version) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append(", decodeResult: ");
buf.append(getDecoderResult());
buf.append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public HttpResponse setProtocolVersion(HttpVersion version) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(decodeResult: ");
buf.append(getDecoderResult());
buf.append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.channel.FileRegion;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -60,7 +61,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
if (msg instanceof HttpMessage) {
if (state != ST_INIT) {
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName());
throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
}

@SuppressWarnings({ "unchecked", "CastConflictsWithInstanceof" })
Expand All @@ -76,7 +77,7 @@ protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) t
}
if (msg instanceof HttpContent || msg instanceof ByteBuf || msg instanceof FileRegion) {
if (state == ST_INIT) {
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName());
throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
}

int contentLength = contentLength(msg);
Expand Down Expand Up @@ -148,7 +149,7 @@ private static Object encodeAndRetain(Object msg) {
if (msg instanceof FileRegion) {
return ((FileRegion) msg).retain();
}
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName());
throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
}

private static int contentLength(Object msg) {
Expand All @@ -161,7 +162,7 @@ private static int contentLength(Object msg) {
if (msg instanceof FileRegion) {
return (int) ((FileRegion) msg).count();
}
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName());
throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
}

private static void encodeHeaders(ByteBuf buf, HttpHeaders headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.util.internal.StringUtil;

/**
* Base class for web socket frames
Expand Down Expand Up @@ -67,7 +68,7 @@ public int rsv() {

@Override
public String toString() {
return getClass().getSimpleName() + "(data: " + content().toString() + ')';
return StringUtil.simpleClassName(this) + "(data: " + content().toString() + ')';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public boolean release(int decrement) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(last: ");
buf.append(isLast());
buf.append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public SpdyGoAwayFrame setStatus(SpdySessionStatus status) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE);
buf.append("--> Last-good-stream-ID = ");
buf.append(getLastGoodStreamId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public SpdyHeaders headers() {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(last: ");
buf.append(isLast());
buf.append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SpdyPingFrame setId(int id) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE);
buf.append("--> ID = ");
buf.append(getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public SpdyRstStreamFrame setStatus(SpdyStreamStatus status) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(getStreamId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void appendSettings(StringBuilder buf) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE);
appendSettings(buf);
buf.setLength(buf.length() - StringUtil.NEWLINE.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public SpdySynReplyFrame setInvalid() {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(last: ");
buf.append(isLast());
buf.append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public SpdySynStreamFrame setUnidirectional(boolean unidirectional) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append("(last: ");
buf.append(isLast());
buf.append("; unidirectional: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public SpdyWindowUpdateFrame setDeltaWindowSize(int deltaWindowSize) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(getStreamId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.netty.buffer.SwappedByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.Signal;
import io.netty.util.internal.StringUtil;

import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -788,7 +789,7 @@ public String toString(Charset charsetName) {

@Override
public String toString() {
return getClass().getSimpleName() + '(' +
return StringUtil.simpleClassName(this) + '(' +
"ridx=" +
readerIndex() +
", " +
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/io/netty/util/HashedWheelTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.util;

import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

Expand Down Expand Up @@ -541,7 +542,7 @@ public String toString() {
long remaining = deadline - currentTime + startTime;

StringBuilder buf = new StringBuilder(192);
buf.append(getClass().getSimpleName());
buf.append(StringUtil.simpleClassName(this));
buf.append('(');

buf.append("deadline: ");
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.netty.util;

import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
Expand Down Expand Up @@ -70,15 +71,15 @@ public static boolean isEnabled() {
private long leakCheckCnt;

public ResourceLeakDetector(Class<?> resourceType) {
this(resourceType.getSimpleName());
this(StringUtil.simpleClassName(resourceType));
}

public ResourceLeakDetector(String resourceType) {
this(resourceType, DEFAULT_SAMPLING_INTERVAL, Long.MAX_VALUE);
}

public ResourceLeakDetector(Class<?> resourceType, int samplingInterval, long maxActive) {
this(resourceType.getSimpleName(), samplingInterval, maxActive);
this(StringUtil.simpleClassName(resourceType), samplingInterval, maxActive);
}

public ResourceLeakDetector(String resourceType, int samplingInterval, long maxActive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.netty.util.internal.logging;

import io.netty.util.internal.StringUtil;

import java.io.ObjectStreamException;
import java.io.Serializable;

Expand Down Expand Up @@ -183,6 +185,6 @@ protected Object readResolve() throws ObjectStreamException {

@Override
public String toString() {
return getClass().getSimpleName() + '(' + name() + ')';
return StringUtil.simpleClassName(this) + '(' + name() + ')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;

import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -97,7 +98,7 @@ private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req)
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format(
"Channel %s received %s", ctx.channel().hashCode(), frame.getClass().getSimpleName()));
"Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame)));
}

if (frame instanceof CloseWebSocketFrame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.netty.testsuite.transport.sctp.SctpTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule;
Expand All @@ -37,7 +38,7 @@ public abstract class AbstractSctpTest {

private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
SctpTestPermutation.sctpChannel();
private static List<ByteBufAllocator> ALLOCATORS = SctpTestPermutation.allocator();
private static final List<ByteBufAllocator> ALLOCATORS = SctpTestPermutation.allocator();

@Rule
public final TestName testName = new TestName();
Expand Down Expand Up @@ -65,7 +66,7 @@ protected void run() throws Throwable {
cb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format(
"Running: %s %d of %d (%s + %s) with %s",
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator)));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected void run() throws Throwable {
cb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format(
"Running: %s %d of %d with %s",
testName.getMethodName(), ++ i, COMBO.size(), allocator.getClass().getSimpleName()));
testName.getMethodName(), ++ i, COMBO.size(), StringUtil.simpleClassName(allocator)));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), Bootstrap.class);
Expand Down
Loading

0 comments on commit 54db9ec

Please sign in to comment.