📄 scriptbytecodeadapter.java
字号:
} public static Object convertToPrimitiveArray(Object a, Class type) throws Throwable { try { return InvokerHelper.convertToPrimitiveArray(a,type); } catch (GroovyRuntimeException gre) { return unwrap(gre); } } public static boolean compareIdentical(Object left, Object right) { return left == right; } public static boolean compareEqual(Object left, Object right) throws Throwable{ try { return InvokerHelper.compareEqual(left, right); } catch (GroovyRuntimeException gre) { unwrap(gre); // return never reached return false; } } public static boolean compareNotEqual(Object left, Object right) throws Throwable{ return !compareEqual(left, right); } public static Integer compareTo(Object left, Object right) throws Throwable{ try { return InvokerHelper.compareTo(left, right); } catch (GroovyRuntimeException gre) { return (Integer) unwrap(gre); } } public static Matcher findRegex(Object left, Object right) throws Throwable{ try { return InvokerHelper.findRegex(left, right); } catch (GroovyRuntimeException gre) { return (Matcher) unwrap(gre); } } public static boolean matchRegex(Object left, Object right) throws Throwable{ try { return InvokerHelper.matchRegex(left, right); } catch (GroovyRuntimeException gre) { unwrap(gre); // return never reached return false; } } public static boolean compareLessThan(Object left, Object right) throws Throwable{ return compareTo(left, right).intValue() < 0; } public static boolean compareLessThanEqual(Object left, Object right) throws Throwable{ return compareTo(left, right).intValue() <= 0; } public static boolean compareGreaterThan(Object left, Object right) throws Throwable{ return compareTo(left, right).intValue() > 0; } public static boolean compareGreaterThanEqual(Object left, Object right) throws Throwable{ return compareTo(left, right).intValue() >= 0; } public static boolean isCase(Object switchValue, Object caseExpression) throws Throwable{ if (caseExpression == null) { return switchValue == null; } return asBool(invokeMethod(caseExpression, "isCase", new Object[]{switchValue})); } public static Tuple createTuple(Object[] array) throws Throwable{ return new Tuple(array); } public static List createList(Object[] values) throws Throwable{ return InvokerHelper.createList(values); } public static Map createMap(Object[] values) throws Throwable{ return InvokerHelper.createMap(values); } public static List createRange(Object from, Object to, boolean inclusive) throws Throwable{ try { return InvokerHelper.createRange(from,to,inclusive); } catch (GroovyRuntimeException gre) { return (List) unwrap(gre); } } public static void assertFailed(Object expression, Object message) { InvokerHelper.assertFailed(expression,message); } public static Object box(boolean value) { return value ? Boolean.TRUE : Boolean.FALSE; } public static Object box(byte value) { return new Byte(value); } public static Object box(char value) { return new Character(value); } public static Object box(short value) { return new Short(value); } public static Object box(int value) { return integerValue(value); } public static Object box(long value) { return new Long(value); } public static Object box(float value) { return new Float(value); } public static Object box(double value) { return new Double(value); } /** * get the Integer object from an int. Cached version is used for small ints. * * @param v * @return */ public static Integer integerValue(int v) { return InvokerHelper.integerValue(v); } public static byte byteUnbox(Object value) throws Throwable { Number n = (Number) asType(value, Byte.class); return n.byteValue(); } public static char charUnbox(Object value) throws Throwable { Character n = (Character) asType(value, Character.class); return n.charValue(); } public static short shortUnbox(Object value) throws Throwable { Number n = (Number) asType(value, Short.class); return n.shortValue(); } public static int intUnbox(Object value) throws Throwable { Number n = (Number) asType(value, Integer.class); return n.intValue(); } public static boolean booleanUnbox(Object value) throws Throwable { Boolean n = (Boolean) asType(value, Boolean.class); return n.booleanValue(); } public static long longUnbox(Object value) throws Throwable { Number n = (Number) asType(value, Long.class); return n.longValue(); } public static float floatUnbox(Object value) throws Throwable { Number n = (Number) asType(value, Float.class); return n.floatValue(); } public static double doubleUnbox(Object value) throws Throwable { Number n = (Number) asType(value, Double.class); return n.doubleValue(); } public static MetaClass getMetaClass(Object object) { return InvokerHelper.getMetaClass(object); } /* public static void removeClass(Class clazz) { getInstance().removeMetaClass(clazz); Introspector.flushFromCaches(clazz); } public static Invoker getInstance() { return singleton; } public static Collection asCollection(Object collection) { return getInstance().asCollection(collection); } public static List asList(Object args) { return getInstance().asList(args); } public static String toString(Object arguments) { return getInstance().toString(arguments); } public static String toTypeString(Object[] arguments) { return getInstance().toTypeString(arguments); } public static String inspect(Object self) { return getInstance().inspect(self); } public static Object runScript(Class scriptClass, String[] args) { Binding context = new Binding(args); Script script = createScript(scriptClass, context); return invokeMethod(script, "run", EMPTY_ARGS); } public static Script createScript(Class scriptClass, Binding context) { try { final GroovyObject object = (GroovyObject) scriptClass.newInstance(); Script script = null; if (object instanceof Script) { script = (Script) object; } else { // it could just be a class, so lets wrap it in a Script wrapper // though the bindings will be ignored script = new Script() { public Object run() { object.invokeMethod("main", EMPTY_MAIN_ARGS); return null; } }; setProperties(object, context.getVariables()); } script.setBinding(context); return script; } catch (Exception e) { throw new GroovyRuntimeException("Failed to create Script instance for class: " + scriptClass + ". Reason: " + e, e); } }*/ /** * Sets the properties on the given object * * @param object * @param map *//* public static void setProperties(Object object, Map map) { getMetaClass(object).setProperties(object, map); } public static String getVersion() { String version = null; Package p = Package.getPackage("groovy.lang"); if (p != null) { version = p.getImplementationVersion(); } if (version == null) { version = ""; } return version; }*/ /** * Allows conversion of arrays into a mutable List * * @return the array as a List */ /*protected static List primitiveArrayToList(Object array) { int size = Array.getLength(array); List list = new ArrayList(size); for (int i = 0; i < size; i++) { list.add(Array.get(array, i)); } return list; }*/ /** * Writes the given object to the given stream *//* public static void write(Writer out, Object object) throws IOException { if (object instanceof String) { out.write((String) object); } else if (object instanceof Writable) { Writable writable = (Writable) object; writable.writeTo(out); } else if (object instanceof InputStream || object instanceof Reader) { // Copy stream to stream Reader reader; if (object instanceof InputStream) { reader = new InputStreamReader((InputStream) object); } else { reader = (Reader) object; } char[] chars = new char[8192]; int i; while ((i = reader.read(chars)) != -1) { out.write(chars, 0, i); } reader.close(); } else { out.write(toString(object)); } } public static int[] convertToIntArray(Object a) { int[] ans = null; // conservative coding if (a.getClass().getName().equals("[I")) { ans = (int[]) a; } else { Object[] ia = (Object[]) a; ans = new int[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Number) ia[i]).intValue(); } } return ans; } public static boolean[] convertToBooleanArray(Object a) { boolean[] ans = null; // conservative coding if (a.getClass().getName().equals("[Z")) { ans = (boolean[]) a; } else { Object[] ia = (Object[]) a; ans = new boolean[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Boolean) ia[i]).booleanValue(); } } return ans; } public static byte[] convertToByteArray(Object a) { byte[] ans = null; // conservative coding if (a.getClass().getName().equals("[B")) { ans = (byte[]) a; } else { Object[] ia = (Object[]) a; ans = new byte[ia.length]; for (int i = 0; i < ia.length; i++) { if (ia[i] != null) ans[i] = ((Number) ia[i]).byteValue(); } } return ans; } public static short[] convertToShortArray(Object a) { short[] ans = null; // conservative coding if (a.getClass().getName().equals("[S")) { ans = (short[]) a; } else { Object[] ia = (Object[]) a; ans = new short[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Number) ia[i]).shortValue(); } } return ans; } public static char[] convertToCharArray(Object a) { char[] ans = null; // conservative coding if (a.getClass().getName().equals("[C")) { ans = (char[]) a; } else { Object[] ia = (Object[]) a; ans = new char[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Character) ia[i]).charValue(); } } return ans; } public static long[] convertToLongArray(Object a) { long[] ans = null; // conservative coding if (a.getClass().getName().equals("[J")) { ans = (long[]) a; } else { Object[] ia = (Object[]) a; ans = new long[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Number) ia[i]).longValue(); } } return ans; } public static float[] convertToFloatArray(Object a) { float[] ans = null; // conservative coding if (a.getClass().getName().equals("[F")) { ans = (float[]) a; } else { Object[] ia = (Object[]) a; ans = new float[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Number) ia[i]).floatValue(); } } return ans; } public static double[] convertToDoubleArray(Object a) { double[] ans = null; // conservative coding if (a.getClass().getName().equals("[D")) { ans = (double[]) a; } else { Object[] ia = (Object[]) a; ans = new double[ia.length]; for (int i = 0; i < ia.length; i++) { ans[i] = ((Number) ia[i]).doubleValue(); } } return ans; }*/ /* private static Integer[] SMALL_INTEGERS; private static int INT_CACHE_OFFSET = 128, INT_CACHE_LEN = 256; static { SMALL_INTEGERS = new Integer[INT_CACHE_LEN]; for (int i = 0; i < SMALL_INTEGERS.length; i++) { SMALL_INTEGERS[i] = new Integer(i - INT_CACHE_OFFSET); } }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -