use of org.codehaus.groovy.ast.ASTNode in project groovy-core by groovy.
the class VerifierCodeVisitorTest method assertInvalidName.
protected void assertInvalidName(String name) {
try {
VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
fail("Should have thrown exception due to invalid name: " + name);
} catch (RuntimeParserException e) {
System.out.println("Caught invalid exception: " + e);
}
}
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);
}
use of org.codehaus.groovy.ast.ASTNode in project repository-permissions-updater by jenkins-infra.
the class GradleVerifier method getShortName.
public static String getShortName(String contents) {
String res = null;
AstBuilder astBuilder = new AstBuilder();
List<ASTNode> nodes = astBuilder.buildFromString(CompilePhase.SEMANTIC_ANALYSIS, false, contents);
boolean isDone = false;
BlockStatement node = (BlockStatement) nodes.get(0);
for (Statement s : node.getStatements()) {
Expression e = ((ExpressionStatement) s).getExpression();
if (e instanceof MethodCallExpression) {
MethodCallExpression mc = (MethodCallExpression) e;
if (mc.getMethodAsString().equals("jenkinsPlugin")) {
Expression jenkinsPlugin = ((ArgumentListExpression) mc.getArguments()).getExpression(0);
if (jenkinsPlugin instanceof ClosureExpression) {
ClosureExpression c = (ClosureExpression) jenkinsPlugin;
for (Statement st : ((BlockStatement) c.getCode()).getStatements()) {
ExpressionStatement sm = (ExpressionStatement) st;
if (sm.getExpression() instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) sm.getExpression();
if (be.getLeftExpression().getText().equals("shortName")) {
if (be.getRightExpression() instanceof ConstantExpression) {
res = be.getRightExpression().getText();
isDone = true;
break;
}
}
}
}
}
}
}
if (isDone) {
break;
}
}
return res;
}
use of org.codehaus.groovy.ast.ASTNode in project gradle by gradle.
the class IntegrationTestFixtureVisitor method checkOutputContains.
private void checkOutputContains(MethodCallExpression call) {
ASTNode receiver = call.getReceiver();
if (receiver instanceof PropertyExpression) {
if (((PropertyExpression) receiver).getPropertyAsString().equals("output")) {
Expression objectExpr = ((PropertyExpression) receiver).getObjectExpression();
checkIndirectOutputContains(objectExpr, call);
}
}
}
Aggregations