Refine search
@Deprecated public static void upto(Date self, Date to, Closure closure) { if (self.compareTo(to) <= 0) { for (Date i = (Date) self.clone(); i.compareTo(to) <= 0; i = next(i)) { closure.call(i); } } else throw new GroovyRuntimeException("The argument (" + to + ") to upto() cannot be earlier than the value (" + self + ") it's called on."); }
public String getMessage() { return getMessageWithoutLocationText() + getLocationText(); }
public GroovyRuntimeException(Throwable t) { super(); initCause(t); }
@Override public Writer writeTo(Writer out) throws IOException { String[] s = getStrings(); int numberOfValues = values.length; for (int i = 0, size = s.length; i < size; i++) { out.write(s[i]); if (i < numberOfValues) { final Object value = values[i]; if (value instanceof Closure) { final Closure c = (Closure) value; int maximumNumberOfParameters = c.getMaximumNumberOfParameters(); if (maximumNumberOfParameters == 0) { InvokerHelper.write(out, c.call()); } else if (maximumNumberOfParameters == 1) { c.call(out); } else { throw new GroovyRuntimeException("Trying to evaluate a GString containing a Closure taking " + maximumNumberOfParameters + " parameters"); } } else { InvokerHelper.write(out, value); } } } return out; }
private void throwException(String m, Exception e) { if (!ignoreErrors) { throw new GroovyRuntimeException(m + e, e); } }
groovyClass = loader.parseClass(new GroovyCodeSource(templateExpressions.toString(), "GStringTemplateScript" + counter.incrementAndGet() + ".groovy", "x")); } catch (Exception e) { throw new GroovyRuntimeException("Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): " + e.getMessage()); this.template.setResolveStrategy(Closure.DELEGATE_FIRST); } catch (InstantiationException e) { throw new ClassNotFoundException(e.getMessage());
private Closure createTemplateClosure(List<StringSection> sections, final ClassLoader parentLoader, StringBuilder target) throws ClassNotFoundException { final GroovyClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() { public GroovyClassLoader run() { return new GroovyClassLoader(parentLoader); } }); final Class groovyClass; try { groovyClass = loader.parseClass(new GroovyCodeSource(target.toString(), TEMPLATE_SCRIPT_PREFIX + counter++ + ".groovy", "x")); } catch (MultipleCompilationErrorsException e) { throw mangleMultipleCompilationErrorsException(e, sections); } catch (Exception e) { throw new GroovyRuntimeException("Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): " + e.getMessage()); } Closure result; try { final GroovyObject object = (GroovyObject) groovyClass.newInstance(); Closure chicken = (Closure) object.invokeMethod("getTemplate", null); //bind the two first parameters of the generated closure to this class and the sections list result = chicken.curry(this, sections); } catch (InstantiationException e) { throw new ClassNotFoundException(e.getMessage()); } catch (IllegalAccessException e) { throw new ClassNotFoundException(e.getMessage()); } return result; }
public Object leftShift(Closure c) { if(c != null) { Class[] paramTypes = c.getParameterTypes(); if(paramTypes == null)paramTypes = ZERO_ARGUMENTS; Constructor ctor = retrieveConstructor(paramTypes); if(ctor != null) throw new GroovyRuntimeException("Cannot add new constructor for arguments ["+DefaultGroovyMethods.inspect(paramTypes)+"]. It already exists!"); registerInstanceMethod(GROOVY_CONSTRUCTOR, c); } return this; } }
public void testInvokerException() throws Throwable { try { throw new GroovyRuntimeException("message", new NullPointerException()); } catch (GroovyRuntimeException e) { // worked assertEquals("message", e.getMessage()); assertTrue(e.getCause() instanceof NullPointerException); } }
/** * Coerces this map to the given type, using the map's keys as the public * method names, and values as the implementation. Typically the value * would be a closure which behaves like the method implementation. * * @param map this map * @param clazz the target type * @return a Proxy of the given type, which defers calls to this map's elements. * @since 1.0 */ @SuppressWarnings("unchecked") public static <T> T asType(Map map, Class<T> clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface() && !Traits.isTrait(clazz)) { return (T) Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return (T) ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
private static void visit(Closure closure, CodeVisitorSupport visitor) { if (closure != null) { ClassNode classNode = closure.getMetaClass().getClassNode(); if (classNode == null) { throw new GroovyRuntimeException( "DataSet unable to evaluate expression. AST not available for closure: " + closure.getMetaClass().getTheClass().getName() + ". Is the source code on the classpath?"); } List methods = classNode.getDeclaredMethods("doCall"); if (!methods.isEmpty()) { MethodNode method = (MethodNode) methods.get(0); if (method != null) { Statement statement = method.getCode(); if (statement != null) { statement.visit(visitor); } } } } }
verifier.visitClass(classNode); } catch (GroovyRuntimeException rpe) { ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source );
throw new GroovyRuntimeException("Automatic coercion of " + n.getClass().getName() + " value " + n + " to double failed. Value is out of range."); throw new GroovyRuntimeException("Automatic coercion of " + aClass.getName() + " value " + object + " to double failed. Value is out of range."); throw iie; } catch (GroovyRuntimeException e) { if(e.getMessage().contains("Could not find matching constructor for")) { try { return InvokerHelper.invokeConstructorOf(type, object);
private void handleScriptRuntimeException(final GroovyRuntimeException e, PrintStream outStream, IFreeplaneScriptErrorHandler errorHandler) { outStream.print("message: " + e.getMessage()); final ModuleNode module = e.getModule(); final ASTNode astNode = e.getNode(); int lineNumber = -1; if (module != null) { lineNumber = module.getLineNumber(); } else if (astNode != null) { lineNumber = astNode.getLineNumber(); } else { lineNumber = findLineNumberInString(e.getMessage(), lineNumber); } outStream.print("Line number: " + lineNumber); errorHandler.gotoLine(lineNumber); throw new ExecuteScriptException(e.getMessage() + " at line " + lineNumber, e); }
private void filterConfigurations( final MatrixBuildExecution execution, final Collection<MatrixConfiguration> touchStoneConfigurations, final Collection<MatrixConfiguration> delayedConfigurations ) throws AbortException { final MatrixBuild build = execution.getBuild(); final FilterScript combinationFilter = FilterScript.parse(execution.getProject().getCombinationFilter(), FilterScript.ACCEPT_ALL); final FilterScript touchStoneFilter = FilterScript.parse(getTouchStoneCombinationFilter(), FilterScript.REJECT_ALL); try { for (MatrixConfiguration c: execution.getActiveConfigurations()) { if (!MatrixBuildListener.buildConfiguration(build, c)) continue; // skip rebuild final Combination combination = c.getCombination(); if (touchStoneFilter != null && touchStoneFilter.apply(execution, combination)) { touchStoneConfigurations.add(c); } else if (combinationFilter.apply(execution, combination)) { delayedConfigurations.add(c); } } } catch (GroovyRuntimeException ex) { PrintStream logger = execution.getListener().getLogger(); logger.println(ex.getMessage()); ex.printStackTrace(logger); throw new AbortException("Failed executing combination filter"); } }
public static ScriptError fromGroovyException(GroovyRuntimeException e, String scriptName) { Objects.requireNonNull(scriptName); for (StackTraceElement element : e.getStackTrace()) { if (scriptName.equals(element.getFileName()) && scriptName.equals(element.getClassName()) && "run".equals(element.getMethodName())) { return new ScriptError(e.getMessage(), element.getLineNumber(), -1, element.getLineNumber(), -1); } } return null; }
public String getMessageWithoutLocationText() { final Throwable cause = getCause(); if (cause == null) { if (super.getMessageWithoutLocationText() != null) { return super.getMessageWithoutLocationText(); } return "No such property: " + property + " for class: " + type.getName() + MethodRankHelper.getPropertySuggestionString(property, type); } return "No such property: " + property + " for class: " + type.getName() + ". Reason: " + cause; }
/** * Throws a <code>GroovyRuntimeException</code>, because an attribute can have no children. */ public Iterator childNodes() { throw new GroovyRuntimeException("can't call childNodes() in the attribute " + this.name); }
} catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting closure to " + clazz.getName() + ", Reason: " + cause.getMessage());
verifier.visitClass(classNode); } catch (GroovyRuntimeException rpe) { ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), null, node.getLineNumber(), node.getColumnNumber()), source );