本文整理汇总了Java中org.eclipse.emf.codegen.ecore.genmodel.GenModel类的典型用法代码示例。如果您正苦于以下问题:Java GenModel类的具体用法?Java GenModel怎么用?Java GenModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenModel类属于org.eclipse.emf.codegen.ecore.genmodel包,在下文中一共展示了GenModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadGenmodel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
private GenModel loadGenmodel(String path) {
try {
if (!EPackage.Registry.INSTANCE.containsKey(GenModelPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("genmodel", new XMIResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
URI uri = URI.createURI(path);
Resource pkg = rs.getResource(uri, true);
return (GenModel) pkg.getContents().get(0);
} catch (Exception e) {
// ...
}
return null;
}
示例2: generateEMFCode
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* TODO merge monitor
*/
private void generateEMFCode(String genModelPath) throws InvocationTargetException, InterruptedException {
/*
* Generate model & edit
*/
List<URI> uris = new ArrayList<URI>();
uris.add(URI.createFileURI(genModelPath));
List<GenModel> genModels = GeneratorUIUtil.loadGenModels(new NullProgressMonitor(), uris, shell);
GeneratorUIUtil.GeneratorOperation editOp = new GeneratorUIUtil.GeneratorOperation(shell);
editOp.addGeneratorAndArguments(GenModelUtil.createGenerator(genModels.get(0)), genModels.get(0),
"org.eclipse.emf.codegen.ecore.genmodel.generator.EditProject", "Edit");
editOp.addGeneratorAndArguments(GenModelUtil.createGenerator(genModels.get(0)), genModels.get(0),
"org.eclipse.emf.codegen.ecore.genmodel.generator.ModelProject", "Model");
ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell);
progressMonitorDialog.run(true, true, editOp);
}
示例3: loadReferencedGenModels
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* Use {@link GenModelAccess#getGenPackage(EPackage)}
*/
@Deprecated
protected List<GenPackage> loadReferencedGenModels(ResourceSet rs) {
List<GenPackage> result = Lists.newArrayList();
if (getReferencedGenModels() != null) {
for (String uri : getReferencedGenModels().split(",")) {
try {
Resource resource = rs.getResource(URI.createURI(uri.trim()), true);
GenModel genmodel = (GenModel) resource.getContents().get(0);
EList<GenPackage> genPackages = genmodel.getGenPackages();
for (GenPackage genPackage : genPackages) {
genPackage.getEcorePackage().getEClassifiers();
result.add(genPackage);
}
} catch (Exception e) {
log.error("Couldn't find genmodel for uri '" + uri + "'");
throw new WrappedException(e);
}
}
}
return result;
}
示例4: findEPackagesInGenPackages
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
private Map<String, EPackage> findEPackagesInGenPackages(Set<String> packageNsURIs, ResourceSet resourceSet) {
Map<String, EPackage> result = Maps.newHashMap();
for(String nsURI: packageNsURIs) {
Resource resource = GenModelAccess.getGenModelResource(null, nsURI, resourceSet);
if (resource != null) {
for(EObject content: resource.getContents()) {
if (content instanceof GenModel) {
GenModel loadedGenModel = (GenModel) content;
GenPackage genPackage = findGenPackageByNsURI(loadedGenModel, nsURI);
result.put(nsURI, genPackage.getEcorePackage());
break;
}
}
}
}
return result;
}
示例5: getGenPackagesForPackages
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* @since 2.0
*/
protected List<GenPackage> getGenPackagesForPackages(GenModel existingGenModel, Collection<EPackage> packs) {
List<GenPackage> result = Lists.newArrayList();
for (EPackage pkg : packs) {
boolean found = false;
for (GenPackage gp : existingGenModel.getGenPackages())
if (gp.getEcorePackage() != null && gp.getEcorePackage().getNsURI() != null
&& gp.getEcorePackage().getNsURI().equals(pkg.getNsURI()))
found = true;
if (!found)
result.add(GenModelAccess.getGenPackage(pkg, existingGenModel.eResource().getResourceSet()));
}
Collections.sort(result, new Comparator<GenPackage>() {
@Override
public int compare(GenPackage o1, GenPackage o2) {
return EcoreUtil.getURI(o1).toString().compareTo(EcoreUtil.getURI(o2).toString());
}
});
return result;
}
示例6: getSaveAndReconcileGenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* @since 2.0
*/
protected GenModel getSaveAndReconcileGenModel(ResourceSet rs, Grammar grammar, XpandExecutionContext ctx,
List<EPackage> packs) throws ConfigurationException {
GenModel genModel = getGenModel(rs, grammar, ctx, packs);
genModel.initialize(packs);
for (GenPackage genPackage : genModel.getGenPackages()) {
genPackage.setBasePackage(getBasePackage(grammar));
if (isSuppressLoadInitialization()) {
genPackage.setLoadInitialization(false);
}
if (getFileExtensions() != null && packs.contains(genPackage.getEcorePackage())) {
genPackage.setFileExtensions(getFileExtensions());
}
}
Set<EPackage> referencedEPackages = getReferencedEPackages(packs);
List<GenPackage> usedGenPackages = getGenPackagesForPackages(genModel, referencedEPackages);
reconcileMissingGenPackagesInUsedModels(usedGenPackages);
genModel.getUsedGenPackages().addAll(usedGenPackages);
try {
saveResource(genModel.eResource());
} catch (IOException e) {
throw new WrappedException(e);
}
new GenModelHelper().registerGenModel(genModel);
return genModel;
}
示例7: getGenPackage
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
public static GenPackage getGenPackage(EPackage pkg, ResourceSet resourceSet) {
String nsURI = pkg.getNsURI();
String location = null;
if (pkg.eResource() != null && pkg.eResource().getURI() != null)
location = pkg.eResource().getURI().toString();
Resource genModelResource = getGenModelResource(location, nsURI, resourceSet);
if (genModelResource != null) {
for (EObject model : genModelResource.getContents()) {
if (model instanceof GenModel) {
GenPackage genPkg = ((GenModel) model).findGenPackage(pkg);
if (genPkg != null) {
genPkg.getEcorePackage().getEClassifiers();
return genPkg;
}
}
}
throw new RuntimeException("No GenPackage for NsURI " + nsURI + " found in " + genModelResource.getURI());
}
throw new RuntimeException("No GenPackage for NsURI " + nsURI + ".");
}
示例8: findEPackagesInGenPackages
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
private Map<String, EPackage> findEPackagesInGenPackages(final Collection<String> packageNsURIs, final ResourceSet resourceSet) {
final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap();
for (final String nsURI : packageNsURIs) {
{
final Resource resource = GenModelUtil2.getGenModelResource(null, nsURI, resourceSet);
if ((resource != null)) {
final GenModel loadedGenModel = IterableExtensions.<GenModel>head(Iterables.<GenModel>filter(resource.getContents(), GenModel.class));
if ((loadedGenModel != null)) {
final GenPackage genPackage = this.findGenPackageByNsURI(loadedGenModel, nsURI);
result.put(nsURI, genPackage.getEcorePackage());
}
}
}
}
return result;
}
示例9: getSaveAndReconcileGenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
protected GenModel getSaveAndReconcileGenModel(final Grammar grammar, final List<EPackage> packs, final ResourceSet rs) {
final GenModel genModel = this.getGenModel(rs, grammar);
genModel.initialize(packs);
EList<GenPackage> _genPackages = genModel.getGenPackages();
for (final GenPackage genPackage : _genPackages) {
{
genPackage.setBasePackage(this.getBasePackage(grammar));
if (this.suppressLoadInitialization) {
genPackage.setLoadInitialization(false);
}
if (((!this.getLanguage().getFileExtensions().isEmpty()) && packs.contains(genPackage.getEcorePackage()))) {
genPackage.setFileExtensions(IterableExtensions.join(this.getLanguage().getFileExtensions(), ","));
}
}
}
final Set<EPackage> referencedEPackages = this.getReferencedEPackages(packs);
final List<GenPackage> usedGenPackages = this.getGenPackagesForPackages(genModel, referencedEPackages);
this.reconcileMissingGenPackagesInUsedModels(usedGenPackages);
genModel.getUsedGenPackages().addAll(usedGenPackages);
this.saveResource(genModel.eResource());
new GenModelHelper().registerGenModel(genModel);
return genModel;
}
示例10: getGenPackagesForPackages
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
protected List<GenPackage> getGenPackagesForPackages(final GenModel existingGenModel, final Collection<EPackage> packs) {
final ArrayList<GenPackage> result = CollectionLiterals.<GenPackage>newArrayList();
for (final EPackage pkg : packs) {
final Function1<GenPackage, Boolean> _function = (GenPackage it) -> {
EPackage _ecorePackage = it.getEcorePackage();
String _nsURI = null;
if (_ecorePackage!=null) {
_nsURI=_ecorePackage.getNsURI();
}
String _nsURI_1 = pkg.getNsURI();
return Boolean.valueOf(Objects.equal(_nsURI, _nsURI_1));
};
boolean _exists = IterableExtensions.<GenPackage>exists(existingGenModel.getGenPackages(), _function);
boolean _not = (!_exists);
if (_not) {
result.add(GenModelUtil2.getGenPackage(pkg, existingGenModel.eResource().getResourceSet()));
}
}
final Comparator<GenPackage> _function_1 = (GenPackage o1, GenPackage o2) -> {
return EcoreUtil.getURI(o1).toString().compareTo(EcoreUtil.getURI(o2).toString());
};
Collections.<GenPackage>sort(result, _function_1);
return result;
}
示例11: setUri
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>
* Registers all EPackages (transitively) referenced by registered GenModels prior to calling {@link LanguageConfig#setUri(String)}.
*/
@Override
public void setUri(final String uri) {
ResourceSet rs = new ResourceSetImpl();
Set<URI> result = Sets.newHashSet();
@SuppressWarnings("deprecation")
Map<String, URI> genModelLocationMap = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
for (Map.Entry<String, URI> entry : genModelLocationMap.entrySet()) {
Resource resource = GenModelAccess.getGenModelResource(null, entry.getKey(), rs);
if (resource != null) {
for (EObject model : resource.getContents()) {
if (model instanceof GenModel) {
GenModel genModel = (GenModel) model;
result.addAll(getReferencedEPackages(genModel));
}
}
}
}
for (URI u : result) {
addLoadedResource(u.toString());
}
super.setUri(uri);
}
示例12: findGenModelInContainers
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* Given an array of {@link IContainers}, searches through all *.genmodel files in all {@link IFolders}, ignoring nested folders, trying to find a
* {@link GenModel} for the given {@link EPackage}.
*
* @param containers
* To search, may be empty, but must not be {@code null}
* @param baseURI
* of these containers; must not be {@code null}
* @param ePackage
* to find a genmodel for; must not be {@code null}
* @param resourceSet
* to use for resource loading; must not be {@code null}
* @return the genmodel, if found, or {@code null} if not.
* @throws CoreException
* if enumerating folder contents does so
*/
private static GenModel findGenModelInContainers(final IContainer[] containers, final URI baseURI, final EPackage ePackage, final ResourceSet resourceSet) throws CoreException {
Preconditions.checkNotNull(containers);
Preconditions.checkNotNull(baseURI);
Preconditions.checkNotNull(ePackage);
Preconditions.checkNotNull(resourceSet);
final URIConverter uriConverter = resourceSet.getURIConverter();
for (IContainer container : containers) {
if (!(container instanceof IFolder)) {
continue;
}
IResource[] resources = container.members();
for (IResource r : resources) {
if (r.exists() && r instanceof IFile && GENMODEL_EXTENSION.equals(r.getFileExtension())) {
URI uriToTry = uriConverter.normalize(baseURI.appendSegment(URI.encodeSegment(r.getName(), false)));
GenModel result = loadGenModel(uriToTry, ePackage, resourceSet);
if (result != null) {
return result;
}
}
}
}
return null;
}
示例13: createGenModelAdapter
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
@Override
public Adapter createGenModelAdapter() {
if (genModelGeneratorAdapter == null) {
genModelGeneratorAdapter = new GenModelGeneratorAdapter(this) {
@Override
protected void createImportManager(final String packageName, final String className) {
importManager = new ImportManagerHack(packageName, typeMapper);
importManager.addMasterImport(packageName, className);
if (generatingObject != null) {
((GenBase) generatingObject).getGenModel().setImportManager(importManager);
}
}
/**
* We handle this one on our own, see
* {@link org.eclipse.xtext.generator.ecore.CvsIdFilteringGeneratorAdapterFactoryDescriptor.IdFilteringGenModelGeneratorAdapterFactory# createGenModelAdapter()}
* . Note that the original source comment vanishes in de-compiled Java code.
*/
@Override
protected void generateModelPluginProperties(final GenModel genModel, final org.eclipse.emf.common.util.Monitor monitor) {
// Do nothing.
}
};
}
return genModelGeneratorAdapter;
}
示例14: preInvoke
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
/**
* Registers the given source-paths in the generator.
*/
@Override
public void preInvoke() {
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.getResource(URI.createURI(genModel), true);
for (EObject obj : resource.getContents()) {
if (obj instanceof GenModel) {
GenModel model = (GenModel) obj;
addSourcePathForPlugin(model.getModelPluginID());
for (GenPackage usedPackage : model.getUsedGenPackages()) {
addSourcePathForPlugin(usedPackage.getGenModel().getModelPluginID());
}
}
}
LOGGER.info("Registered source path to discover custom classes: " + Joiner.on(", ").join(this.srcPaths));
}
示例15: createGenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入依赖的package包/类
public static void createGenModel(final EPackage rootPackage, final IPath ecorePath, final IResource genmodelResource) {
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.setComplianceLevel(GenJDKLevel.JDK60_LITERAL);
genModel.setModelDirectory(ecorePath.removeLastSegments(1).toString());
genModel.getForeignModel().add(ecorePath.lastSegment());
genModel.setModelName(rootPackage.getName());
genModel.setRootExtendsInterface("");
genModel.initialize(Collections.singleton(rootPackage));
GenPackage genPackage = (GenPackage) genModel.getGenPackages().get(0);
genPackage.setPrefix("");
try {
URI genModelURI = URI.createURI(genmodelResource.getLocationURI().toString());
final XMIResourceImpl genModelResource = new XMIResourceImpl(genModelURI);
genModelResource.getContents().add(genModel);
genModelResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}