/** * Returns {@link NullObject#getNullObject()} if the receiver * (args[0]) is null. If it is not null, the recevier itself * is returned. */ public Object getCorrectedReceiver() { Object receiver = args[0]; if (receiver==null) { if (LOG_ENABLED) LOG.info("receiver is null"); receiver = NullObject.getNullObject(); } return receiver; }
/** * Gives the meta class to an Object. */ public void getMetaClass() { Object receiver = args[0]; if (receiver == null) { mc = NullObject.getNullObject().getMetaClass(); } else if (receiver instanceof GroovyObject) { mc = ((GroovyObject) receiver).getMetaClass(); } else if (receiver instanceof Class) { Class c = (Class) receiver; ClassLoader cl = c.getClassLoader(); try { Class.forName(c.getName(), true, cl); } catch (ClassNotFoundException e) {} mc = GroovySystem.getMetaClassRegistry().getMetaClass(c); this.cache &= !ClassInfo.getClassInfo(c).hasPerInstanceMetaClasses(); } else { mc = ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(receiver); this.cache &= !ClassInfo.getClassInfo(receiver.getClass()).hasPerInstanceMetaClasses(); } mc.initialize(); }
/** * Sets the metaclass for a given class. * * @param self the class whose metaclass we wish to set * @param metaClass the new MetaClass * @since 1.6.0 */ public static void setMetaClass(Class self, MetaClass metaClass) { final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry(); if (metaClass == null) metaClassRegistry.removeMetaClass(self); else { if (metaClass instanceof HandleMetaClass) { metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee()); } else { metaClassRegistry.setMetaClass(self, metaClass); } if (self==NullObject.class) { NullObject.getNullObject().setMetaClass(metaClass); } } }
/** * Allows to add a String to null. * The result is concatenated String of the result of calling * toString() on this object and the String in the parameter. * * @param s - the String to concatenate * @return the concatenated string */ public Object plus(String s) { return getMetaClass().invokeMethod(this, "toString", new Object[]{}) + s; }
return ((NullObject)delegate).asType(clazz);
/** * Allows to add a String to null. * The result is concatenated String of the result of calling * toString() on this object and the String in the parameter. * * @param s - the String to concatenate * @return the concatenated string */ public Object plus(String s) { return getMetaClass().invokeMethod(this, "toString", new Object[]{}) + s; }
/** * Provides a hook for type coercion of the given object to the required type * * @param type of object to convert the given object to * @param object the object to be converted * @return the original object or a new converted value * @throws Throwable if the coercion fails */ public static Object asType(Object object, Class type) throws Throwable { if (object == null) object = NullObject.getNullObject(); return invokeMethodN(object.getClass(), object, "asType", new Object[]{type}); }
public static String format(Object arguments, boolean verbose, int maxSize, boolean safe) { if (arguments == null) { final NullObject nullObject = NullObject.getNullObject(); return (String) nullObject.getMetaClass().invokeMethod(nullObject, "toString", EMPTY_ARGS);
/** * Sets the metaclass for a given class. * * @param self the class whose metaclass we wish to set * @param metaClass the new MetaClass * @since 1.6.0 */ public static void setMetaClass(Class self, MetaClass metaClass) { final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry(); if (metaClass == null) metaClassRegistry.removeMetaClass(self); else { if (metaClass instanceof HandleMetaClass) { metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee()); } else { metaClassRegistry.setMetaClass(self, metaClass); } if (self==NullObject.class) { NullObject.getNullObject().setMetaClass(metaClass); } } }
/** * Allows to add a String to null. * The result is concatenated String of the result of calling * toString() on this object and the String in the parameter. * * @param s - the String to concatenate * @return the concatenated string */ public Object plus(String s) { return getMetaClass().invokeMethod(this, "toString", new Object[]{}) + s; }
public static void setProperty(Object messageArgument, Class senderClass, Object receiver, String messageName) throws Throwable { try { if (receiver==null) receiver=NullObject.getNullObject(); InvokerHelper.setProperty(receiver, messageName, messageArgument); } catch (GroovyRuntimeException gre) { throw unwrap(gre); } }
protected static String format(Object arguments, boolean verbose) { if (arguments == null) { final NullObject nullObject = NullObject.getNullObject(); return (String) nullObject.getMetaClass().invokeMethod(nullObject, "toString", EMPTY_ARGS);
/** * Sets the metaclass for a given class. * * @param self the class whose metaclass we wish to set * @param metaClass the new MetaClass * @since 1.6.0 */ public static void setMetaClass(Class self, MetaClass metaClass) { final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry(); if (metaClass == null) metaClassRegistry.removeMetaClass(self); else { if (metaClass instanceof HandleMetaClass) { metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee()); } else { metaClassRegistry.setMetaClass(self, metaClass); } if (self==NullObject.class) { NullObject.getNullObject().setMetaClass(metaClass); } } }
/** * Allows to add a String to null. * The result is concatenated String of the result of calling * toString() on this object and the String in the parameter. * * @param s - the String to concatenate * @return the concatenated string */ public Object plus(String s) { return getMetaClass().invokeMethod(this, "toString", new Object[]{}) + s; }
public static Object getProperty(Object object, String property) { if (object == null) { object = NullObject.getNullObject(); } if (object instanceof GroovyObject) { GroovyObject pogo = (GroovyObject) object; return pogo.getProperty(property); } else if (object instanceof Class) { Class c = (Class) object; return metaRegistry.getMetaClass(c).getProperty(object, property); } else { return ((MetaClassRegistryImpl) metaRegistry).getMetaClass(object).getProperty(object, property); } }
protected static String format(Object arguments, boolean verbose) { if (arguments == null) { final NullObject nullObject = NullObject.getNullObject(); return (String) nullObject.getMetaClass().invokeMethod(nullObject, "toString", EMPTY_ARGS);
/** * Allows to add a String to null. * The result is concatenated String of the result of calling * toString() on this object and the String in the parameter. * * @param s - the String to concatenate * @return the concatenated string */ public Object plus(String s) { return getMetaClass().invokeMethod(this, "toString", new Object[]{}) + s; }
/** * Gives a replacement receiver for null. * In case of the receiver being null we want to do the method * invocation on NullObject instead. */ public void correctNullReceiver() { if (args[0]!=null) return; handle = handle.bindTo(NullObject.getNullObject()); handle = MethodHandles.dropArguments(handle, 0, targetType.parameterType(0)); if (LOG_ENABLED) LOG.info("binding null object receiver and dropping old receiver"); }
public static String format(Object arguments, boolean verbose, int maxSize) { if (arguments == null) { final NullObject nullObject = NullObject.getNullObject(); return (String) nullObject.getMetaClass().invokeMethod(nullObject, "toString", EMPTY_ARGS);
public static void setProperty(Object object, String property, Object newValue) { if (object == null) { object = NullObject.getNullObject(); } if (object instanceof GroovyObject) { GroovyObject pogo = (GroovyObject) object; pogo.setProperty(property, newValue); } else if (object instanceof Class) { metaRegistry.getMetaClass((Class) object).setProperty((Class) object, property, newValue); } else { ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue); } }