Skip to content

Commit

Permalink
Back to ModelUtils for EPackageProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Degueule authored and François Boschet committed Aug 26, 2015
1 parent fbe0655 commit 62c89e5
Showing 1 changed file with 4 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,28 @@ import fr.inria.diverse.melange.ast.LanguageExtensions
import fr.inria.diverse.melange.ast.ModelTypeExtensions
import fr.inria.diverse.melange.eclipse.EclipseProjectHelper
import fr.inria.diverse.melange.lib.EcoreExtensions
import fr.inria.diverse.melange.lib.ModelUtils
import fr.inria.diverse.melange.metamodel.melange.Inheritance
import fr.inria.diverse.melange.metamodel.melange.Metamodel
import fr.inria.diverse.melange.metamodel.melange.ModelType
import fr.inria.diverse.melange.metamodel.melange.ModelingElement
import java.util.List
import org.apache.log4j.Logger
import org.eclipse.emf.codegen.ecore.genmodel.GenModel
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.EPackage
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtext.naming.IQualifiedNameProvider

@Singleton
class EPackageProvider
{
ResourceSet rs = new ResourceSetImpl
@Inject ModelUtils modelUtils
@Inject extension EcoreExtensions
@Inject extension ModelTypeExtensions
@Inject extension LanguageExtensions
@Inject extension EclipseProjectHelper
@Inject extension IQualifiedNameProvider
private ListMultimap<String, EPackage> packages = ArrayListMultimap.create
private ListMultimap<String, GenModel> genmodels = ArrayListMultimap.create
private final Logger log = Logger.getLogger(EPackageProvider)

def void reset() {
packages = ArrayListMultimap.create
Expand All @@ -53,7 +49,7 @@ class EPackageProvider

switch (m) {
case m.ecoreUri !== null: {
val root = loadPkg(m.ecoreUri.toPlatformURI)
val root = modelUtils.loadPkg(m.ecoreUri.toPlatformURI)

if (root !== null) {
val pkgs = newArrayList
Expand Down Expand Up @@ -109,7 +105,7 @@ class EPackageProvider
mm.genmodelUris += mm.owningLanguage.externalGenmodelUri
}
mm.genmodelUris.forEach[
val gm = loadGenmodel(it.toPlatformURI)
val gm = modelUtils.loadGenmodel(it.toPlatformURI)

if (gm !== null)
genmodels.put(mm.fqn, gm)
Expand Down Expand Up @@ -143,32 +139,6 @@ class EPackageProvider
return mt.fullyQualifiedName?.toString
}

private def EPackage loadPkg(String path) {
try {
val uri = URI.createURI(path)
val pkg = rs.getResource(uri, true)

return pkg.contents.head as EPackage
} catch (Exception e) {
log.error(e)
}

return null
}

private def GenModel loadGenmodel(String path) {
try {
val uri = URI.createURI(path)
val pkg = rs.getResource(uri, true)

return pkg.contents.head as GenModel
} catch (Exception e) {
log.error(e)
}

return null
}

private def String toPlatformURI(String uri) {
return '''«IF uri.startsWith("/")»platform:/resource«ENDIF»«uri»'''
}
Expand Down

0 comments on commit 62c89e5

Please sign in to comment.