use of org.codehaus.groovy.ast.expr.Expression in project groovy-core by groovy.
the class NewifyASTTransformation method isNewMethodStyle.
private boolean isNewMethodStyle(MethodCallExpression mce) {
final Expression obj = mce.getObjectExpression();
final Expression meth = mce.getMethod();
return (obj instanceof ClassExpression && meth instanceof ConstantExpression && ((ConstantExpression) meth).getValue().equals("new"));
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy-core by groovy.
the class BaseScriptASTTransformation method changeBaseScriptTypeFromPackageOrImport.
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) {
Expression value = node.getMember("value");
if (!(value instanceof ClassExpression)) {
addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value);
return;
}
List<ClassNode> classes = source.getAST().getClasses();
for (ClassNode classNode : classes) {
if (classNode.isScriptBody()) {
changeBaseScriptType(parent, classNode, value.getType());
}
}
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy-core by groovy.
the class BaseScriptASTTransformation method changeBaseScriptTypeFromDeclaration.
private void changeBaseScriptTypeFromDeclaration(final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
Expression value = node.getMember("value");
if (value != null) {
addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
return;
}
ClassNode cNode = de.getDeclaringClass();
ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
de.setRightExpression(new VariableExpression("this"));
changeBaseScriptType(de, cNode, baseScriptType);
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy-core by groovy.
the class ImmutableASTTransformation method createGetterBodyArrayOrCloneable.
private Statement createGetterBodyArrayOrCloneable(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
final Expression expression = cloneArrayOrCloneableExpr(fieldExpr, fNode.getType());
return safeExpression(fieldExpr, expression);
}
use of org.codehaus.groovy.ast.expr.Expression in project groovy-core by groovy.
the class ImmutableASTTransformation method createConstructorStatementArrayOrCloneable.
private Statement createConstructorStatementArrayOrCloneable(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
Expression initExpr = fNode.getInitialValueExpression();
ClassNode fieldType = fNode.getType();
final Expression array = findArg(fNode.getName());
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression) initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneArrayOrCloneableExpr(initExpr, fieldType));
}
return ifElseS(equalsNullX(array), assignInit, assignS(fieldExpr, cloneArrayOrCloneableExpr(array, fieldType)));
}
Aggregations