Java Code Examples for org.eclipse.emf.ecore.EcoreFactory#eINSTANCE()

The following examples show how to use org.eclipse.emf.ecore.EcoreFactory#eINSTANCE() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnChangeEvictingCacheAdapterTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testAdapterIsCleared() throws Exception {
	EcoreFactory factory = EcoreFactory.eINSTANCE;
	EClass eClass = factory.createEClass();
	Resource resource = new ResourceImpl();
	resource.getContents().add(eClass);
	CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
	setValue(ca);
	EAttribute attribute = factory.createEAttribute();
	assertIsSet(ca);
	eClass.getEStructuralFeatures().add(attribute);
	assertIsNull(ca);
	setValue(ca);
	attribute.setName("Foo");
	assertIsNull(ca);
	setValue(ca);
}
 
Example 2
Source File: OnChangeEvictingCacheAdapterTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCacheSurvivesChangesToAdapters() throws Exception {
	EcoreFactory factory = EcoreFactory.eINSTANCE;
	EClass eClass = factory.createEClass();
	Resource resource = new ResourceImpl();
	resource.getContents().add(eClass);
	CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
	setValue(ca);
	List<Adapter> adapters = resource.eAdapters();
	assertIsSet(ca);
	AdapterImpl adapter = new AdapterImpl();
	adapters.add(adapter);
	assertIsSet(ca);
	adapters.remove(adapter);
	assertIsSet(ca);
}
 
Example 3
Source File: ShortFragmentProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void initialize() {
  EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;

  testClass = ecoreFactory.createEClass();

  testReference = ecoreFactory.createEReference();
  testReference.setEType(testClass);
  testReference.setContainment(true);
  testClass.getEStructuralFeatures().add(testReference);

  testReference2 = ecoreFactory.createEReference();
  testReference2.setEType(testClass);
  testReference2.setContainment(true);
  testClass.getEStructuralFeatures().add(testReference2);

  testPackage = ecoreFactory.createEPackage();
  testPackage.getEClassifiers().add(testClass);
  testPackage.setNsURI("http:///com.avaloq.tools.ddk.xtext.test");
  EPackage.Registry.INSTANCE.put(testPackage.getNsURI(), testPackage);
}
 
Example 4
Source File: AbstractTypeProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void init() {
  EcoreFactory modelFactory = EcoreFactory.eINSTANCE;
  testModelPackage = modelFactory.createEPackage();
  testModelPackage.setName("TypeProviderTestEPackage");
  testModelPackage.setNsPrefix("typeprovidertestpackage");
  testModelPackage.setNsURI("http://testabstracttype");
  EFactory instanceFactory = testModelPackage.getEFactoryInstance();
  EClass clazz = createEClass("ExpressionContainer");
  expressionContainerReference = modelFactory.createEReference();
  clazz.getEStructuralFeatures().add(expressionContainerReference);
  expressionContainerReference.setName("expression");
  expressionContainerReference.setEType(typeModelPackage.getIExpression());
  expressionContainerReference.setContainment(true);
  expression1Container = instanceFactory.create(clazz);
  expression1Container.eSet(expressionContainerReference, expression1);
  expression2Container = instanceFactory.create(clazz);
  expression2Container.eSet(expressionContainerReference, expression2);
  expression3Container = instanceFactory.create(clazz);
  expression3Container.eSet(expressionContainerReference, expression3);
}
 
Example 5
Source File: AbstractURIHandlerWithEcoreTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() {
  super.setUp();
  EcoreFactory factory = EcoreFactory.eINSTANCE;
  EClass baseClass = factory.createEClass();
  baseClass.setName("Base");
  primaryResource.getContents().add(baseClass);
  EClass superClass = factory.createEClass();
  superClass.setName("SuperClass");
  referencedResource.getContents().add(superClass);
  baseClass.getESuperTypes().add(superClass);
}
 
