-
Notifications
You must be signed in to change notification settings - Fork 3
/
IsUniqueService.java
65 lines (57 loc) · 2.38 KB
/
IsUniqueService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.acceleo.query.services;
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.JavaMethodService;
import org.eclipse.acceleo.query.runtime.impl.LambdaValue;
import org.eclipse.acceleo.query.runtime.impl.ValidationServices;
import org.eclipse.acceleo.query.validation.type.IType;
import org.eclipse.acceleo.query.validation.type.LambdaType;
/**
* {@link JavaMethodService} for services taking a {@link LambdaValue} as second parameter.
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
public class IsUniqueService extends JavaMethodService {
/**
* Creates a new service instance given a method and an instance.
*
* @param method
* the method that realizes the service
* @param serviceInstance
* the instance on which the service must be called
* @param forWorkspace
* tells if the {@link IService} will be used in a workspace
*/
public IsUniqueService(Method method, Object serviceInstance, boolean forWorkspace) {
super(method, serviceInstance, forWorkspace);
}
@Override
public Set<IType> getType(Call call, ValidationServices services, IValidationResult validationResult,
IReadOnlyQueryEnvironment queryEnvironment, List<IType> argTypes) {
final Set<IType> result;
if (argTypes.get(1) instanceof LambdaType) {
result = super.getType(call, services, validationResult, queryEnvironment, argTypes);
} else {
result = new LinkedHashSet<>();
result.add(services.nothing("The %s service takes a lambda as parameter: v | v...", call
.getServiceName()));
}
return result;
}
}