use of groovy.lang.GroovyRuntimeException in project groovy by apache.
the class ProxyGeneratorAdapter method proxy.
@SuppressWarnings("unchecked")
public GroovyObject proxy(Map<Object, Object> map, Object... constructorArgs) {
if (constructorArgs == null && cachedNoArgConstructor != null) {
// if there isn't any argument, we can make invocation faster using the cached constructor
try {
return (GroovyObject) cachedNoArgConstructor.newInstance(map);
} catch (InstantiationException e) {
throw new GroovyRuntimeException(e);
} catch (IllegalAccessException e) {
throw new GroovyRuntimeException(e);
} catch (InvocationTargetException e) {
throw new GroovyRuntimeException(e);
}
}
if (constructorArgs == null)
constructorArgs = EMPTY_ARGS;
Object[] values = new Object[constructorArgs.length + 1];
System.arraycopy(constructorArgs, 0, values, 0, constructorArgs.length);
values[values.length - 1] = map;
return DefaultGroovyMethods.<GroovyObject>newInstance(cachedClass, values);
}
use of groovy.lang.GroovyRuntimeException in project groovy by apache.
the class WriterController method init.
public void init(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, ClassVisitor cv, ClassNode cn) {
CompilerConfiguration config = cn.getCompileUnit().getConfig();
Map<String, Boolean> optOptions = config.getOptimizationOptions();
boolean invokedynamic = false;
if (optOptions.isEmpty()) {
// IGNORE
} else if (Boolean.FALSE.equals(optOptions.get("all"))) {
optimizeForInt = false;
// set other optimizations options to false here
} else {
if (Boolean.TRUE.equals(optOptions.get(CompilerConfiguration.INVOKEDYNAMIC)))
invokedynamic = true;
if (Boolean.FALSE.equals(optOptions.get("int")))
optimizeForInt = false;
if (invokedynamic)
optimizeForInt = false;
// set other optimizations options to false here
}
this.classNode = cn;
this.outermostClass = null;
this.internalClassName = BytecodeHelper.getClassInternalName(classNode);
bytecodeVersion = chooseBytecodeVersion(invokedynamic, config.getTargetBytecode());
if (invokedynamic) {
try {
this.invocationWriter = (InvocationWriter) indyWriter.newInstance(this);
this.callSiteWriter = (CallSiteWriter) indyCallSiteWriter.newInstance(this);
this.binaryExpHelper = (BinaryExpressionHelper) indyBinHelper.newInstance(this);
} catch (Exception e) {
throw new GroovyRuntimeException("Cannot use invokedynamic, indy module was excluded from this build.");
}
} else {
this.callSiteWriter = new CallSiteWriter(this);
this.invocationWriter = new InvocationWriter(this);
this.binaryExpHelper = new BinaryExpressionHelper(this);
}
this.unaryExpressionHelper = new UnaryExpressionHelper(this);
if (optimizeForInt) {
this.fastPathBinaryExpHelper = new BinaryExpressionMultiTypeDispatcher(this);
// todo: replace with a real fast path unary expression helper when available
this.fastPathUnaryExpressionHelper = new UnaryExpressionHelper(this);
} else {
this.fastPathBinaryExpHelper = this.binaryExpHelper;
this.fastPathUnaryExpressionHelper = new UnaryExpressionHelper(this);
}
this.operandStack = new OperandStack(this);
this.assertionWriter = new AssertionWriter(this);
this.closureWriter = new ClosureWriter(this);
this.internalBaseClassName = BytecodeHelper.getClassInternalName(classNode.getSuperClass());
this.acg = asmClassGenerator;
this.sourceUnit = acg.getSourceUnit();
this.context = gcon;
this.compileStack = new CompileStack(this);
this.cv = cv;
if (optimizeForInt) {
this.statementWriter = new OptimizingStatementWriter(this);
} else {
this.statementWriter = new StatementWriter(this);
}
this.typeChooser = new StatementMetaTypeChooser();
}
use of groovy.lang.GroovyRuntimeException in project intellij-community by JetBrains.
the class ScriptSupport method evaluate.
public String evaluate(MatchResult result, PsiElement context) {
try {
final HashMap<String, Object> variableMap = new HashMap<>();
variableMap.put(ScriptLog.SCRIPT_LOG_VAR_NAME, myScriptLog);
if (result != null) {
buildVariableMap(result, variableMap);
if (context == null) {
context = result.getMatch();
}
}
context = StructuralSearchUtil.getPresentableElement(context);
variableMap.put(myName, context);
variableMap.put(Configuration.CONTEXT_VAR_NAME, context);
script.setBinding(new Binding(variableMap));
final Object o = script.run();
return String.valueOf(o);
} catch (GroovyRuntimeException ex) {
throw new StructuralSearchException(SSRBundle.message("groovy.script.error", ex.getMessage()));
} finally {
script.setBinding(null);
}
}
use of groovy.lang.GroovyRuntimeException in project intellij-community by JetBrains.
the class GroovyCompilerWrapper method processException.
private void processException(Throwable exception, String prefix) {
if (exception instanceof GroovyRuntimeException) {
addErrorMessage((GroovyRuntimeException) exception);
return;
}
if (forStubs) {
collector.add(new CompilerMessage(GroovyCompilerMessageCategories.INFORMATION, GroovyRtConstants.GROOVYC_STUB_GENERATION_FAILED, null, -1, -1));
}
final StringWriter writer = new StringWriter();
writer.append(prefix);
if (!prefix.endsWith("\n")) {
writer.append("\n\n");
}
//noinspection IOResourceOpenedButNotSafelyClosed
exception.printStackTrace(new PrintWriter(writer));
collector.add(new CompilerMessage(forStubs ? GroovyCompilerMessageCategories.INFORMATION : GroovyCompilerMessageCategories.ERROR, writer.toString(), null, -1, -1));
}
Aggregations