Example 6
Source File: EClassInfoTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void testChangeable(){
	EcorePackage pack = EcorePackage.eINSTANCE;
	EClass eClass = pack.getEClass();
	EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
	EcoreFactory fac = EcoreFactory.eINSTANCE;
	EReference reference = fac.createEReference();
	reference.setName("newReference");
	reference.setEType(eClass);
	reference.setChangeable(true);
	reference.setContainment(true);
	eClass.getEStructuralFeatures().add(reference);
	assertEquals(true,objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
	reference.setChangeable(false);
	assertEquals(false,objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
}
 
Example 7
Source File: ResourceSetReferencingResourceSetTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private Resource getResource(String resourceURI, String references) {
	XMIResourceImpl res = new XMIResourceImpl();
	res.setURI(URI.createURI(resourceURI));
	EcoreFactory f = EcoreFactory.eINSTANCE;
	EClass class1 = f.createEClass();
	res.getContents().add(class1);
	class1.setName("mytype");
	if (references!=null) {
		EClass referencedProxy = f.createEClass();
		String fragment = res.getURIFragment(class1);
		((InternalEObject)referencedProxy).eSetProxyURI(URI.createURI(references).appendFragment(fragment));
		class1.getESuperTypes().add(referencedProxy);
	}
	return res;
}
 
Example 8
Source File: DefaultResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	resource = new XMLResourceImpl();
	resource.setURI(URI.createURI("foo:/test"));
	nameProvider = new IQualifiedNameProvider.AbstractImpl() {
		@Override
		public QualifiedName getFullyQualifiedName(EObject obj) {
			if (obj instanceof ENamedElement)
				return QualifiedName.create(((ENamedElement) obj).getName());
			return null;
		}
	};
	strategy = new DefaultResourceDescriptionStrategy();
	strategy.setQualifiedNameProvider(nameProvider);
	description = new DefaultResourceDescription(resource, strategy);
	EcoreFactory f = EcoreFactory.eINSTANCE;
	pack = f.createEPackage();
	pack.setName("MyPackage");
	eClass = f.createEClass();
	eClass.setName("MyEClass");
	dtype = f.createEDataType();
	dtype.setName("MyDatatype");
	pack.getEClassifiers().add(eClass);
	pack.getEClassifiers().add(dtype);
	resource.getContents().add(pack);

}
 
Example 9
Source File: OnChangeEvictingCacheAdapterTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCacheSurvivesChangeToDiagnostics() throws Exception {
	EcoreFactory factory = EcoreFactory.eINSTANCE;
	EClass eClass = factory.createEClass();
	Resource resource = new ResourceImpl();
	resource.getContents().add(eClass);
	CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
	setValue(ca);
	List<Diagnostic> errors = resource.getErrors();
	assertIsSet(ca);
	errors.clear();
	assertIsSet(ca);
}
 
Example 10
Source File: AbstractTypeProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
private EClass createEClass(final String name, final EClass... superTypes) {
  EcoreFactory modelFactory = EcoreFactory.eINSTANCE;
  EClass clazz = modelFactory.createEClass();
  clazz.setName(name);
  for (EClass superType : superTypes) {
    clazz.getESuperTypes().add(superType);
  }
  testModelPackage.getEClassifiers().add(clazz);
  return clazz;
}
 
Example 11
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public Express2EMF(File schemaFileName, String modelName, String nsUri) {
	schema = new SchemaLoader(schemaFileName.getAbsolutePath()).getSchema();
	eFactory = EcoreFactory.eINSTANCE;
	ePackage = EcorePackage.eINSTANCE;
	schemaPack = eFactory.createEPackage();
	try {
		new DerivedReader(schemaFileName, schema);
	} catch (FileNotFoundException e) {
		LOGGER.error("", e);
	}
	schemaPack.setName(modelName);
	schemaPack.setNsPrefix("iai");
	schemaPack.setNsURI(nsUri);

	createTristate();

	addClasses();
	addSupertypes();
	addSimpleTypes();
	addDerivedTypes();
	addEnumerations();
	addHackedTypes();
	addSelects();
	addAttributes();
	addInverses();
	EClass ifcBooleanClass = (EClass) schemaPack.getEClassifier("IfcBoolean");
	ifcBooleanClass.getESuperTypes().add((EClass) schemaPack.getEClassifier("IfcValue"));
	doRealDerivedAttributes();
	clean();
}
 
Example 12
Source File: XtextGrammarRefactoringIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testRefactorXtextGrammarWithGeneratedClassifierAndModelWithRefToClassifier() throws Exception {
	ResourceSet rs = resourceSetProvider.get();
	EcoreFactory eInstance = EcoreFactory.eINSTANCE;
	Resource ecoreModelResource = createEcoreModel(rs, ecoreURI, initialModelRoot);
	EClass greetingClass = getGreetingClass(ecoreModelResource);
	EReference greetingRefLocal = getReferenceoGreeting(ecoreModelResource, greetingClass);
	String greetingClassFragment = EcoreUtil.getURI(greetingClass).fragment();
	String greetingRefFragment = EcoreUtil.getURI(greetingRefLocal).fragment();

	EPackage refPackage = eInstance.createEPackage();
	refPackage.setName("myDsl2");
	refPackage.setNsPrefix("myDsl2");
	refPackage.setNsURI("http://testrefactoring2");
	EClass modelRefClass = eInstance.createEClass();
	refPackage.getEClassifiers().add(modelRefClass);
	modelRefClass.setName("ModelRef");
	EReference reference = eInstance.createEReference();
	reference.setName("ref");
	reference.setLowerBound(0);
	reference.setUpperBound(-1);
	reference.setEType(greetingClass);
	modelRefClass.getEStructuralFeatures().add(reference);
	Resource refToGreetingResource = createEcoreModel(rs,
			URI.createPlatformResourceURI(TEST_PROJECT + "/src/org/xtext/example/mydsl/" + "MyDsl2.ecore", true),
			refPackage);
	refToGreetingResource.unload();
	ecoreModelResource.unload();
	waitForBuild();
	waitForDisplay();
	XtextEditor editor = openEditor(grammarFile);
	doRefactoring(editor);
	waitForBuild();
	checkConsistenceOfGrammar(editor);
	ecoreModelResource.load(null);
	String renamedGreetingClassFragment = greetingClassFragment.replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME);
	EObject renamedGreetingClass = ecoreModelResource.getEObject(renamedGreetingClassFragment);
	assertNotNull(renamedGreetingClass);
	assertEquals(REFACTOREDCLASSIFIERNAME, SimpleAttributeResolver.NAME_RESOLVER.apply(renamedGreetingClass));
	EReference greetingReference = (EReference) ecoreModelResource.getEObject(greetingRefFragment);
	EClassifier eType = greetingReference.getEType();
	assertFalse(eType.eIsProxy());
	assertEquals(REFACTOREDCLASSIFIERNAME, eType.getName());

	refToGreetingResource.load(null);
	EReference externalReferenceToGreeting = getReferenceoGreeting(refToGreetingResource, eType);
	assertFalse(externalReferenceToGreeting.getEType().eIsProxy());
	assertEquals(REFACTOREDCLASSIFIERNAME, externalReferenceToGreeting.getEType().getName());

}
 
Example 13
Source File: SimpleAttributeResolverTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
	factory = EcoreFactory.eINSTANCE;
	nameResolver = SimpleAttributeResolver.newResolver(String.class, "name");
	superClassResolver = SimpleAttributeResolver.newResolver(EList.class, "eSuperTypes");
}