use of org.codehaus.groovy.ast.expr.MethodCallExpression in project groovy-core by groovy.
the class StaticMethodCallExpressionTransformer method transformStaticMethodCallExpression.
Expression transformStaticMethodCallExpression(final StaticMethodCallExpression orig) {
MethodNode target = (MethodNode) orig.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
if (target != null) {
MethodCallExpression call = new MethodCallExpression(new ClassExpression(orig.getOwnerType()), orig.getMethod(), orig.getArguments());
call.setMethodTarget(target);
call.setSourcePosition(orig);
call.copyNodeMetaData(orig);
return transformer.transform(call);
}
return transformer.superTransform(orig);
}
use of org.codehaus.groovy.ast.expr.MethodCallExpression in project groovy-core by groovy.
the class BinaryExpressionTransformer method convertInOperatorToTernary.
private Expression convertInOperatorToTernary(final BinaryExpression bin, final Expression rightExpression, final Expression leftExpression) {
MethodCallExpression call = new MethodCallExpression(rightExpression, "isCase", leftExpression);
call.setMethodTarget((MethodNode) bin.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET));
call.setSourcePosition(bin);
call.copyNodeMetaData(bin);
TernaryExpression tExp = new TernaryExpression(new BooleanExpression(new BinaryExpression(rightExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null))), new BinaryExpression(leftExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null)), call);
return staticCompilationTransformer.transform(tExp);
}
use of org.codehaus.groovy.ast.expr.MethodCallExpression in project grails-core by grails.
the class AbstractGrailsArtefactTransformer method performInstanceImplementationInjection.
protected void performInstanceImplementationInjection(SourceUnit source, ClassNode classNode, Map<String, ClassNode> genericsPlaceholders, Class instanceImplementation) {
ClassNode implementationNode;
final ConstructorCallExpression constructorCallExpression;
try {
implementationNode = GrailsASTUtils.replaceGenericsPlaceholders(ClassHelper.make(instanceImplementation), genericsPlaceholders);
constructorCallExpression = GrailsASTUtils.hasZeroArgsConstructor(implementationNode) ? new ConstructorCallExpression(implementationNode, ZERO_ARGS) : null;
} catch (Throwable e) {
// this may well be ok, as we want to be able to compile against, for example, non servlet environments. In this case just bail out.
return;
}
String apiInstanceProperty = INSTANCE_PREFIX + instanceImplementation.getSimpleName();
Expression apiInstance = new VariableExpression(apiInstanceProperty, implementationNode);
if (requiresStaticLookupMethod()) {
final String lookupMethodName = CURRENT_PREFIX + instanceImplementation.getSimpleName();
MethodNode lookupMethod = createStaticLookupMethod(classNode, implementationNode, apiInstanceProperty, lookupMethodName);
apiInstance = new MethodCallExpression(new ClassExpression(classNode), lookupMethodName, ZERO_ARGS);
((MethodCallExpression) apiInstance).setMethodTarget(lookupMethod);
} else if (requiresAutowiring()) {
PropertyNode propertyNode = new PropertyNode(apiInstanceProperty, Modifier.PUBLIC, implementationNode, classNode, constructorCallExpression, null, null);
propertyNode.addAnnotation(AUTO_WIRED_ANNOTATION);
if (getMarkerAnnotation() != null) {
propertyNode.addAnnotation(getMarkerAnnotation());
}
classNode.addProperty(propertyNode);
} else {
FieldNode fieldNode = classNode.getField(apiInstanceProperty);
if (fieldNode == null || (Modifier.isPrivate(fieldNode.getModifiers()) && !fieldNode.getDeclaringClass().equals(classNode))) {
fieldNode = new FieldNode(apiInstanceProperty, PRIVATE_STATIC_MODIFIER, implementationNode, classNode, constructorCallExpression);
classNode.addField(fieldNode);
}
}
while (!implementationNode.equals(AbstractGrailsArtefactTransformer.OBJECT_CLASS)) {
List<MethodNode> declaredMethods = implementationNode.getMethods();
for (MethodNode declaredMethod : declaredMethods) {
if (GrailsASTUtils.isConstructorMethod(declaredMethod)) {
GrailsASTUtils.addDelegateConstructor(classNode, declaredMethod, genericsPlaceholders);
} else if (isCandidateInstanceMethod(classNode, declaredMethod)) {
addDelegateInstanceMethod(classNode, apiInstance, declaredMethod, getMarkerAnnotation(), genericsPlaceholders);
}
}
implementationNode = implementationNode.getSuperClass();
}
performInjectionInternal(apiInstanceProperty, source, classNode);
}
use of org.codehaus.groovy.ast.expr.MethodCallExpression in project grails-core by grails.
the class AbstractGrailsArtefactTransformer method performStaticImplementationInjection.
protected void performStaticImplementationInjection(ClassNode classNode, Map<String, ClassNode> genericsPlaceholders, Class staticImplementation) {
ClassNode staticImplementationNode = GrailsASTUtils.replaceGenericsPlaceholders(ClassHelper.make(staticImplementation), genericsPlaceholders);
final List<MethodNode> declaredMethods = staticImplementationNode.getMethods();
final String staticImplementationSimpleName = staticImplementation.getSimpleName();
String apiInstanceProperty = STATIC_PREFIX + staticImplementationSimpleName;
final String lookupMethodName = CURRENT_PREFIX + staticImplementationSimpleName;
if (!requiresStaticLookupMethod()) {
final ConstructorCallExpression constructorCallExpression = new ConstructorCallExpression(staticImplementationNode, ZERO_ARGS);
addApiLookupFieldAndSetter(classNode, staticImplementationNode, apiInstanceProperty, constructorCallExpression);
}
MethodNode lookupMethod = createStaticLookupMethod(classNode, staticImplementationNode, apiInstanceProperty, lookupMethodName);
MethodCallExpression apiLookupMethod = new MethodCallExpression(new ClassExpression(classNode), lookupMethodName, ZERO_ARGS);
apiLookupMethod.setMethodTarget(lookupMethod);
for (MethodNode declaredMethod : declaredMethods) {
if (isStaticCandidateMethod(classNode, declaredMethod)) {
addDelegateStaticMethod(classNode, apiLookupMethod, declaredMethod, genericsPlaceholders);
}
}
}
use of org.codehaus.groovy.ast.expr.MethodCallExpression in project grails-core by grails.
the class ASTValidationErrorsHelper method addGetErrorsMethod.
protected void addGetErrorsMethod(final ClassNode paramTypeClassNode) {
final ASTNode getErrorsMethod = paramTypeClassNode.getMethod(GET_ERRORS_METHOD_NAME, GrailsArtefactClassInjector.ZERO_PARAMETERS);
if (getErrorsMethod == null) {
final BlockStatement getErrorsMethodCode = new BlockStatement();
final Expression initErrorsMethodCallExpression = new MethodCallExpression(new VariableExpression("this"), INIT_ERRORS_METHOD_NAME, EMPTY_TUPLE);
getErrorsMethodCode.addStatement(new ExpressionStatement(initErrorsMethodCallExpression));
final Statement returnStatement = new ReturnStatement(ERRORS_EXPRESSION);
getErrorsMethodCode.addStatement(returnStatement);
paramTypeClassNode.addMethod(new MethodNode(GET_ERRORS_METHOD_NAME, Modifier.PUBLIC, ERRORS_CLASS_NODE, GrailsArtefactClassInjector.ZERO_PARAMETERS, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, getErrorsMethodCode));
}
}
Aggregations