IDEA Auto Inspect

This commit is contained in:
Izzel_Aliz
2018-03-24 23:18:11 +08:00
parent 848b91f2e7
commit d4910db108
139 changed files with 1714 additions and 1814 deletions

View File

@@ -9,11 +9,7 @@ public class MethodsUtils {
public static boolean checkUser(String packagename, String current)
{
if (current.substring(0, 8).equals(packagename))
{
return true;
}
return false;
return current.substring(0, 8).equals(packagename);
}
@SuppressWarnings("rawtypes")
@@ -23,22 +19,14 @@ public class MethodsUtils {
{
throw new Error("未经允许的方法调用");
}
Class<? extends Object> clazz = classname.getClass();
Class<?> clazz = classname.getClass();
Method method = null;
try {
method = clazz.getDeclaredMethod(methodname, classes);
method.setAccessible(true);
return new Object[] { method.invoke(classname, objects) };
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
} catch (SecurityException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | IllegalArgumentException e) {
e.printStackTrace();
}
return null;
@@ -50,21 +38,15 @@ public class MethodsUtils {
{
throw new Error("未经允许的方法调用");
}
Class<? extends Object> clazz = classname.getClass();
Class<?> clazz = classname.getClass();
Field field = null;
Object object = null;
try {
field = clazz.getDeclaredField(fieldname);
field.setAccessible(true);
object = field.get(classname);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
e.printStackTrace();
}
return object;

View File

@@ -1,5 +1,7 @@
package me.skymc.taboolib.methods;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -7,8 +9,6 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
/**
* <b>ReflectionUtils</b>
* <p>
@@ -60,7 +60,6 @@ public final class ReflectionUtils {
* @return The constructor of the desired target class with the specified parameter types
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
* @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getConstructor(Class, Class...)
*/
public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
@@ -96,7 +95,6 @@ public final class ReflectionUtils {
* @throws InvocationTargetException If the desired constructor cannot be invoked
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #instantiateObject(Class, Object...)
*/
public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
@@ -135,7 +133,6 @@ public final class ReflectionUtils {
* @return The method of the desired target class with the specified name and parameter types
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getMethod(Class, String, Class...)
*/
public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
@@ -193,7 +190,6 @@ public final class ReflectionUtils {
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #invokeMethod(Object, Class, String, Object...)
*/
public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
@@ -380,7 +376,7 @@ public final class ReflectionUtils {
*
* @param path Path of the package
*/
private PackageType(String path) {
PackageType(String path) {
this.path = path;
}
@@ -390,7 +386,7 @@ public final class ReflectionUtils {
* @param parent Parent package of the package
* @param path Path of the package
*/
private PackageType(PackageType parent, String path) {
PackageType(PackageType parent, String path) {
this(parent + "." + path);
}
@@ -448,7 +444,7 @@ public final class ReflectionUtils {
DOUBLE(double.class, Double.class),
BOOLEAN(boolean.class, Boolean.class);
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<>();
private final Class<?> primitive;
private final Class<?> reference;
@@ -466,7 +462,7 @@ public final class ReflectionUtils {
* @param primitive Primitive class of this data type
* @param reference Reference class of this data type
*/
private DataType(Class<?> primitive, Class<?> reference) {
DataType(Class<?> primitive, Class<?> reference) {
this.primitive = primitive;
this.reference = reference;
}
@@ -554,7 +550,6 @@ public final class ReflectionUtils {
/**
* Returns the primitive class array of the given object array
*
* @param object Given object array
* @return The primitive class array
*/
public static Class<?>[] getPrimitive(Object[] objects) {
@@ -569,7 +564,6 @@ public final class ReflectionUtils {
/**
* Returns the reference class array of the given object array
*
* @param object Given object array
* @return The reference class array
*/
public static Class<?>[] getReference(Object[] objects) {