blob: 02c2f59e633883f37c279735aeb0d0afd5b0a7bf [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2021 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.acceleo.query.services.collection;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.acceleo.query.ast.Call;
import org.eclipse.acceleo.query.runtime.IReadOnlyQueryEnvironment;
import org.eclipse.acceleo.query.runtime.IService;
import org.eclipse.acceleo.query.runtime.IValidationResult;
import org.eclipse.acceleo.query.runtime.impl.ValidationServices;
import org.eclipse.acceleo.query.validation.type.IType;
import org.eclipse.acceleo.query.validation.type.LambdaType;
/**
* Exists {@link IService}.
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
public class BooleanLambdaService extends AbstractCollectionService {
/**
* Constructor.
*
* @param serviceMethod
* the method that realizes the service
* @param serviceInstance
* the instance on which the service must be called
*/
public BooleanLambdaService(Method serviceMethod, Object serviceInstance) {
super(serviceMethod, serviceInstance);
}
@Override
public Set<IType> getType(Call call, ValidationServices services, IValidationResult validationResult,
IReadOnlyQueryEnvironment queryEnvironment, List<IType> argTypes) {
final Set<IType> result = new LinkedHashSet<IType>();
final LambdaType lambdaType = (LambdaType)argTypes.get(1);
final Object lambdaExpressionType = lambdaType.getLambdaExpressionType().getType();
if (isBooleanType(queryEnvironment, lambdaExpressionType)) {
result.addAll(super.getType(call, services, validationResult, queryEnvironment, argTypes));
} else {
result.add(services.nothing("expression in %s must return a boolean", getName()));
}
return result;
}
}