use of groovy.lang.MissingMethodException in project cucumber-jvm by cucumber.
the class GroovyWorld method findWorldWithMethod.
private GroovyObject findWorldWithMethod(String methodName, Object arguments) {
Object[] args = unwrapMethodArguments(arguments);
if (worlds.isEmpty()) {
throw new MissingMethodException(methodName, this.getClass(), args);
}
if (worlds.size() == 1) {
return worlds.get(0);
}
GroovyObject worldWithMethod = null;
for (GroovyObject world : worlds) {
if (world.getMetaClass().getMetaMethod(methodName, args) != null) {
if (worldWithMethod == null) {
worldWithMethod = world;
} else {
throw new RuntimeException("Multiple method call: " + methodName);
}
}
}
if (worldWithMethod == null) {
throw new MissingMethodException(methodName, this.getClass(), args);
}
return worldWithMethod;
}
use of groovy.lang.MissingMethodException in project grails-core by grails.
the class ConstrainedPropertyBuilder method createNode.
@SuppressWarnings("rawtypes")
@Override
protected Object createNode(Object name, Map attributes) {
try {
String property = (String) name;
ConstrainedProperty cp;
if (constrainedProperties.containsKey(property)) {
cp = (ConstrainedProperty) constrainedProperties.get(property);
} else {
Class<?> propertyType = classPropertyFetcher.getPropertyType(property, true);
if (propertyType == null) {
throw new MissingMethodException(property, targetClass, new Object[] { attributes }, true);
}
cp = new ConstrainedProperty(targetClass, property, propertyType);
cp.setOrder(order++);
constrainedProperties.put(property, cp);
}
if (cp.getPropertyType() == null) {
if (!IMPORT_FROM_CONSTRAINT.equals(name)) {
GrailsUtil.warn("Property [" + cp.getPropertyName() + "] not found in domain class " + targetClass.getName() + "; cannot apply constraints: " + attributes);
}
return cp;
}
for (Object o : attributes.keySet()) {
String constraintName = (String) o;
final Object value = attributes.get(constraintName);
if (SHARED_CONSTRAINT.equals(constraintName)) {
if (value != null) {
sharedConstraints.put(property, value.toString());
}
continue;
}
if (cp.supportsContraint(constraintName)) {
cp.applyConstraint(constraintName, value);
} else {
if (ConstrainedProperty.hasRegisteredConstraint(constraintName)) {
// constraint is registered but doesn't support this property's type
GrailsUtil.warn("Property [" + cp.getPropertyName() + "] of domain class " + targetClass.getName() + " has type [" + cp.getPropertyType().getName() + "] and doesn't support constraint [" + constraintName + "]. This constraint will not be checked during validation.");
} else {
// in the case where the constraint is not supported we still retain meta data
// about the constraint in case its needed for other things
cp.addMetaConstraint(constraintName, value);
}
}
}
return cp;
} catch (InvalidPropertyException ipe) {
throw new MissingMethodException((String) name, targetClass, new Object[] { attributes });
}
}
use of groovy.lang.MissingMethodException in project groovity by disney.
the class ScriptHelper method tag.
@SuppressWarnings("rawtypes")
protected final Object tag(final String tagName, final Object[] argsArray) throws Exception {
Map tagParams = null;
Closure tagClosure = null;
if (argsArray != null && argsArray.length > 0) {
Object arg1 = argsArray[0];
if (arg1 instanceof Map) {
tagParams = (Map) arg1;
if (argsArray.length > 1) {
Object arg2 = argsArray[1];
if (arg2 instanceof Closure) {
tagClosure = (Closure) arg2;
} else if (arg2 instanceof ClosureWritable) {
tagClosure = ((ClosureWritable) arg2).getClosure();
}
}
} else {
if (arg1 instanceof Closure) {
tagClosure = (Closure) arg1;
} else if (arg1 instanceof ClosureWritable) {
tagClosure = ((ClosureWritable) arg1).getClosure();
} else {
throw new MissingMethodException(tagName, groovityClassLoader.getScriptClass(), argsArray);
}
}
}
if (tagParams == null) {
tagParams = Collections.EMPTY_MAP;
}
if (tagClosure == null) {
tagClosure = new groovy.lang.Closure(groovityClassLoader.getScriptClass()) {
private static final long serialVersionUID = 2274670949356312472L;
@SuppressWarnings("unused")
public void doCall() {
}
};
}
return groovity.tag(tagName, tagParams, tagClosure);
}
use of groovy.lang.MissingMethodException in project groovy by apache.
the class CachedMethod method invoke.
@Override
public final Object invoke(final Object object, final Object[] arguments) {
makeAccessibleIfNecessary();
if (!accessAllowed) {
try {
AccessPermissionChecker.checkAccessPermission(cachedMethod);
accessAllowed = true;
} catch (CacheAccessControlException ex) {
throw new InvokerInvocationException(ex);
}
}
try {
return cachedMethod.invoke(object, arguments);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new InvokerInvocationException(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
throw (cause instanceof RuntimeException && !(cause instanceof MissingMethodException)) ? (RuntimeException) cause : new InvokerInvocationException(e);
}
}
use of groovy.lang.MissingMethodException in project groovy by apache.
the class BuilderSupport method doInvokeMethod.
protected Object doInvokeMethod(final String methodName, final Object name, final Object args) {
Object node = null;
Closure closure = null;
List list = InvokerHelper.asList(args);
switch(list.size()) {
case 0:
node = proxyBuilder.createNode(name);
break;
case 1:
{
Object object = list.get(0);
if (object instanceof Map) {
node = proxyBuilder.createNode(name, (Map) object);
} else if (object instanceof Closure) {
closure = (Closure) object;
node = proxyBuilder.createNode(name);
} else {
node = proxyBuilder.createNode(name, object);
}
}
break;
case 2:
{
Object object1 = list.get(0);
Object object2 = list.get(1);
if (object1 instanceof Map) {
if (object2 instanceof Closure) {
closure = (Closure) object2;
node = proxyBuilder.createNode(name, (Map) object1);
} else {
node = proxyBuilder.createNode(name, (Map) object1, object2);
}
} else {
if (object2 instanceof Closure) {
closure = (Closure) object2;
node = proxyBuilder.createNode(name, object1);
} else if (object2 instanceof Map) {
node = proxyBuilder.createNode(name, (Map) object2, object1);
} else {
throw new MissingMethodException(name.toString(), getClass(), list.toArray(), false);
}
}
}
break;
case 3:
{
Object arg0 = list.get(0);
Object arg1 = list.get(1);
Object arg2 = list.get(2);
if (arg0 instanceof Map && arg2 instanceof Closure) {
closure = (Closure) arg2;
node = proxyBuilder.createNode(name, (Map) arg0, arg1);
} else if (arg1 instanceof Map && arg2 instanceof Closure) {
closure = (Closure) arg2;
node = proxyBuilder.createNode(name, (Map) arg1, arg0);
} else {
throw new MissingMethodException(name.toString(), getClass(), list.toArray(), false);
}
}
break;
default:
throw new MissingMethodException(name.toString(), getClass(), list.toArray(), false);
}
if (current != null) {
proxyBuilder.setParent(current, node);
}
if (closure != null) {
// push new node on stack
Object oldCurrent = getCurrent();
setCurrent(node);
// let's register the builder as the delegate
setClosureDelegate(closure, node);
try {
closure.call();
} catch (Exception e) {
throw new GroovyRuntimeException(e);
}
setCurrent(oldCurrent);
}
proxyBuilder.nodeCompleted(current, node);
return proxyBuilder.postNodeCompletion(current, node);
}
Aggregations