/** * 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()); } } }
} catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting closure to " + clazz.getName() + ", Reason: " + cause.getMessage());
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); } }
throw iie; } catch (GroovyRuntimeException e) { if (e.getMessage().contains("Could not find matching constructor for")) { try { return InvokerHelper.invokeConstructorOf(type, object);
ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source );
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; }
@SuppressWarnings("unchecked") @Override public void validate(Object target, Errors errors) { JobData<String> jobData = (JobData<String>) target; GroovyShell shell = new GroovyShell(); try { shell.parse(jobData.getInput()); } catch (GroovyRuntimeException e) { errors.rejectValue(INPUT, null, e.getMessage()); } }
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); }
/** * Check if groovy code is valid * * @param bpmnFile * @param baseElement * @param scriptText * @return CheckerIssue or null */ private CheckerIssue parseGroovyCode(final String bpmnFile, final BpmnElement element, final BaseElement baseElement, final String scriptText) { final GroovyShell shell = new GroovyShell(); try { shell.evaluate(scriptText); } catch (final CompilationFailedException | MissingPropertyException ex) { if (ex instanceof CompilationFailedException) { return IssueWriter.createSingleIssue(rule, CriticalityEnum.ERROR, element, bpmnFile, ex.getMessage()); } else { return IssueWriter.createSingleIssue(rule, CriticalityEnum.ERROR, element, bpmnFile, String.format(Messages.getString("EmbeddedGroovyScriptChecker.1"), ex.getMessage())); //$NON-NLS-1$ } } return null; }
/** * 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. */ public static Object asType(Map map, Class clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
/** * Coerces the closure to an implementation of the given class. The class * is assumed to be an interface or class with a single method definition. * The closure is used as the implementation of that single method. * * @param cl the implementation of the single method * @param clazz the target type * @return a Proxy of the given type which wraps this closure. * @since 1.0 */ public static Object asType(Closure cl, Class clazz) { if (clazz.isInterface() && !(clazz.isInstance(cl))) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedClosure(cl)); } try { return asType((Object) cl, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(cl, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting closure to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
/** * 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 */ public static Object asType(Map map, Class clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
/** * Coerces the closure to an implementation of the given class. The class * is assumed to be an interface or class with a single method definition. * The closure is used as the implementation of that single method. * * @param cl the implementation of the single method * @param clazz the target type * @return a Proxy of the given type which wraps this closure. * @since 1.0 */ @SuppressWarnings("unchecked") public static <T> T asType(Closure cl, Class<T> clazz) { if (clazz.isInterface() && !(clazz.isInstance(cl))) { return (T) Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedClosure(cl)); } try { return asType((Object) cl, clazz); } catch (GroovyCastException ce) { try { return (T) ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(cl, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting closure to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
/** * Coerces the closure to an implementation of the given class. The class * is assumed to be an interface or class with a single method definition. * The closure is used as the implementation of that single method. * * @param cl the implementation of the single method * @param clazz the target type * @return a Proxy of the given type which wraps this closure. * @since 1.0 */ public static Object asType(Closure cl, Class clazz) { if (clazz.isInterface() && !(clazz.isInstance(cl))) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedClosure(cl)); } try { return asType((Object) cl, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(cl, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting closure to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
/** * 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 */ public static Object asType(Map map, Class clazz) { if (!(clazz.isInstance(map)) && clazz.isInterface()) { return Proxy.newProxyInstance( clazz.getClassLoader(), new Class[]{clazz}, new ConvertedMap(map)); } try { return asType((Object) map, clazz); } catch (GroovyCastException ce) { try { return ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz); } catch (GroovyRuntimeException cause) { throw new GroovyCastException("Error casting map to " + clazz.getName() + ", Reason: " + cause.getMessage()); } } }
/** * 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()) { 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 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"); } }
ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), null, node.getLineNumber(), node.getColumnNumber()), source );
ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), null, node.getLineNumber(), node.getColumnNumber()), source );