本文整理匯總了Java中org.eclipse.emf.ecore.EcoreFactory類的典型用法代碼示例。如果您正苦於以下問題:Java EcoreFactory類的具體用法?Java EcoreFactory怎麽用?Java EcoreFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EcoreFactory類屬於org.eclipse.emf.ecore包,在下文中一共展示了EcoreFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testTwo
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
public void testTwo() throws Exception {
new TestHelper() {
Resource ecoreResource;
@Override
void loadResources(ResourceSet resourceSet) {
ecoreResource = resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"), true);
}
@Override
void makeChanges() {
EPackage ePackage = (EPackage) ecoreResource.getContents().get(0);
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
ePackage.getEClassifiers().add(5, eClass);
eClass.setName("NewClass");
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eClass.getEAnnotations().add(eAnnotation);
eAnnotation.getContents().add(0, ePackage.getEClassifiers().get(2));
}
}.doit();
}
示例2: createEnumerationType
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
private EEnum createEnumerationType(EnumerationType type) {
EEnum eenum = EcoreFactory.eINSTANCE.createEEnum();
eenum.setName(type.getName());
int value = 0;
for (EnumerationLiteral literal : type.getLiterals()) {
EEnumLiteral eenumliteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eenum.getELiterals().add(eenumliteral);
eenumliteral.setName(literal.getName());
eenumliteral.setLiteral(literal.getName());
eenumliteral.setValue(value);
value++;
if (literal.getDocumentation() != null) {
attachInfo(eenumliteral, literal.getDocumentation());
}
}
if (type.getDocumentation() != null) {
attachInfo(eenum, type.getDocumentation());
}
return eenum;
}
示例3: createStringType
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
private EDataType createStringType(StringType type) {
EDataType edatatype = EcoreFactory.eINSTANCE.createEDataType();
edatatype.setName(type.getName());
edatatype.setInstanceTypeName("java.lang.String");
if (type.getDocumentation() != null) {
attachInfo(edatatype, type.getDocumentation());
}
if (type.isSetLength() || type.isSetMaxLength() || type.isSetMinLength() || type.getPattern() != null) {
EAnnotation eannotation = EcoreFactory.eINSTANCE.createEAnnotation();
edatatype.getEAnnotations().add(eannotation);
eannotation.setSource("http:///org/eclipse/emf/ecore/util/ExtendedMetaData");
if (type.isSetLength())
eannotation.getDetails().put("length", Integer.toString(type.getLength()));
if (type.isSetMaxLength())
eannotation.getDetails().put("maxLength", Integer.toString(type.getMaxLength()));
if (type.isSetMinLength())
eannotation.getDetails().put("minLength", Integer.toString(type.getMinLength()));
if (type.getPattern() != null) {
if (type.getPattern() != "")
eannotation.getDetails().put("pattern", type.getPattern());
}
}
return edatatype;
}
示例4: convertConstraints
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
protected void convertConstraints(EClass eClass, Type type) {
if (type.getConstraints().size() > 0) {
// EMF Annotation
EAnnotation annotation_emf = EcoreFactory.eINSTANCE.createEAnnotation();
annotation_emf.setSource("http://www.eclipse.org/emf/2002/Ecore");
String value = "";
// OCL Annotation
EAnnotation annotation_ocl = EcoreFactory.eINSTANCE.createEAnnotation();
annotation_ocl.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
for (Constraint constraint : type.getConstraints()) {
annotation_ocl.getDetails().put(constraint.getName(),
convertbody(constraint.getBody(), (Extension) type.eContainer()));
if (value.equals("")) {
value += constraint.getName();
} else {
value += " ";
value += constraint.getName();
}
// convertbody(constraint.getBody(), (Extension)
// type.eContainer());
}
annotation_emf.getDetails().put("constraints", value);
eClass.getEAnnotations().add(annotation_emf);
eClass.getEAnnotations().add(annotation_ocl);
}
}
示例5: convertAction
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
/**
* Convert an OCCI action to an Ecore operation.
*
* @param action
* the OCCI action to convert.
* @return the resulting Ecore operation.
*/
protected EOperation convertAction(Action action) {
// Create the Ecore operation.
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
// Set the name of the Ecore operation.
eOperation.setName(ConverterUtils.formatName(action.getTerm()));
// Convert all attributes of the OCCI action.
for (Attribute attribute : action.getAttributes()) {
// Each OCCI attribute of the OCCI action is converted to an Ecore
// parameter of the Ecore operation.
EParameter convertParameter = convertParameter(attribute);
if (convertParameter != null) {
// Add the Ecore parameter to the Ecore operation.
eOperation.getEParameters().add(convertParameter);
}
}
attachInfo(eOperation, action.getTitle());
return eOperation;
}
示例6: convertParameter
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
/**
* Convert an OCCI action's attribute to an Ecore operation parameter.
*
* @param attribute
* the OCCI attribute to convert.
* @return the resulting Ecore operation parameter.
*/
protected EParameter convertParameter(Attribute attribute) {
// Create an Ecore parameter.
EParameter eParam = EcoreFactory.eINSTANCE.createEParameter();
// Set the name of the Ecore parameter.
eParam.setName(Occi2Ecore.convertOcciAttributeName2EcoreAttributeName(attribute.getName()));
// Set the type of the Ecore parameter.
eParam.setEType(getMappedType(attribute.getType()));
// If the OCCI attribute is required then the Ecore parameter is also
// required.
if (attribute.isRequired()) {
eParam.setLowerBound(1);
}
attachInfo(eParam, attribute.getDescription());
return eParam;
}
示例7: setBirthdayOfFatherBart
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
public void setBirthdayOfFatherBart(PersonRegister register) {
Calendar cal = Calendar.getInstance();
Date date;
// Person bart = getFromRegister("Simpson, Bart", register);
// cal.set(2013, Calendar.MARCH, 9, 10, 11, 12);
// date = cal.getTime();
// bart.setBirthday(date);
List<Person> barts = getAllFromRegister("Simpson, Bart", register);
Date defaultDate = (Date) EcoreFactory.eINSTANCE.createFromString(EcorePackage.eINSTANCE.getEDate(), "0000-1-1");
for (Person bart : barts) {
if (bart.getBirthday().equals(defaultDate)) {
cal.set(2013, Calendar.MARCH, 9, 10, 11, 12);
date = cal.getTime();
bart.setBirthday(date);
return;
}
}
}
示例8: testNestedPackage
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
@Test public void testNestedPackage() throws Exception {
Resource resource = new XMIResourceImpl();
EPackage parent = EcoreFactory.eINSTANCE.createEPackage();
parent.setName("parent");
parent.setNsURI("http://parent");
EPackage child = EcoreFactory.eINSTANCE.createEPackage();
child.setName("child");
child.setNsURI("http://child");
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Test");
child.getEClassifiers().add(eClass);
parent.getESubpackages().add(child);
resource.getContents().add(parent);
Map<QualifiedName, IEObjectDescription> index = createIndex(resource);
checkEntry(index, parent, false, "parent");
checkEntry(index, child, false, "parent", "child");
checkEntry(index, eClass, false, "parent", "child", "Test");
checkEntry(index, parent, true, "http://parent");
checkEntry(index, child, true, "http://child");
checkEntry(index, eClass, true, "http://child", "Test");
assertEquals(6,index.size());
}
示例9: testMissingMiddleName
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
@Test public void testMissingMiddleName() {
Resource resource = new XMIResourceImpl();
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("test");
ePackage.setNsURI("http://test");
EClass unnamedEClass = EcoreFactory.eINSTANCE.createEClass();
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("test");
unnamedEClass.getEStructuralFeatures().add(eAttribute);
ePackage.getEClassifiers().add(unnamedEClass);
resource.getContents().add(ePackage);
Map<QualifiedName, IEObjectDescription> index = createIndex(resource);
checkEntry(index, ePackage, false, "test");
checkEntry(index, ePackage, true, "http://test");
assertEquals(2,index.size());
unnamedEClass.setName("Test");
index = createIndex(resource);
checkEntry(index, ePackage, false, "test");
checkEntry(index, ePackage, true, "http://test");
checkEntry(index, unnamedEClass, false, "test", "Test");
checkEntry(index, unnamedEClass, true, "http://test", "Test");
checkEntry(index, eAttribute, false, "test", "Test", "test");
checkEntry(index, eAttribute, true, "http://test", "Test", "test");
assertEquals(6,index.size());
}
示例10: createFeatureWith
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
private EStructuralFeature createFeatureWith(String featureName, EClassifier featureClassifier,
boolean isMultivalue, boolean isContainment) {
EStructuralFeature newFeature;
if (featureClassifier instanceof EClass) {
EReference reference = EcoreFactory.eINSTANCE.createEReference();
reference.setContainment(isContainment);
newFeature = reference;
} else {
newFeature = EcoreFactory.eINSTANCE.createEAttribute();
}
newFeature.setName(featureName);
newFeature.setEType(featureClassifier);
newFeature.setLowerBound(0);
newFeature.setUpperBound(isMultivalue ? -1 : 1);
newFeature.setUnique(!isMultivalue || (isContainment && featureClassifier instanceof EClass));
if (newFeature.getEType() instanceof EEnum) {
newFeature.setDefaultValue(null);
}
return newFeature;
}
示例11: createPackage
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
private List<EObject> createPackage(GeneratedMetamodel generatedMetamodel, ILeafNode text) {
final String nsURI = getMetamodelNsURI(text);
final URI uri = URI.createURI(nsURI);
if (uri == null || isReferencedByUsedGrammar(generatedMetamodel, nsURI))
return Collections.emptyList();
EPackage pack = ((GeneratedMetamodelImpl)generatedMetamodel).basicGetEPackage();
if (pack != null && !pack.eIsProxy())
return singletonList((EObject)pack);
final EPackage generatedEPackage = EcoreFactory.eINSTANCE.createEPackage();
generatedEPackage.setName(generatedMetamodel.getName());
generatedEPackage.setNsPrefix(generatedMetamodel.getName());
generatedEPackage.setNsURI(nsURI);
final Resource generatedPackageResource = new EcoreResourceFactoryImpl().createResource(uri);
XtextResourceSet resourceSet = (XtextResourceSet) generatedMetamodel.eResource().getResourceSet();
if (!resourceSet.getURIResourceMap().containsKey(generatedPackageResource.getURI())) {
generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource);
} else {
generatedPackageResource.setURI(URI.createURI(nsURI+"_"+generatedMetamodel.hashCode()));
generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource);
}
generatedPackageResource.getContents().add(generatedEPackage);
return Collections.<EObject>singletonList(generatedEPackage);
}
示例12: testFillIdToEObjectMap
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
@Test
public void testFillIdToEObjectMap() {
EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
EClass root = createEClass(pack, "Root");
EClass someType = createEClass(pack, "SomeType");
EReference ref1 = addEReference(root, someType, "ref1", false);
EReference ref2 = addEReference(root, someType, "ref2", true);
EFactory factory = pack.getEFactoryInstance();
EObject rootObject = factory.create(root);
EObject someTypeObject1 = factory.create(someType);
EObject someTypeObject2 = factory.create(someType);
rootObject.eSet(ref1, someTypeObject1);
rootObject.eSet(ref2, someTypeObject2);
List<EObject> map = new ArrayList<>();
SerializationUtil.fillIdToEObjectMap(rootObject, map);
assertTrue(map.contains(rootObject));
assertTrue(map.contains(someTypeObject1));
assertFalse(map.contains(someTypeObject2));
assertEquals(2, map.size());
}
示例13: testNoShortCircuiting
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
/** Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=396726 */
@Test public void testNoShortCircuiting() {
CompositeEValidator compositeValidator = new CompositeEValidator();
compositeValidator.setEqualitySupportProvider(new Provider<CompositeEValidator.EValidatorEqualitySupport>() {
@Override
public EValidatorEqualitySupport get() {
return new CompositeEValidator.EValidatorEqualitySupport();
}
});
assertEquals(1, compositeValidator.getContents().size());
compositeValidator.addValidator(EcoreValidator.INSTANCE);
assertEquals(2, compositeValidator.getContents().size());
TestEcoreValidator testValidator = new TestEcoreValidator();
compositeValidator.addValidator(testValidator);
assertEquals(3, compositeValidator.getContents().size());
compositeValidator.validate(EcoreFactory.eINSTANCE.createEClass(), new BasicDiagnostic(), null);
assertTrue(testValidator.wasCalled());
}
示例14: testCreatedErrors_07
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
@Test public void testCreatedErrors_07() {
maxCallCount = 0;
ImmutableList<ENamedElement> elements = ImmutableList.of(
createEPackage(),
createEDataType(),
EcoreFactory.eINSTANCE.createEEnumLiteral()
);
for(ENamedElement classifier: elements) {
classifier.setName("Same");
}
expected.add(elements.get(0));
expected.add(elements.get(2));
helper.checkUniqueNames(
Scopes.scopedElementsFor(elements),
this, this);
assertEquals(elements.size(), callCount);
assertTrue(expected.isEmpty());
}
示例15: testConvertNullInput
import org.eclipse.emf.ecore.EcoreFactory; //導入依賴的package包/類
@Test
public void testConvertNullInput() throws Exception {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {
@Override
public Object apply(String lexerRule, INode node) {
if ("foo".equals(lexerRule) ) {
return "FOO";
}
return null;
}
};
DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
factory.setConverterService(new MockedConverterService(toValueImpl));
factory.set(eClass, "name", null, "foo", null);
assertEquals("FOO", eClass.getName());
}