-
Notifications
You must be signed in to change notification settings - Fork 45
/
EPackageService.java
40 lines (36 loc) · 1.4 KB
/
EPackageService.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
/*******************************************************************************
* Copyright (c) 2019, 2024 Obeo.
* 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.emf;
import java.util.Optional;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EPackage.Descriptor;
import org.eclipse.emf.ecore.EPackage.Registry;
/**
* Services related to EPackages.
*
* @author sbegaudeau
*/
public class EPackageService {
public Optional<EPackage> findEPackage(Registry ePackageRegistry, String packageName) {
return ePackageRegistry.values().stream().map(value -> {
EPackage ePackage = null;
if (value instanceof EPackage.Descriptor) {
EPackage.Descriptor descriptor = (Descriptor) value;
ePackage = descriptor.getEPackage();
} else if (value instanceof EPackage) {
ePackage = (EPackage) value;
}
return ePackage;
}).filter(ePackage -> packageName.equals(ePackage.getName())).findFirst();
}
}