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

The following examples show how to use org.eclipse.emf.ecore.EcoreFactory#createEClass() . 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: 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 5
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 6
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 7
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 8
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 9
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());

}