本文整理汇总了Java中org.codehaus.groovy.syntax.SyntaxException类的典型用法代码示例。如果您正苦于以下问题:Java SyntaxException类的具体用法?Java SyntaxException怎么用?Java SyntaxException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxException类属于org.codehaus.groovy.syntax包,在下文中一共展示了SyntaxException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrapCompilationFailure
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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: getMacroArguments
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的package包/类
protected static TupleExpression getMacroArguments(SourceUnit source, MethodCallExpression call) {
Expression macroCallArguments = call.getArguments();
if (macroCallArguments == null) {
source.addError(new SyntaxException("Call should have arguments" + '\n', call));
return null;
}
if (!(macroCallArguments instanceof TupleExpression)) {
source.addError(new SyntaxException("Call should have TupleExpression as arguments" + '\n', macroCallArguments));
return null;
}
TupleExpression tupleArguments = (TupleExpression) macroCallArguments;
if (tupleArguments.getExpressions() == null) {
source.addError(new SyntaxException("Call arguments should have expressions" + '\n', tupleArguments));
return null;
}
return tupleArguments;
}
示例3: getClosureArgument
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的package包/类
protected static ClosureExpression getClosureArgument(SourceUnit source, MethodCallExpression call) {
TupleExpression tupleArguments = getMacroArguments(source, call);
if (tupleArguments == null || tupleArguments.getExpressions().size() < 1) {
source.addError(new SyntaxException("Call arguments should have at least one argument" + '\n', tupleArguments));
return null;
}
Expression result = tupleArguments.getExpression(tupleArguments.getExpressions().size() - 1);
if (!(result instanceof ClosureExpression)) {
source.addError(new SyntaxException("Last call argument should be a closure" + '\n', result));
return null;
}
return (ClosureExpression) result;
}
示例4: createParsingFailedException
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的package包/类
private CompilationFailedException createParsingFailedException(Throwable t) {
if (t instanceof SyntaxException) {
this.collectSyntaxError((SyntaxException) t);
} else if (t instanceof GroovySyntaxError) {
GroovySyntaxError groovySyntaxError = (GroovySyntaxError) t;
this.collectSyntaxError(
new SyntaxException(
groovySyntaxError.getMessage(),
groovySyntaxError,
groovySyntaxError.getLine(),
groovySyntaxError.getColumn()));
} else if (t instanceof Exception) {
this.collectException((Exception) t);
}
return new CompilationFailedException(
CompilePhase.PARSING.getPhaseNumber(),
this.sourceUnit,
t);
}
示例5: tryPrivateMethod
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的package包/类
private boolean tryPrivateMethod(final MethodNode target, final boolean implicitThis, final Expression receiver, final TupleExpression args, final ClassNode classNode) {
ClassNode declaringClass = target.getDeclaringClass();
if ((isPrivateBridgeMethodsCallAllowed(declaringClass, classNode) || isPrivateBridgeMethodsCallAllowed(classNode, declaringClass))
&& declaringClass.getNodeMetaData(PRIVATE_BRIDGE_METHODS) != null
&& !declaringClass.equals(classNode)) {
if (tryBridgeMethod(target, receiver, implicitThis, args, classNode)) {
return true;
} else if (declaringClass != classNode) {
controller.getSourceUnit().addError(new SyntaxException("Cannot call private method " + (target.isStatic() ? "static " : "") +
declaringClass.toString(false) + "#" + target.getName() + " from class " + classNode.toString(false), receiver.getLineNumber(), receiver.getColumnNumber(), receiver.getLastLineNumber(), receiver.getLastColumnNumber()));
}
}
if (declaringClass != classNode) {
controller.getSourceUnit().addError(new SyntaxException("Cannot call private method " + (target.isStatic() ? "static " : "") +
declaringClass.toString(false) + "#" + target.getName() + " from class " + classNode.toString(false), receiver.getLineNumber(), receiver.getColumnNumber(), receiver.getLastLineNumber(), receiver.getLastColumnNumber()));
}
return false;
}
示例6: addListenerToProperty
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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));
}
示例7: visit
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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]);
}
}
示例8: wrapCompilationFailure
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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);
}
示例9: visitMapExpression
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的package包/类
@Override
public void visitMapExpression(final MapExpression exp) {
if (exp.getMapEntryExpressions().size() > 125) {
sourceUnit.addError(new SyntaxException("Map expressions can only contain up to 125 entries",
exp.getLineNumber(), exp.getColumnNumber()));
} else {
makeNode("map", new Runnable() {
@Override
public void run() {
for (MapEntryExpression e : exp.getMapEntryExpressions()) {
visit(e.getKeyExpression());
visit(e.getValueExpression());
}
}
});
}
}
示例10: scalifyProperty
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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));
}
示例11: addObservableIfNeeded
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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));
}
示例12: visit
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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]);
}
}
示例13: addVetoableIfNeeded
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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));
}
示例14: call
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的package包/类
@Override
public void call(SourceUnit source) throws CompilationFailedException {
List<Statement> statements = source.getAST().getStatementBlock().getStatements();
for (Statement statement : statements) {
ScriptBlock scriptBlock = AstUtils.detectScriptBlock(statement, SCRIPT_BLOCK_NAMES);
if (scriptBlock == null) {
// Look for model(«») (i.e. call to model with anything other than non literal closure)
MethodCallExpression methodCall = AstUtils.extractBareMethodCall(statement);
if (methodCall == null) {
continue;
}
String methodName = AstUtils.extractConstantMethodName(methodCall);
if (methodName == null) {
continue;
}
if (methodName.equals(MODEL)) {
source.getErrorCollector().addError(
new SyntaxException(NON_LITERAL_CLOSURE_TO_TOP_LEVEL_MODEL_MESSAGE, statement.getLineNumber(), statement.getColumnNumber()),
source
);
}
} else {
RuleVisitor ruleVisitor = new RuleVisitor(source, scriptSourceDescription, location);
RulesVisitor rulesVisitor = new RulesVisitor(source, ruleVisitor);
scriptBlock.getClosureExpression().getCode().visit(rulesVisitor);
}
}
}
示例15: fromGroovyException
import org.codehaus.groovy.syntax.SyntaxException; //导入依赖的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");
}
}