Search in sources :

Example 11 with SyntaxErrorMessage

use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project grails-core by grails.

the class BindingFormatASTTransformation method error.

protected void error(final SourceUnit sourceUnit, final ASTNode astNode, final String message) {
    final SyntaxException syntaxException = new SyntaxException(message, astNode.getLineNumber(), astNode.getColumnNumber());
    final SyntaxErrorMessage syntaxErrorMessage = new SyntaxErrorMessage(syntaxException, sourceUnit);
    sourceUnit.getErrorCollector().addError(syntaxErrorMessage, false);
}
Also used : SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 12 with SyntaxErrorMessage

use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy-core by groovy.

the class StaticTypeCheckingVisitor method addError.

@Override
protected 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);
    }
}
Also used : SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxException(org.codehaus.groovy.syntax.SyntaxException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 13 with SyntaxErrorMessage

use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project gradle by gradle.

the class DefaultScriptCompilationHandler method wrapCompilationFailure.

private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) {
    // Fix the source file name displayed in the error messages
    for (Object message : e.getErrorCollector().getErrors()) {
        if (message instanceof SyntaxErrorMessage) {
            try {
                SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message;
                Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source");
                sourceField.setAccessible(true);
                SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage);
                Field nameField = SourceUnit.class.getDeclaredField("name");
                nameField.setAccessible(true);
                nameField.set(sourceUnit, source.getDisplayName());
            } catch (Exception failure) {
                throw UncheckedException.throwAsUncheckedException(failure);
            }
        }
    }
    SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0);
    Integer lineNumber = syntaxError == null ? null : syntaxError.getLine();
    throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber);
}
Also used : Field(java.lang.reflect.Field) SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxException(org.codehaus.groovy.syntax.SyntaxException) ScriptCompilationException(org.gradle.groovy.scripts.ScriptCompilationException) SourceUnit(org.codehaus.groovy.control.SourceUnit) UncheckedException(org.gradle.internal.UncheckedException) MultipleCompilationErrorsException(org.codehaus.groovy.control.MultipleCompilationErrorsException) MalformedURLException(java.net.MalformedURLException) GradleException(org.gradle.api.GradleException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) ScriptCompilationException(org.gradle.groovy.scripts.ScriptCompilationException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 14 with SyntaxErrorMessage

use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project grails-core by grails.

the class GrailsASTUtils method error.

/**
     * Generates a fatal compilation error.
     *
     * @param sourceUnit the SourceUnit
     * @param astNode the ASTNode which caused the error
     * @param message The error message
     * @param fatal indicates if this is a fatal error
     */
public static void error(final SourceUnit sourceUnit, final ASTNode astNode, final String message, final boolean fatal) {
    final SyntaxException syntaxException = new SyntaxException(message, astNode.getLineNumber(), astNode.getColumnNumber());
    final SyntaxErrorMessage syntaxErrorMessage = new SyntaxErrorMessage(syntaxException, sourceUnit);
    sourceUnit.getErrorCollector().addError(syntaxErrorMessage, fatal);
}
Also used : SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 15 with SyntaxErrorMessage

use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy-core by groovy.

the class BindableASTTransformation method visit.

/**
     * Handles the bulk of the processing, mostly delegating to other methods.
     *
     * @param nodes   the ast nodes
     * @param source  the source unit for the nodes
     */
public void visit(ASTNode[] nodes, SourceUnit source) {
    if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }
    AnnotationNode node = (AnnotationNode) nodes[0];
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    if (VetoableASTTransformation.hasVetoableAnnotation(parent)) {
        // VetoableASTTransformation will handle both @Bindable and @Vetoable
        return;
    }
    ClassNode declaringClass = parent.getDeclaringClass();
    if (parent instanceof FieldNode) {
        if ((((FieldNode) parent).getModifiers() & Opcodes.ACC_FINAL) != 0) {
            source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Bindable cannot annotate a final property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
        }
        if (VetoableASTTransformation.hasVetoableAnnotation(parent.getDeclaringClass())) {
            // VetoableASTTransformation will handle both @Bindable and @Vetoable
            return;
        }
        addListenerToProperty(source, node, declaringClass, (FieldNode) parent);
    } else if (parent instanceof ClassNode) {
        addListenerToClass(source, (ClassNode) parent);
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) FieldNode(org.codehaus.groovy.ast.FieldNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxException(org.codehaus.groovy.syntax.SyntaxException) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode)

Aggregations

SyntaxErrorMessage (org.codehaus.groovy.control.messages.SyntaxErrorMessage)28 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)23 Message (org.codehaus.groovy.control.messages.Message)10 ClassNode (org.codehaus.groovy.ast.ClassNode)7 FieldNode (org.codehaus.groovy.ast.FieldNode)6 PropertyNode (org.codehaus.groovy.ast.PropertyNode)6 SourceUnit (org.codehaus.groovy.control.SourceUnit)6 ExceptionMessage (org.codehaus.groovy.control.messages.ExceptionMessage)6 LocatedMessage (org.codehaus.groovy.control.messages.LocatedMessage)6 WarningMessage (org.codehaus.groovy.control.messages.WarningMessage)6 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)5 MismatchedCharException (antlr.MismatchedCharException)2 MismatchedTokenException (antlr.MismatchedTokenException)2 NoViableAltException (antlr.NoViableAltException)2 NoViableAltForCharException (antlr.NoViableAltForCharException)2 GroovyShell (groovy.lang.GroovyShell)2 Reference (groovy.lang.Reference)2 Script (groovy.lang.Script)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2