use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy by apache.
the class VetoableASTTransformation method addListenerToProperty.
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) {
ClassNode declaringClass = parent.getDeclaringClass();
FieldNode field = ((FieldNode) parent);
String fieldName = field.getName();
for (PropertyNode propertyNode : declaringClass.getProperties()) {
boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent) || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass());
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
} else {
createListenerSetter(source, bindable, declaringClass, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy by apache.
the class StaticTypeCheckingVisitor method addError.
@Override
public void addError(final String msg, final ASTNode expr) {
Long err = ((long) expr.getLineNumber()) << 16 + expr.getColumnNumber();
if ((DEBUG_GENERATED_CODE && expr.getLineNumber() < 0) || !typeCheckingContext.reportedErrors.contains(err)) {
typeCheckingContext.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException(msg + '\n', expr.getLineNumber(), expr.getColumnNumber(), expr.getLastLineNumber(), expr.getLastColumnNumber()), typeCheckingContext.source));
typeCheckingContext.reportedErrors.add(err);
}
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project ratpack by ratpack.
the class GroovySnippetExecuter method execute.
@Override
public void execute(TestCodeSnippet snippet) throws Exception {
CompilerConfiguration config = new CompilerConfiguration();
config.addCompilationCustomizers(new CompilationCustomizer(CompilePhase.CONVERSION) {
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
if (compileStatic) {
classNode.addAnnotation(new AnnotationNode(new ClassNode(CompileStatic.class)));
}
}
});
ClassLoader classLoader = new URLClassLoader(new URL[] {}, getClass().getClassLoader());
GroovyShell groovyShell = new GroovyShell(classLoader, new Binding(), config);
List<String> importsAndSnippet = extractImports(snippet.getSnippet());
String imports = importsAndSnippet.get(0);
String snippetMinusImports = fixture.transform(importsAndSnippet.get(1));
String fullSnippet = imports + fixture.pre() + snippetMinusImports + fixture.post();
Script script;
try {
script = groovyShell.parse(fullSnippet, snippet.getClassName());
} catch (MultipleCompilationErrorsException e) {
Message error = e.getErrorCollector().getError(0);
if (error instanceof SyntaxErrorMessage) {
//noinspection ThrowableResultOfMethodCallIgnored
System.out.println(snippet.getSnippet());
throw new CompileException(e, ((SyntaxErrorMessage) error).getCause().getLine());
} else {
throw e;
}
}
ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(groovyShell.getClassLoader());
fixture.around(script::run);
} finally {
Thread.currentThread().setContextClassLoader(previousContextClassLoader);
}
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy-core by groovy.
the class ErrorCollector method getSyntaxError.
/**
* Convenience routine to return the specified error's
* underlying SyntaxException, or null if it isn't one.
*/
public SyntaxException getSyntaxError(int index) {
SyntaxException exception = null;
Message message = getError(index);
if (message != null && message instanceof SyntaxErrorMessage) {
exception = ((SyntaxErrorMessage) message).getCause();
}
return exception;
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage 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