use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project groovy-core by groovy.
the class NotYetImplementedASTTransformation method throwAssertionFailedError.
private Statement throwAssertionFailedError(AnnotationNode annotationNode) {
ThrowStatement throwStatement = new ThrowStatement(new ConstructorCallExpression(ASSERTION_FAILED_ERROR_TYPE, new ArgumentListExpression(new ConstantExpression("Method is marked with @NotYetImplemented but passes unexpectedly"))));
throwStatement.setSourcePosition(annotationNode);
return throwStatement;
}
use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project groovy-core by groovy.
the class NewifyASTTransformation method transform.
public Expression transform(Expression expr) {
if (expr == null)
return null;
if (expr instanceof MethodCallExpression && candidate == null) {
MethodCallExpression mce = (MethodCallExpression) expr;
Expression args = transform(mce.getArguments());
if (isNewifyCandidate(mce)) {
Expression transformed = transformMethodCall(mce, args);
transformed.setSourcePosition(mce);
return transformed;
}
Expression method = transform(mce.getMethod());
Expression object = transform(mce.getObjectExpression());
MethodCallExpression transformed = callX(object, method, args);
transformed.setSourcePosition(mce);
return transformed;
} else if (expr instanceof ClosureExpression) {
ClosureExpression ce = (ClosureExpression) expr;
ce.getCode().visit(this);
} else if (expr instanceof ConstructorCallExpression) {
ConstructorCallExpression cce = (ConstructorCallExpression) expr;
if (cce.isUsingAnonymousInnerClass()) {
cce.getType().visitContents(this);
}
} else if (expr instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) expr;
if (de == candidate || auto) {
candidate = null;
Expression left = de.getLeftExpression();
Expression right = transform(de.getRightExpression());
DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right);
newDecl.addAnnotations(de.getAnnotations());
return newDecl;
}
return de;
}
return expr.transformExpression(this);
}
use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project groovy-core by groovy.
the class NewifyASTTransformation method transformMethodCall.
private Expression transformMethodCall(MethodCallExpression mce, Expression args) {
ClassNode classType;
if (isNewMethodStyle(mce)) {
classType = mce.getObjectExpression().getType();
} else {
classType = findMatchingCandidateClass(mce);
}
if (classType != null) {
return new ConstructorCallExpression(classType, args);
}
// set the args as they might have gotten Newify transformed GROOVY-3491
mce.setArguments(args);
return mce;
}
use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project grails-core by grails.
the class DelegateAsyncTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode annotationNode = (AnnotationNode) nodes[0];
if (parent instanceof ClassNode) {
Expression value = annotationNode.getMember("value");
if (value instanceof ClassExpression) {
ClassNode targetApi = value.getType().getPlainNodeReference();
ClassNode classNode = (ClassNode) parent;
final String fieldName = '$' + Introspector.decapitalize(targetApi.getNameWithoutPackage());
FieldNode fieldNode = classNode.getField(fieldName);
if (fieldNode == null) {
fieldNode = new FieldNode(fieldName, Modifier.PRIVATE, targetApi, classNode, new ConstructorCallExpression(targetApi, NO_ARGS));
classNode.addField(fieldNode);
}
applyDelegateAsyncTransform(classNode, targetApi, fieldName);
}
} else if (parent instanceof FieldNode) {
FieldNode fieldNode = (FieldNode) parent;
ClassNode targetApi = fieldNode.getType().getPlainNodeReference();
ClassNode classNode = fieldNode.getOwner();
applyDelegateAsyncTransform(classNode, targetApi, fieldNode.getName());
}
}
use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project groovy-core by groovy.
the class JavaStubGenerator method printSpecialConstructorArgs.
private void printSpecialConstructorArgs(PrintWriter out, ConstructorNode node, ConstructorCallExpression constrCall) {
// Select a constructor from our class, or super-class which is legal to call,
// then write out an invoke w/nulls using casts to avoid ambiguous crapo
Parameter[] params = selectAccessibleConstructorFromSuper(node);
if (params != null) {
out.print("super (");
for (int i = 0; i < params.length; i++) {
printDefaultValue(out, params[i].getType());
if (i + 1 < params.length) {
out.print(", ");
}
}
out.println(");");
return;
}
// Otherwise try the older method based on the constructor's call expression
Expression arguments = constrCall.getArguments();
if (constrCall.isSuperCall()) {
out.print("super(");
} else {
out.print("this(");
}
// Else try to render some arguments
if (arguments instanceof ArgumentListExpression) {
ArgumentListExpression argumentListExpression = (ArgumentListExpression) arguments;
List<Expression> args = argumentListExpression.getExpressions();
for (Expression arg : args) {
if (arg instanceof ConstantExpression) {
ConstantExpression expression = (ConstantExpression) arg;
Object o = expression.getValue();
if (o instanceof String) {
out.print("(String)null");
} else {
out.print(expression.getText());
}
} else {
ClassNode type = getConstructorArgumentType(arg, node);
printDefaultValue(out, type);
}
if (arg != args.get(args.size() - 1)) {
out.print(", ");
}
}
}
out.println(");");
}
Aggregations