-
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.
Merge pull request #758 from eclipse-passage/573296
Bug 573296 - [Passage] rework EMF migration facilities
- Loading branch information
Showing
6 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
.../org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/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.resource; | ||
|
||
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(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ExtractResource.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,41 @@ | ||
/******************************************************************************* | ||
* 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.resource; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
|
||
/** | ||
* Extracts {@link Resource} from the given object | ||
* | ||
* @since 2.0 | ||
* | ||
*/ | ||
public final class ExtractResource implements Function<Object, Optional<Resource>> { | ||
|
||
@Override | ||
public Optional<Resource> apply(Object object) { | ||
if (object instanceof EObject) { | ||
EObject eObject = (EObject) object; | ||
return Optional.ofNullable(eObject.eResource()); | ||
} | ||
if (object instanceof Resource) { | ||
return Optional.of((Resource) object); | ||
} | ||
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