Skip to content

Commit

Permalink
Add util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
grbeni committed Feb 11, 2022
1 parent 97769d0 commit 2c3e069
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ class GammaEcoreUtil {
return contents
}

def <T extends EObject> T getFirstOfAllContentsOfType(EObject object, Class<T> type) {
val contents = newLinkedList
contents += object.eContents
while (!contents.empty) {
val content = contents.poll
if (type.isInstance(content)) {
return content as T
}
else {
contents += content.eContents
}
}
return null
}

def boolean containsTransitively(EObject potentialContainer, EObject object) {
if (potentialContainer === null || object === null) {
return false
Expand Down Expand Up @@ -318,6 +333,10 @@ class GammaEcoreUtil {
def EObject normalLoad(String parentFolder, String fileName, ResourceSet resourceSet) {
return URI.createFileURI(parentFolder + File.separator + fileName).normalLoad(resourceSet)
}

def void resolveAll(ResourceSet resourceSet) {
EcoreUtil.resolveAll(resourceSet)
}

def Resource normalSave(ResourceSet resourceSet, EObject rootElem, URI uri) {
val resource = resourceSet.createResource(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class JavaUtil {
return IterableExtensions.flatten(inputs).toList
}

def <T> T getFirstOfType(Iterable<? super T> collection, Class<T> clazz) {
for (element : collection) {
if (clazz.isInstance(element)) {
return element as T
}
}
}

def boolean isUnique(Iterable<?> collection) {
val set = newHashSet
for (element : collection) {
Expand Down

0 comments on commit 2c3e069

Please sign in to comment.