use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project groovy by apache.
the class JavaAwareResolveVisitor method getConstructorCall.
private static Expression getConstructorCall(Statement code) {
if (code == null)
return null;
if (code instanceof BlockStatement) {
BlockStatement bs = (BlockStatement) code;
if (bs.isEmpty())
return null;
return getConstructorCall(bs.getStatements().get(0));
}
if (!(code instanceof ExpressionStatement))
return null;
ExpressionStatement es = (ExpressionStatement) code;
Expression exp = es.getExpression();
if (!(exp instanceof ConstructorCallExpression))
return null;
ConstructorCallExpression cce = (ConstructorCallExpression) exp;
if (!cce.isSpecialCall())
return null;
return cce;
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project groovy by apache.
the class AntlrParserPlugin method variableDef.
protected Statement variableDef(AST variableDef) {
ExpressionStatement expressionStatement = new ExpressionStatement(declarationExpression(variableDef));
configureAST(expressionStatement, variableDef);
return expressionStatement;
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project groovy by apache.
the class AntlrParserPlugin method declarationExpression.
protected Expression declarationExpression(AST variableDef) {
AST node = variableDef.getFirstChild();
ClassNode type = null;
List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();
int modifiers = 0;
if (isType(MODIFIERS, node)) {
// force check of modifier conflicts
modifiers = modifiers(node, annotations, 0);
node = node.getNextSibling();
}
if (isType(TYPE, node)) {
type = makeTypeWithArguments(node);
node = node.getNextSibling();
}
Expression leftExpression;
Expression rightExpression = EmptyExpression.INSTANCE;
AST right;
if (isType(ASSIGN, node)) {
node = node.getFirstChild();
AST left = node.getFirstChild();
ArgumentListExpression alist = new ArgumentListExpression();
for (AST varDef = left; varDef != null; varDef = varDef.getNextSibling()) {
assertNodeType(VARIABLE_DEF, varDef);
DeclarationExpression de = (DeclarationExpression) declarationExpression(varDef);
alist.addExpression(de.getVariableExpression());
}
leftExpression = alist;
right = node.getNextSibling();
if (right != null)
rightExpression = expression(right);
} else {
String name = identifier(node);
VariableExpression ve = new VariableExpression(name, type);
ve.setModifiers(modifiers);
leftExpression = ve;
right = node.getNextSibling();
if (right != null) {
assertNodeType(ASSIGN, right);
rightExpression = expression(right.getFirstChild());
}
}
configureAST(leftExpression, node);
Token token = makeToken(Types.ASSIGN, variableDef);
DeclarationExpression expression = new DeclarationExpression(leftExpression, token, rightExpression);
expression.addAnnotations(annotations);
configureAST(expression, variableDef);
ExpressionStatement expressionStatement = new ExpressionStatement(expression);
configureAST(expressionStatement, variableDef);
return expression;
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project groovy by apache.
the class GeneralUtils method copyStatementsWithSuperAdjustment.
public static boolean copyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body) {
Statement preCode = pre.getCode();
boolean changed = false;
if (preCode instanceof BlockStatement) {
BlockStatement block = (BlockStatement) preCode;
List<Statement> statements = block.getStatements();
for (int i = 0; i < statements.size(); i++) {
Statement statement = statements.get(i);
// adjust the first statement if it's a super call
if (i == 0 && statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression preExp = es.getExpression();
if (preExp instanceof MethodCallExpression) {
MethodCallExpression mce = (MethodCallExpression) preExp;
String name = mce.getMethodAsString();
if ("super".equals(name)) {
es.setExpression(new ConstructorCallExpression(ClassNode.SUPER, mce.getArguments()));
changed = true;
}
}
}
body.addStatement(statement);
}
}
return changed;
}
use of org.codehaus.groovy.ast.stmt.ExpressionStatement in project groovy by apache.
the class AntlrParserPlugin method methodCall.
protected Statement methodCall(AST code) {
Expression expression = methodCallExpression(code);
ExpressionStatement expressionStatement = new ExpressionStatement(expression);
configureAST(expressionStatement, code);
return expressionStatement;
}
Aggregations