Archiviert
13
0

Remove PrimitiveUtils - it's already present in Bukkit's Guava library.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-10-29 22:15:25 +01:00
Ursprung d54cc35445
Commit ae08abe821
7 geänderte Dateien mit 13 neuen und 139 gelöschten Zeilen

Datei anzeigen

@ -4,7 +4,7 @@
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<name>ProtocolLib</name> <name>ProtocolLib</name>
<version>1.5.0</version> <version>1.5.1-SNAPSHOT</version>
<description>Provides read/write access to the Minecraft protocol.</description> <description>Provides read/write access to the Minecraft protocol.</description>
<url>http://dev.bukkit.org/server-mods/protocollib/</url> <url>http://dev.bukkit.org/server-mods/protocollib/</url>
<developers> <developers>

Datei anzeigen

@ -14,7 +14,6 @@ import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.MethodUtils; import com.comphenix.protocol.reflect.MethodUtils;
import com.comphenix.protocol.reflect.ObjectCloner; import com.comphenix.protocol.reflect.ObjectCloner;
import com.comphenix.protocol.reflect.PrimitiveUtils;
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler; import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
import com.comphenix.protocol.reflect.compiler.StructureCompiler; import com.comphenix.protocol.reflect.compiler.StructureCompiler;
import com.comphenix.protocol.reflect.instances.CollectionGenerator; import com.comphenix.protocol.reflect.instances.CollectionGenerator;
@ -46,8 +45,7 @@ class CleanupStaticMembers {
BukkitUnwrapper.class, DefaultInstances.class, CollectionGenerator.class, BukkitUnwrapper.class, DefaultInstances.class, CollectionGenerator.class,
PrimitiveGenerator.class, FuzzyReflection.class, MethodUtils.class, PrimitiveGenerator.class, FuzzyReflection.class, MethodUtils.class,
BackgroundCompiler.class, StructureCompiler.class, BackgroundCompiler.class, StructureCompiler.class,
ObjectCloner.class, PrimitiveUtils.class, Packets.Server.class, ObjectCloner.class, Packets.Server.class, Packets.Client.class
Packets.Client.class
}; };
String[] internalClasses = { String[] internalClasses = {

Datei anzeigen

@ -25,9 +25,9 @@ import net.minecraft.server.Packet;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.PrimitiveUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.primitives.Primitives;
/** /**
* A packet constructor that uses an internal Minecraft. * A packet constructor that uses an internal Minecraft.
@ -181,9 +181,9 @@ public class PacketConstructor {
Class<?> paramType = params[i]; Class<?> paramType = params[i];
// The input type is always wrapped // The input type is always wrapped
if (PrimitiveUtils.isPrimitive(paramType)) { if (paramType.isPrimitive()) {
// Wrap it // Wrap it
paramType = PrimitiveUtils.wrap(paramType); paramType = Primitives.wrap(paramType);
} }
// Compare assignability // Compare assignability

Datei anzeigen

@ -1,124 +0,0 @@
package com.comphenix.protocol.reflect;
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Contains static utility methods pertaining to primitive types and their
* corresponding wrapper types.
*
* @author Kevin Bourrillion
*/
public final class PrimitiveUtils {
private PrimitiveUtils() {
}
/** A map from primitive types to their corresponding wrapper types. */
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE;
/** A map from wrapper types to their corresponding primitive types. */
private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE;
// Sad that we can't use a BiMap. :(
static {
Map<Class<?>, Class<?>> primToWrap = new HashMap<Class<?>, Class<?>>(16);
Map<Class<?>, Class<?>> wrapToPrim = new HashMap<Class<?>, Class<?>>(16);
add(primToWrap, wrapToPrim, boolean.class, Boolean.class);
add(primToWrap, wrapToPrim, byte.class, Byte.class);
add(primToWrap, wrapToPrim, char.class, Character.class);
add(primToWrap, wrapToPrim, double.class, Double.class);
add(primToWrap, wrapToPrim, float.class, Float.class);
add(primToWrap, wrapToPrim, int.class, Integer.class);
add(primToWrap, wrapToPrim, long.class, Long.class);
add(primToWrap, wrapToPrim, short.class, Short.class);
add(primToWrap, wrapToPrim, void.class, Void.class);
PRIMITIVE_TO_WRAPPER_TYPE = Collections.unmodifiableMap(primToWrap);
WRAPPER_TO_PRIMITIVE_TYPE = Collections.unmodifiableMap(wrapToPrim);
}
private static void add(Map<Class<?>, Class<?>> forward,
Map<Class<?>, Class<?>> backward, Class<?> key, Class<?> value) {
forward.put(key, value);
backward.put(value, key);
}
/**
* Returns true if this type is a primitive.
*/
public static boolean isPrimitive(Type type) {
return PRIMITIVE_TO_WRAPPER_TYPE.containsKey(type);
}
/**
* Returns {@code true} if {@code type} is one of the nine primitive-wrapper
* types, such as {@link Integer}.
*
* @see Class#isPrimitive
*/
public static boolean isWrapperType(Type type) {
return WRAPPER_TO_PRIMITIVE_TYPE.containsKey(checkNotNull(type));
}
/**
* Returns the corresponding wrapper type of {@code type} if it is a
* primitive type; otherwise returns {@code type} itself. Idempotent.
*
* <pre>
* wrap(int.class) == Integer.class
* wrap(Integer.class) == Integer.class
* wrap(String.class) == String.class
* </pre>
*/
public static <T> Class<T> wrap(Class<T> type) {
// cast is safe: long.class and Long.class are both of type Class<Long>
@SuppressWarnings("unchecked")
Class<T> wrapped = (Class<T>) PRIMITIVE_TO_WRAPPER_TYPE
.get(checkNotNull(type));
return (wrapped == null) ? type : wrapped;
}
/**
* Returns the corresponding primitive type of {@code type} if it is a
* wrapper type; otherwise returns {@code type} itself. Idempotent.
*
* <pre>
* unwrap(Integer.class) == int.class
* unwrap(int.class) == int.class
* unwrap(String.class) == String.class
* </pre>
*/
public static <T> Class<T> unwrap(Class<T> type) {
// cast is safe: long.class and Long.class are both of type Class<Long>
@SuppressWarnings("unchecked")
Class<T> unwrapped = (Class<T>) WRAPPER_TO_PRIMITIVE_TYPE
.get(checkNotNull(type));
return (unwrapped == null) ? type : unwrapped;
}
public static <T> T checkNotNull(T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
}

Datei anzeigen

@ -426,7 +426,7 @@ public class StructureModifier<TField> {
Class<?> type = field.getType(); Class<?> type = field.getType();
// First, ignore primitive fields // First, ignore primitive fields
if (!PrimitiveUtils.isPrimitive(type)) { if (!type.isPrimitive()) {
// Next, see if we actually can generate a default value // Next, see if we actually can generate a default value
if (generator.getDefault(type) != null) { if (generator.getDefault(type) != null) {
// If so, require it // If so, require it

Datei anzeigen

@ -25,9 +25,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.comphenix.protocol.reflect.PrimitiveUtils;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.primitives.Primitives;
import net.sf.cglib.asm.*; import net.sf.cglib.asm.*;
@ -306,7 +306,7 @@ public final class StructureCompiler {
for (int i = 0; i < fields.size(); i++) { for (int i = 0; i < fields.size(); i++) {
Class<?> outputType = fields.get(i).getType(); Class<?> outputType = fields.get(i).getType();
Class<?> inputType = PrimitiveUtils.wrap(outputType); Class<?> inputType = Primitives.wrap(outputType);
String typeDescriptor = Type.getDescriptor(outputType); String typeDescriptor = Type.getDescriptor(outputType);
String inputPath = inputType.getName().replace('.', '/'); String inputPath = inputType.getName().replace('.', '/');
@ -323,7 +323,7 @@ public final class StructureCompiler {
mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ALOAD, 3);
mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitVarInsn(Opcodes.ALOAD, 2);
if (!PrimitiveUtils.isPrimitive(outputType)) if (!outputType.isPrimitive())
mv.visitTypeInsn(Opcodes.CHECKCAST, inputPath); mv.visitTypeInsn(Opcodes.CHECKCAST, inputPath);
else else
boxingHelper.unbox(Type.getType(outputType)); boxingHelper.unbox(Type.getType(outputType));

Datei anzeigen

@ -21,8 +21,8 @@ import java.lang.reflect.Array;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.comphenix.protocol.reflect.PrimitiveUtils;
import com.google.common.base.Defaults; import com.google.common.base.Defaults;
import com.google.common.primitives.Primitives;
/** /**
* Provides constructors for primtive types, wrappers, arrays and strings. * Provides constructors for primtive types, wrappers, arrays and strings.
@ -58,10 +58,10 @@ public class PrimitiveGenerator implements InstanceProvider {
@Override @Override
public Object create(@Nullable Class<?> type) { public Object create(@Nullable Class<?> type) {
if (PrimitiveUtils.isPrimitive(type)) { if (type.isPrimitive()) {
return Defaults.defaultValue(type); return Defaults.defaultValue(type);
} else if (PrimitiveUtils.isWrapperType(type)) { } else if (Primitives.isWrapperType(type)) {
return Defaults.defaultValue(PrimitiveUtils.unwrap(type)); return Defaults.defaultValue(Primitives.unwrap(type));
} else if (type.isArray()) { } else if (type.isArray()) {
Class<?> arrayType = type.getComponentType(); Class<?> arrayType = type.getComponentType();
return Array.newInstance(arrayType, 0); return Array.newInstance(arrayType, 0);