本文整理汇总了Java中org.eclipse.emf.codegen.ecore.genmodel.GenModel.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java GenModel.initialize方法的具体用法?Java GenModel.initialize怎么用?Java GenModel.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.emf.codegen.ecore.genmodel.GenModel
的用法示例。
在下文中一共展示了GenModel.initialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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();
}
}
示例4: generate
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入方法依赖的package包/类
public VirtualFile generate(VirtualFile basedir) throws DatabaseException {
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.setRuntimeVersion(GenRuntimeVersion.EMF25);
genModel.setComplianceLevel(GenJDKLevel.JDK60_LITERAL);
genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
genModel.setRootExtendsClass("org.bimserver.emf.IdEObjectImpl");
genModel.setRootExtendsInterface("org.bimserver.emf.IdEObject");
genModel.setSuppressContainment(true);
genModel.setCodeFormatting(true);
genModel.setCopyrightText(StringUtils.readFromFile(new File("copyright.txt")));
genModel.setCanGenerate(true);
genModel.setModelDirectory("test");
genModel.setModelName("model name");
genModel.setForceOverwrite(true);
genModel.setSuppressNotification(false);
genModel.setContainmentProxies(false);
genModel.setBinaryCompatibleReflectiveMethods(false);
genModel.setPublicConstructors(false);
genModel.setMinimalReflectiveMethods(true); // More code, but faster
genModel.setUpdateClasspath(false);
genModel.initialize(schema.getEPackages());
GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
Generator generator = new Generator();
generator.setInput(genModel);
generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, new BasicMonitor.Printing(System.out));
// List<GenPackage> genPackages = createGenPackages(genModel, basedir);
// generatePackages(genModel, genPackages, basedir);
return basedir;
}
示例5: createGenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入方法依赖的package包/类
private GenModel createGenModel(Resource resource, IPath ecoreLocation, String genModelName) {
// Get root package
EPackage rootPackage = (EPackage)resource.getContents().get(0);
// Create genModel and initialize with referred ecore model
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.getForeignModel().add(ecoreLocation.lastSegment());
genModel.initialize(Collections.singleton(rootPackage));
// Set properties for GenModel
genModel.setComplianceLevel(GenJDKLevel.JDK70_LITERAL);
genModel.setCopyrightText("");
genModel.setLanguage("EN");
genModel.setModelName(genModelName + " genmodel");
genModel.setModelDirectory(project.getName() + "/src");
genModel.setModelPluginID(project.getName());
genModel.setRootExtendsInterface("");
genModel.setSuppressEMFTypes(true);
genModel.setImportOrganizing(true);
// Set properties for generated package
GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
genPackage.setPrefix(genModelName);
genPackage.setBasePackage(project.getName().substring(0, project.getName().lastIndexOf('.')));
genPackage.getEcorePackage().setName(""); //TODO
genPackage.getEcorePackage().setNsPrefix(""); //TODO
genPackage.getEcorePackage().setNsURI(""); //TODO
return genModel;
}
示例6: createGenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入方法依赖的package包/类
public static GenPackage createGenModel(final EPackage rootPackage, final String ecoreLocation, String basePackage,
Collection<GenPackage> usedGenPackages) throws IOException {
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.setComplianceLevel(GenJDKLevel.JDK80_LITERAL);
genModel.setCopyrightText(
"Copyright (c) 2015-2017 Obeo, Inria\n" +
"All rights reserved. This program and the accompanying materials\n" +
"are made available under the terms of the Eclipse Public License v1.0\n" +
"which accompanies this distribution, and is available at\n" +
"http://www.eclipse.org/legal/epl-v10.html\n" +
" \n" +
"Contributors:\n" +
"- William Piers <[email protected]>\n" +
"- Philippe Merle <[email protected]>\n"+
"- Faiez Zalila <[email protected]>"
);
// Added to generate java code corresponding to OCL constraints defined in the OCCI extension
// GenAnnotation genannotation = GenModelFactory.eINSTANCE.createGenAnnotation();
// genannotation.setSource("http://www.eclipse.org/OCL/GenModel");
// genannotation.getDetails().put("Use Delegates", "false");
// genModel.getGenAnnotations().add(genannotation);
String modelPluginId = new Path(ecoreLocation).removeLastSegments(2).lastSegment().toString();
String editPluginId = modelPluginId + ".edit";
String editorPluginId = modelPluginId + ".editor";
String testsPluginId = modelPluginId + ".tests";
genModel.setModelDirectory('/' + modelPluginId + "/src-gen");
genModel.setEditDirectory('/' + editPluginId + "/src-gen");
genModel.setEditorDirectory('/' + editorPluginId + "/src-gen");
genModel.setTestsDirectory('/' + testsPluginId + "/src");
genModel.getForeignModel().add(new Path(ecoreLocation).lastSegment());
genModel.setModelName(ConverterUtils.toU1Case(rootPackage.getName()));
genModel.setModelPluginID(modelPluginId);
genModel.setEditPluginID(editPluginId);
genModel.setEditorPluginID(editorPluginId);
genModel.setTestsPluginID(testsPluginId);
genModel.setRootExtendsInterface("org.eclipse.emf.ecore.EObject");
// Activate code generation for Ecore reflective and dynamic invocation of OCCI actions.
genModel.setOperationReflection(true);
genModel.getUsedGenPackages().addAll(usedGenPackages);
genModel.initialize(Collections.singleton(rootPackage));
GenPackage genPackage = genModel.getGenPackages().get(0);
genPackage.setPrefix(ConverterUtils.toU1Case(rootPackage.getNsPrefix()));
genPackage.setBasePackage(basePackage);
genPackage.setLoadInitialization(false);
URI genModelURI = URI
.createFileURI(new Path(ecoreLocation).removeFileExtension().addFileExtension("genmodel").toString());
final XMIResourceImpl genModelResource = new XMIResourceImpl(genModelURI);
genModelResource.getContents().add(genModel);
genModelResource.save(Collections.EMPTY_MAP);
return genPackage;
}
示例7: createPropertiesDefinition
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入方法依赖的package包/类
public static String createPropertiesDefinition(Classifier classifier) throws Exception {
EPackage _package = EcoreFactory.eINSTANCE.createEPackage();
EClass propertyDefinition = EcoreFactory.eINSTANCE.createEClass();
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
ExtendedMetaData extendedMetaData = genModel.getExtendedMetaData();
List<EStructuralFeature> features = new ArrayList<EStructuralFeature>();
String propertiesDefinition = "";
for(Property property : classifier.getAttributes()) {
// consider attributes only if they aren't members of an association
if(property.getAssociation() == null) {
EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute();
attribute.setName(property.getName());
attribute.setUnsettable(true);
// create an EEnum in case of enumeration
if(property.getType() instanceof Enumeration) {
Enumeration enumeration = (Enumeration) property.getType();
EEnum eenumeration = EcoreFactory.eINSTANCE.createEEnum();
eenumeration.setName(enumeration.getName());
int literalValue = 0;
for(EnumerationLiteral literal : enumeration.getOwnedLiterals()) {
EEnumLiteral eliteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eliteral.setName(literal.getName());
eliteral.setValue(literalValue);
literalValue++;
eenumeration.getELiterals().add(eliteral);
}
_package.getEClassifiers().add(eenumeration);
attribute.setEType(eenumeration);
}
else {
attribute.setEType(XMLTypePackage.eINSTANCE.getString());
}
propertyDefinition.getEStructuralFeatures().add(attribute);
extendedMetaData.setFeatureKind(attribute, ExtendedMetaData.ELEMENT_FEATURE);
features.add(attribute);
}
}
if(!features.isEmpty()) {
// first step: create an Ecore metamodel
URI uri = URI.createFileURI(new File(Path + classifier.getName() + Ecore_Model_Fragment).getAbsolutePath());
Resource resource = Resource_Set.createResource(uri);
_package.setName(classifier.getName() + "Properties");
_package.setNsPrefix(classifier.getName() + "Properties");
_package.setNsURI("http://" + classifier.getName() + "Properties");
resource.getContents().add(_package);
propertyDefinition.setName("Properties");
_package.getEClassifiers().add(propertyDefinition);
// second step: derive the GenModel from the metamodel
genModel.setComplianceLevel(GenJDKLevel.JDK70_LITERAL);
genModel.setModelDirectory("");
genModel.setModelName(_package.getName());
genModel.initialize(Collections.singleton(_package));
// third step: export the XSD from the GenModel
XSDExporter modelExporter = new XSDExporter();
modelExporter.setGenModel(genModel);
modelExporter.getEPackages().add(_package);
EPackageConvertInfo convertInfo = modelExporter.getEPackageConvertInfo(_package);
convertInfo.setConvert(true);
EPackageExportInfo exportInfo = modelExporter.getEPackageExportInfo(_package);
exportInfo.setArtifactLocation(Path + classifier.getName() + Xsd_Model_Fragment);
modelExporter.export(null);
// the name of the properties definition; it allows node types to reference it
propertiesDefinition = classifier.getName() + "Properties";
}
return propertiesDefinition;
}
示例8: createGenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenModel; //导入方法依赖的package包/类
public void createGenModel(String ecorepath, String outputPath) {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"ecore",
new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"genmodel",
new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
IPath ecorePath = new Path(ecorepath);
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getURIConverter().getURIMap()
.putAll(EcorePlugin.computePlatformURIMap());
URI ecoreURI = URI.createFileURI(ecorePath.toString());
Resource resource = resourceSet.getResource(ecoreURI, true);
EPackage ePackage = (EPackage) resource.getContents().get(0);
IPath genModelPath = ecorePath.removeFileExtension().addFileExtension(
"genmodel");
URI genModelURI = URI.createFileURI(genModelPath.toString());
Resource genModelResource = Resource.Factory.Registry.INSTANCE
.getFactory(genModelURI).createResource(genModelURI);
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModelResource.getContents().add(genModel);
resourceSet.getResources().add(genModelResource);
genModel.setModelDirectory("/" + outputPath + "/src");
genModel.getForeignModel().add(ecorePath.toString());
genModel.initialize(Collections.singleton(ePackage));
GenPackage genPackage = (GenPackage) genModel.getGenPackages().get(0);
genModel.setModelName(genModelURI.trimFileExtension().lastSegment());
genPackage.setPrefix(genPackage.getNSName());
genPackage.setBasePackage("");
File f = new File(outputPath);
deleteDirectory(f);
f.mkdir();
EcorePlugin.getPlatformResourceMap().put(outputPath,
URI.createFileURI(f.getAbsolutePath() + "/"));
this.generate(genModel);
}