use of org.codehaus.groovy.ast.ASTNode in project groovy by apache.
the class NotYetImplementedASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotationNode annotationNode = (AnnotationNode) nodes[0];
ASTNode node = nodes[1];
if (!(node instanceof MethodNode)) {
addError("@NotYetImplemented must only be applied on test methods!", node);
return;
}
MethodNode methodNode = (MethodNode) node;
ArrayList<Statement> statements = new ArrayList<Statement>();
Statement statement = methodNode.getCode();
if (statement instanceof BlockStatement) {
statements.addAll(((BlockStatement) statement).getStatements());
}
if (statements.isEmpty())
return;
BlockStatement rewrittenMethodCode = new BlockStatement();
rewrittenMethodCode.addStatement(tryCatchAssertionFailedError(annotationNode, methodNode, statements));
rewrittenMethodCode.addStatement(throwAssertionFailedError(annotationNode));
methodNode.setCode(rewrittenMethodCode);
}
use of org.codehaus.groovy.ast.ASTNode in project intellij-community by JetBrains.
the class GroovyCompilerWrapper method addErrorMessage.
private void addErrorMessage(GroovyRuntimeException exception) {
ASTNode astNode = exception.getNode();
ModuleNode module = exception.getModule();
if (module == null) {
module = findModule(astNode);
}
String moduleName = module == null ? "<no module>" : module.getDescription();
int lineNumber = astNode == null ? -1 : astNode.getLineNumber();
int columnNumber = astNode == null ? -1 : astNode.getColumnNumber();
collector.add(new CompilerMessage(GroovyCompilerMessageCategories.ERROR, getExceptionMessage(exception), moduleName, lineNumber, columnNumber));
}
use of org.codehaus.groovy.ast.ASTNode in project groovy by apache.
the class BytecodeSequence method visit.
/**
* Delegates to the visit method used for this class.
* If the visitor is a ClassGenerator, then
* {@link ClassGenerator#visitBytecodeSequence(BytecodeSequence)}
* is called with this instance. If the visitor is no
* ClassGenerator, then this method will call visit on
* each ASTNode element sorted by this class. If one
* element is a BytecodeInstruction, then it will be skipped
* as it is no ASTNode.
*
* @param visitor the visitor
* @see ClassGenerator
*/
public void visit(GroovyCodeVisitor visitor) {
if (visitor instanceof ClassGenerator) {
ClassGenerator gen = (ClassGenerator) visitor;
gen.visitBytecodeSequence(this);
return;
}
for (Iterator iterator = instructions.iterator(); iterator.hasNext(); ) {
Object part = (Object) iterator.next();
if (part instanceof ASTNode) {
((ASTNode) part).visit(visitor);
}
}
}
use of org.codehaus.groovy.ast.ASTNode in project hale by halestudio.
the class ASTToGraphVisitor method createNode.
@Override
public Vertex createNode(Object node) {
if (node instanceof ASTNode) {
ASTNode astn = (ASTNode) node;
Vertex v = graph.addVertex(null);
// fill vertex with info
v.setProperty(P_AST_NODE, astn);
v.setProperty(P_AST_TYPE, astn.getClass().getSimpleName());
v.setProperty(P_START_LINE, astn.getLineNumber());
v.setProperty(P_START_COL, astn.getColumnNumber());
v.setProperty(P_END_LINE, astn.getLastLineNumber());
v.setProperty(P_END_COL, astn.getLastColumnNumber());
return v;
}
return null;
}
use of org.codehaus.groovy.ast.ASTNode in project freeplane by freeplane.
the class GroovyScript method handleScriptRuntimeException.
private void handleScriptRuntimeException(final GroovyRuntimeException e) {
outStream.print("message: " + e.getMessage());
final ModuleNode module = e.getModule();
final ASTNode astNode = e.getNode();
int lineNumber = -1;
if (module != null) {
lineNumber = module.getLineNumber();
} else if (astNode != null) {
lineNumber = astNode.getLineNumber();
} else {
lineNumber = findLineNumberInString(e.getMessage(), lineNumber);
}
outStream.print("Line number: " + lineNumber);
errorHandler.gotoLine(lineNumber);
throw new ExecuteScriptException(e.getMessage() + " at line " + lineNumber, e);
}
Aggregations