use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy-core by groovy.
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-core by groovy.
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 intellij-community by JetBrains.
the class ScriptSupport method checkValidScript.
public static String checkValidScript(String scriptText) {
try {
final File scriptFile = new File(scriptText);
final GroovyShell shell = new GroovyShell();
final Script script = scriptFile.exists() ? shell.parse(scriptFile) : shell.parse(scriptText);
return null;
} catch (IOException e) {
return e.getMessage();
} catch (MultipleCompilationErrorsException e) {
final ErrorCollector errorCollector = e.getErrorCollector();
final List<Message> errors = errorCollector.getErrors();
for (Message error : errors) {
if (error instanceof SyntaxErrorMessage) {
final SyntaxErrorMessage errorMessage = (SyntaxErrorMessage) error;
final SyntaxException cause = errorMessage.getCause();
return cause.getMessage();
}
}
return e.getMessage();
} catch (CompilationFailedException ex) {
return ex.getLocalizedMessage();
}
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy-core by groovy.
the class ClassCodeVisitorSupport method addError.
protected void addError(String msg, ASTNode expr) {
SourceUnit source = getSourceUnit();
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException(msg + '\n', expr.getLineNumber(), expr.getColumnNumber(), expr.getLastLineNumber(), expr.getLastColumnNumber()), source));
}
use of org.codehaus.groovy.control.messages.SyntaxErrorMessage in project groovy-core by groovy.
the class BindableASTTransformation method addListenerToProperty.
private void addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field) {
String fieldName = field.getName();
for (PropertyNode propertyNode : declaringClass.getProperties()) {
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Bindable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
} else {
if (needsPropertyChangeSupport(declaringClass, source)) {
addPropertyChangeSupport(declaringClass);
}
createListenerSetter(declaringClass, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Bindable 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));
}
Aggregations