本文整理汇总了Java中org.codehaus.groovy.control.messages.SyntaxErrorMessage类的典型用法代码示例。如果您正苦于以下问题:Java SyntaxErrorMessage类的具体用法?Java SyntaxErrorMessage怎么用?Java SyntaxErrorMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxErrorMessage类属于org.codehaus.groovy.control.messages包,在下文中一共展示了SyntaxErrorMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrapCompilationFailure
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
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);
}
示例2: write
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
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();
}
示例3: addListenerToProperty
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
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));
}
示例4: visit
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
/**
* 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];
if (nodes[1] instanceof ClassNode) {
addListenerToClass(source, (ClassNode) nodes[1]);
} else {
if ((((FieldNode)nodes[1]).getModifiers() & Opcodes.ACC_FINAL) != 0) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Vetoable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
addListenerToProperty(source, node, (AnnotatedNode) nodes[1]);
}
}
示例5: wrapCompilationFailure
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
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);
}
示例6: scalifyProperty
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
private void scalifyProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field) {
String fieldName = field.getName();
for (PropertyNode propertyNode : (Collection<PropertyNode>) declaringClass.getProperties()) {
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
source.getErrorCollector().addErrorAndContinue(
new SyntaxErrorMessage(new SyntaxException(
"@Scalify cannot annotate a static property.",
node.getLineNumber(),
node.getColumnNumber()),
source));
} else {
createScalaAccessors(source, node, declaringClass, propertyNode);
}
return;
}
}
source.getErrorCollector().addErrorAndContinue(
new SyntaxErrorMessage(new SyntaxException(
"@Scalify must be on a property, not a field. Try removing the private, protected, or public modifier.",
node.getLineNumber(),
node.getColumnNumber()),
source));
}
示例7: addObservableIfNeeded
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
public static void addObservableIfNeeded(SourceUnit source, AnnotationNode annotationNode, ClassNode classNode, FieldNode field) {
String fieldName = field.getName();
for (PropertyNode propertyNode : classNode.getProperties()) {
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Observable cannot annotate a static property.",
annotationNode.getLineNumber(), annotationNode.getColumnNumber(), annotationNode.getLastLineNumber(), annotationNode.getLastColumnNumber()),
source));
} else {
if (needsObservableSupport(classNode, source)) {
LOG.debug("Injecting {} into {}", OBSERVABLE_TYPE, classNode.getName());
apply(classNode);
}
createListenerSetter(classNode, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Observable must be on a property, not a field. Try removing the private, protected, or public modifier.",
annotationNode.getLineNumber(), annotationNode.getColumnNumber(), annotationNode.getLastLineNumber(), annotationNode.getLastColumnNumber()),
source));
}
示例8: visit
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
/**
* 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];
if (nodes[1] instanceof ClassNode) {
addVetoableIfNeeded(source, (ClassNode) nodes[1]);
} else {
if ((((FieldNode) nodes[1]).getModifiers() & Modifier.FINAL) != 0) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Vetoable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
addVetoableIfNeeded(source, node, (AnnotatedNode) nodes[1]);
}
}
示例9: addVetoableIfNeeded
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
private void addVetoableIfNeeded(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 = hasObservableAnnotation(parent)
|| hasObservableAnnotation(parent.getDeclaringClass());
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.Vetoable cannot annotate a static property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
} else {
createListenerSetter(source, bindable, declaringClass, propertyNode);
}
return;
}
}
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@griffon.transform.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));
}
示例10: fromGroovyException
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
public static ScriptError fromGroovyException(MultipleCompilationErrorsException e) {
ErrorCollector errorCollector = e.getErrorCollector();
if (errorCollector.getErrorCount() > 0) {
Message error = errorCollector.getError(0);
if (error instanceof SyntaxErrorMessage) {
SyntaxException cause = ((SyntaxErrorMessage) error).getCause();
return new ScriptError(cause.getMessage(), cause.getStartLine(), cause.getStartColumn(),
cause.getEndLine(), cause.getEndColumn());
} else {
throw new AssertionError("SyntaxErrorMessage is expected");
}
} else {
throw new AssertionError("At least one error is expected");
}
}
示例11: mangleMultipleCompilationErrorsException
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
private RuntimeException mangleMultipleCompilationErrorsException(MultipleCompilationErrorsException e, List<StringSection> sections) {
RuntimeException result = e;
ErrorCollector collector = e.getErrorCollector();
@SuppressWarnings({"unchecked"})
List<Message> errors = (List<Message>) collector.getErrors();
if (!errors.isEmpty()) {
Message firstMessage = errors.get(0);
if (firstMessage instanceof SyntaxErrorMessage) {
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
SyntaxException syntaxException = ((SyntaxErrorMessage) firstMessage).getCause();
Position errorPosition = new Position(syntaxException.getLine(), syntaxException.getStartColumn());
//find the string section which precedes the row/col of the thrown exception
StringSection precedingSection = findPrecedingSection(errorPosition, sections);
//and now use the string section to mangle the line numbers so that they refer to the
//appropriate line in the source template data
if (precedingSection != null) {
//if the error was thrown on the same row as where the last string section
//ended, fix column value
offsetPositionFromSection(errorPosition, precedingSection);
//the below being true indicates that we had an unterminated ${ or <% sequence and
//the column is thus meaningless, we reset it to where the %{ or <% starts to at
//least give the user a sporting chance
if (sections.get(sections.size() - 1) == precedingSection) {
errorPosition.column = precedingSection.lastSourcePosition.column;
}
String message = mangleExceptionMessage(e.getMessage(), errorPosition);
result = new TemplateParseException(message, e, errorPosition.row, errorPosition.column);
}
}
}
return result;
}
示例12: getSyntaxError
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
/**
* 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;
}
示例13: getException
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
/**
* 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;
}
示例14: convert
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
/**
* Generates an AST from the CST. You can retrieve it with getAST().
*/
public void convert() throws CompilationFailedException {
if (this.phase == Phases.PARSING && this.phaseComplete) {
gotoPhase(Phases.CONVERSION);
}
if (this.phase != Phases.CONVERSION) {
throw new GroovyBugError("SourceUnit not ready for convert()");
}
//
// Build the AST
try {
this.ast = parserPlugin.buildAST(this, this.classLoader, this.cst);
this.ast.setDescription(this.name);
}
catch (SyntaxException e) {
if (this.ast == null) {
// Create a dummy ModuleNode to represent a failed parse - in case a later phase attempts to use the ast
this.ast = new ModuleNode(this);
}
getErrorCollector().addError(new SyntaxErrorMessage(e, this));
}
String property = (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty("groovy.ast");
}
});
if ("xml".equals(property)) {
saveAsXML(name, ast);
}
}
示例15: addError
import org.codehaus.groovy.control.messages.SyntaxErrorMessage; //导入依赖的package包/类
public void addError(String msg, ASTNode expr) {
sourceUnit.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException(msg + '\n', expr.getLineNumber(), expr.getColumnNumber(),
expr.getLastLineNumber(), expr.getLastColumnNumber()),
sourceUnit)
);
}