blob: f9405fc1b7caac16d4776b6769e1813f79c3993c (
plain) (
blame)
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
|
/*
* SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.language.scoping;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.ISelectable;
import tools.refinery.language.naming.NamingUtil;
import java.util.List;
public class NoFullyQualifiedNamesSelectable implements ISelectable {
private final ISelectable delegateSelectable;
// {@link com.google.common.base.Predicate} required by Xtext API.
@SuppressWarnings("squid:S4738")
private final Predicate<IEObjectDescription> filter =
eObjectDescription -> !NamingUtil.isFullyQualified(eObjectDescription.getName());
public NoFullyQualifiedNamesSelectable(ISelectable delegateSelectable) {
this.delegateSelectable = delegateSelectable;
}
@Override
public boolean isEmpty() {
return delegateSelectable.isEmpty();
}
@Override
public Iterable<IEObjectDescription> getExportedObjects() {
return filter(delegateSelectable.getExportedObjects());
}
@Override
public Iterable<IEObjectDescription> getExportedObjects(EClass type, QualifiedName name, boolean ignoreCase) {
if (NamingUtil.isFullyQualified(name)) {
return List.of();
}
return delegateSelectable.getExportedObjects(type, name, ignoreCase);
}
@Override
public Iterable<IEObjectDescription> getExportedObjectsByType(EClass type) {
return filter(delegateSelectable.getExportedObjectsByType(type));
}
@Override
public Iterable<IEObjectDescription> getExportedObjectsByObject(EObject object) {
return filter(delegateSelectable.getExportedObjectsByObject(object));
}
private Iterable<IEObjectDescription> filter(Iterable<IEObjectDescription> eObjectDescriptions) {
return Iterables.filter(eObjectDescriptions, filter);
}
}
|