use of org.codehaus.groovy.control.messages.ExceptionMessage in project intellij-community by JetBrains.
the class GrapeRunner method main.
public static void main(String[] args) {
final GroovyShell shell = new GroovyShell();
try {
shell.parse(args[0] + " import java.lang.*");
} catch (MultipleCompilationErrorsException e) {
List errors = e.getErrorCollector().getErrors();
for (Iterator iterator = errors.iterator(); iterator.hasNext(); ) {
Object o = iterator.next();
if (o instanceof ExceptionMessage) {
Exception cause = ((ExceptionMessage) o).getCause();
String message = cause.getMessage();
if (message != null && message.startsWith("Error grabbing Grapes")) {
System.out.println(message);
return;
}
}
}
e.printStackTrace();
return;
} catch (Throwable e) {
e.printStackTrace();
return;
}
URL[] urls = shell.getClassLoader().getURLs();
for (int i = 0; i < urls.length; i++) {
System.out.println(URL_PREFIX + urls[i]);
}
}
use of org.codehaus.groovy.control.messages.ExceptionMessage in project groovy-core by groovy.
the class JavacJavaCompiler method compile.
public void compile(List<String> files, CompilationUnit cu) {
String[] javacParameters = makeParameters(files, cu.getClassLoader());
StringWriter javacOutput = null;
int javacReturnValue = 0;
try {
Class javac = findJavac(cu);
Method method = null;
try {
method = javac.getMethod("compile", new Class[] { String[].class, PrintWriter.class });
javacOutput = new StringWriter();
PrintWriter writer = new PrintWriter(javacOutput);
Object ret = method.invoke(null, javacParameters, writer);
javacReturnValue = (Integer) ret;
} catch (NoSuchMethodException e) {
}
if (method == null) {
method = javac.getMethod("compile", new Class[] { String[].class });
Object ret = method.invoke(null, new Object[] { javacParameters });
javacReturnValue = (Integer) ret;
}
cu.getConfiguration().getOutput();
} catch (InvocationTargetException ite) {
cu.getErrorCollector().addFatalError(new ExceptionMessage((Exception) ite.getCause(), true, cu));
} catch (Exception e) {
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
}
if (javacReturnValue != 0) {
switch(javacReturnValue) {
case 1:
addJavacError("Compile error during compilation with javac.", cu, javacOutput);
break;
case 2:
addJavacError("Invalid commandline usage for javac.", cu, javacOutput);
break;
case 3:
addJavacError("System error during compilation with javac.", cu, javacOutput);
break;
case 4:
addJavacError("Abnormal termination of javac.", cu, javacOutput);
break;
default:
addJavacError("unexpected return value by javac.", cu, javacOutput);
break;
}
} else {
// print warnings if any
System.out.print(javacOutput);
}
}
use of org.codehaus.groovy.control.messages.ExceptionMessage in project groovy-core by groovy.
the class ASTTransformationCollectorCodeVisitor method addCollectedAnnotations.
private boolean addCollectedAnnotations(List<AnnotationNode> collected, AnnotationNode aliasNode, AnnotatedNode origin) {
ClassNode classNode = aliasNode.getClassNode();
boolean ret = false;
for (AnnotationNode annotation : classNode.getAnnotations()) {
if (annotation.getClassNode().getName().equals(AnnotationCollector.class.getName())) {
Expression processorExp = annotation.getMember("processor");
AnnotationCollectorTransform act = null;
assertStringConstant(processorExp);
if (processorExp != null) {
String className = (String) ((ConstantExpression) processorExp).getValue();
Class klass = loadTransformClass(className, aliasNode);
if (klass != null) {
try {
act = (AnnotationCollectorTransform) klass.newInstance();
} catch (InstantiationException e) {
source.getErrorCollector().addErrorAndContinue(new ExceptionMessage(e, true, source));
} catch (IllegalAccessException e) {
source.getErrorCollector().addErrorAndContinue(new ExceptionMessage(e, true, source));
}
}
} else {
act = new AnnotationCollectorTransform();
}
if (act != null)
collected.addAll(act.visit(annotation, aliasNode, origin, source));
ret = true;
}
}
return ret;
}
use of org.codehaus.groovy.control.messages.ExceptionMessage in project groovy-core by groovy.
the class CompilationUnit method convertUncaughtExceptionToCompilationError.
private void convertUncaughtExceptionToCompilationError(final Throwable e) {
// check the exception for a nested compilation exception
ErrorCollector nestedCollector = null;
for (Throwable next = e.getCause(); next != e && next != null; next = next.getCause()) {
if (!(next instanceof MultipleCompilationErrorsException))
continue;
MultipleCompilationErrorsException mcee = (MultipleCompilationErrorsException) next;
nestedCollector = mcee.collector;
break;
}
if (nestedCollector != null) {
getErrorCollector().addCollectorContents(nestedCollector);
} else {
Exception err = e instanceof Exception ? ((Exception) e) : new RuntimeException(e);
getErrorCollector().addError(new ExceptionMessage(err, configuration.getDebug(), this));
}
}
use of org.codehaus.groovy.control.messages.ExceptionMessage in project groovy-core by groovy.
the class ErrorCollector method getException.
/**
* Convenience routine to return the specified error's
* underlying Exception, or null if it isn't one.
*/
public Exception getException(int index) {
Exception exception = null;
Message message = getError(index);
if (message != null) {
if (message instanceof ExceptionMessage) {
exception = ((ExceptionMessage) message).getCause();
} else if (message instanceof SyntaxErrorMessage) {
exception = ((SyntaxErrorMessage) message).getCause();
}
}
return exception;
}
Aggregations