-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 573296 - [Passage] rework EMF migration facilities
Extract "ExtractEObject" Signed-off-by: Alexander Fedorov <[email protected]>
- Loading branch information
1 parent
18cf6d5
commit 7925036
Showing
3 changed files
with
72 additions
and
35 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...les/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/ecore/ExtractEObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.emf.ecore; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.emf.common.util.EList; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
|
||
/** | ||
* Extracts {@link EObject} from the given object | ||
* | ||
* @since 2.0 | ||
* | ||
*/ | ||
public final class ExtractEObject implements Function<Object, Optional<EObject>> { | ||
|
||
@Override | ||
public Optional<EObject> apply(Object object) { | ||
if (object instanceof EObject) { | ||
return Optional.of((EObject) object); | ||
} | ||
if (object instanceof Resource) { | ||
Resource resource = (Resource) object; | ||
EList<EObject> contents = resource.getContents(); | ||
if (!contents.isEmpty()) { | ||
return Optional.of(contents.get(0)); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters