| /******************************************************************************* |
| * 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.security.Provider.Service; |
| 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.IValidationResult; |
| import org.eclipse.acceleo.query.runtime.impl.ValidationServices; |
| import org.eclipse.acceleo.query.validation.type.ICollectionType; |
| import org.eclipse.acceleo.query.validation.type.IType; |
| |
| /** |
| * A {@link Service} returning the raw type of the first argument {@link ICollectionType}. |
| * |
| * @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a> |
| */ |
| public class FirstCollectionTypeService extends AbstractCollectionService { |
| |
| /** |
| * Creates a new service instance given a method and an instance. |
| * |
| * @param serviceMethod |
| * the method that realizes the service |
| * @param serviceInstance |
| * the instance on which the service must be called |
| */ |
| public FirstCollectionTypeService(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>(); |
| result.add(createReturnCollectionWithType(queryEnvironment, ((ICollectionType)argTypes.get(0)) |
| .getCollectionType())); |
| return result; |
| } |
| |
| } |