@Override public ISlot create(Object owner, Type ownerType, String name) { String addMethodName = GroovyRuntimeUtil.propertyToMethodName("add", name); MetaMethod addMethod = GroovyRuntimeUtil.getMetaClass(owner).pickMethod(addMethodName, new Class[]{Object.class}); return addMethod != null ? new SetterLikeSlot(owner, ownerType, addMethod) : null; } }
@Override public Object invokeMethod(String name, Object args) { try { return GroovyRuntimeUtil.invokeMethod($delegate, name, GroovyRuntimeUtil.asArgumentArray(args)); } catch (MissingMethodException e) { return super.invokeMethod(name, args); } } }
public IterableResponseGenerator(Object iterable) { iterator = GroovyRuntimeUtil.asIterator(iterable); }
Object[] normalizedArgs = GroovyRuntimeUtil.asUnwrappedArgumentArray(arguments); String methodName = GroovyRuntimeUtil.propertyToMethodName("set", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName, GroovyRuntimeUtil.asArgumentArray(normalizedArgs[1]));
@Override public ISlot create(Object owner, Type ownerType, String name) { MetaProperty property = GroovyRuntimeUtil.getMetaClass(owner).getMetaProperty(name); return property != null && MopUtil.isWriteable(property) ? new PropertySlot(owner, ownerType, property) : null; } }
String currPart = exprParts[i]; if (currPart.endsWith("()")) { result = GroovyRuntimeUtil.invokeMethod(result, currPart.substring(0, currPart.length() - 2)); } else { result = GroovyRuntimeUtil.getProperty(result, currPart); return GroovyRuntimeUtil.toString(result); } catch (Exception e) { if (assertUnrollExpressions) {
private Object doInvokeMethod(Object target, String methodName, Object[] arguments, boolean isStatic) { arguments = GroovyRuntimeUtil.asUnwrappedArgumentArray(arguments); Method method = GroovyRuntimeUtil.toMethod(metaMethod); return invokeMethod(target, (String) arguments[0], GroovyRuntimeUtil.asArgumentArray(arguments[1]));
@Override public Object create(IMockConfiguration configuration, Specification specification) throws CannotCreateMockException { final MetaClass oldMetaClass = GroovyRuntimeUtil.getMetaClass(configuration.getType()); GroovyMockMetaClass newMetaClass = new GroovyMockMetaClass(configuration, specification, oldMetaClass); final Class<?> type = configuration.getType(); ". Global cannot add additionalInterfaces."); GroovyRuntimeUtil.setMetaClass(type, newMetaClass); specification.getSpecificationContext().getCurrentIteration().addCleanup(new Runnable() { @Override GroovyRuntimeUtil.setMetaClass(instance, newMetaClass);
@Override public Object getProperty(String name) { return GroovyRuntimeUtil.getProperty(pojo, name); }
@SafeVarargs public static <T> T coerce(Object obj, Class<? extends T>... types) { if (types.length == 0) { throw new IllegalArgumentException("caller must provide at least one target type"); } GroovyCastException lastException = null; for (Class<? extends T> type : types) { try { return GroovyRuntimeUtil.coerce(obj, type); } catch (GroovyCastException e) { lastException = e; } } throw lastException; }
public static List<Object> asArgumentList(Object args) { // there may be a better impl than this (maybe on some Groovy class) return Arrays.asList(GroovyRuntimeUtil.asArgumentArray(args)); }
public static Object[] despreadList(Object[] args, Object[] spreads, int[] positions) { return GroovyRuntimeUtil.despreadList(args, spreads, positions); }
/** * Checks if the given method is a getter method according * to Groovy rules. If yes, the corresponding property name * is returned. Otherwise, null is returned. * This method differs from Groovy 1.6.8 in that the latter * doesn't support the "is" prefix for static boolean properties; * however, that seems more like a bug. * See http://jira.codehaus.org/browse/GROOVY-4206 */ @Nullable public static String getterMethodToPropertyName(String methodName, List<Class<?>> parameterTypes, Class<?> returnType) { if (!parameterTypes.isEmpty()) return null; if (returnType == void.class) return null; // Void.class is allowed if (methodName.startsWith("get")) return getPropertyName(methodName, 3); if (methodName.startsWith("is") && returnType == boolean.class) // Boolean.class is not allowed return getPropertyName(methodName, 2); return null; }
@Override public boolean isSatisfiedBy(Object arg) { if (HamcrestFacade.isMatcher(expected)) { return HamcrestFacade.matches(expected, arg); } return GroovyRuntimeUtil.equals(arg, expected); }
protected String getPropertyName(IMockInvocation invocation) { IMockMethod method = invocation.getMethod(); return GroovyRuntimeUtil.getterMethodToPropertyName( method.getName(), method.getParameterTypes(), method.getReturnType()); } }
Object[] normalizedArgs = GroovyRuntimeUtil.asUnwrappedArgumentArray(arguments); return GroovyRuntimeUtil.invokeMethod(target, (String) normalizedArgs[0], GroovyRuntimeUtil.asArgumentArray(normalizedArgs[1])); String methodName = GroovyRuntimeUtil.propertyToMethodName("get", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName); String methodName = GroovyRuntimeUtil.propertyToMethodName("set", (String) normalizedArgs[0]); return GroovyRuntimeUtil.invokeMethod(target, methodName, normalizedArgs[1]);
@Override public ISlot create(Object owner, Type ownerType, String name) { String plural = toPluralForm(name); MetaProperty property = GroovyRuntimeUtil.getMetaClass(owner).getMetaProperty(plural); return property != null && Collection.class.isAssignableFrom(property.getType()) && MopUtil.isReadable(property) ? new CollectionSlot(plural, owner, ownerType, property) : null; }
@Override public Object getProperty(String property) { try { return GroovyRuntimeUtil.getProperty($delegate, property); } catch (MissingPropertyException e) { return super.getProperty(property); } }
@Override public Object respond(IMockInvocation invocation) { if (iterator.hasNext()) nextValue = iterator.next(); return GroovyRuntimeUtil.coerce(nextValue, invocation.getMethod().getReturnType()); } }
@Override public void write(Object value) { setterLikeMethod.doMethodInvoke(owner, GroovyRuntimeUtil.asArgumentArray(value)); } }