use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy by apache.
the class CompileUnit method addClass.
/**
* Adds a class to the unit.
*/
public void addClass(ClassNode node) {
node = node.redirect();
String name = node.getName();
ClassNode stored = classes.get(name);
if (stored != null && stored != node) {
// we have a duplicate class!
// One possibility for this is, that we declared a script and a
// class in the same file and named the class like the file
SourceUnit nodeSource = node.getModule().getContext();
SourceUnit storedSource = stored.getModule().getContext();
String txt = "Invalid duplicate class definition of class " + node.getName() + " : ";
if (nodeSource == storedSource) {
// same class in same source
txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n";
if (node.isScriptBody() || stored.isScriptBody()) {
txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" + " the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
}
} else {
txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " each contain a class with the name " + node.getName() + ".\n";
}
nodeSource.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), nodeSource));
}
classes.put(name, node);
if (classesToCompile.containsKey(name)) {
ClassNode cn = classesToCompile.get(name);
cn.setRedirect(node);
classesToCompile.remove(name);
}
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy by apache.
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 by apache.
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;
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy by apache.
the class ErrorCollector method write.
//---------------------------------------------------------------------------
// OUTPUT
private void write(PrintWriter writer, Janitor janitor, List messages, String txt) {
if (messages == null || messages.isEmpty())
return;
Iterator iterator = messages.iterator();
while (iterator.hasNext()) {
Message message = (Message) iterator.next();
message.write(writer, janitor);
if (configuration.getDebug() && (message instanceof SyntaxErrorMessage)) {
SyntaxErrorMessage sem = (SyntaxErrorMessage) message;
sem.getCause().printStackTrace(writer);
}
writer.println();
}
writer.print(messages.size());
writer.print(" " + txt);
if (messages.size() > 1)
writer.print("s");
writer.println();
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy by apache.
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);
}
}
Aggregations