org.eclipse.emf.ecore.EcoreFactory Java Examples

The following examples show how to use org.eclipse.emf.ecore.EcoreFactory. 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: EcoreResourceDescriptionManagerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass, final EObject object) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass == eC */
  if (!Objects.equal(eClass, eC)) {
    sneakyThrowRuleFailedException("eClass == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #3
Source File: EcoreUtil2Test.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testPathFragment() {
	EClass foo = EcoreFactory.eINSTANCE.createEClass();
	foo.setName("foo");
	EClass bar = EcoreFactory.eINSTANCE.createEClass();
	foo.setName("bar");
	EPackage p = EcoreFactory.eINSTANCE.createEPackage();
	bar.setName("p");
	p.getEClassifiers().add(foo);
	p.getEClassifiers().add(bar);
	
	assertEquals("/-1", EcoreUtil2.getFragmentPath(foo));
	assertEquals("/-1", EcoreUtil2.getFragmentPath(bar));
	assertEquals("/-1", EcoreUtil2.getFragmentPath(p));
	Resource resource = new ResourceImpl(URI.createURI("platform:/resource/res"));
	resource.getContents().add(p);
	assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.0"), EcoreUtil2.getFragmentPathURI(foo));
	assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.1"), EcoreUtil2.getFragmentPathURI(bar));
	assertEquals(URI.createURI("platform:/resource/res#/"), EcoreUtil2.getFragmentPathURI(p));
	assertEquals(resource.getEObject("//@eClassifiers.0"), foo);
	assertEquals(resource.getEObject("//@eClassifiers.1"), bar);
	assertEquals(resource.getEObject("/"), p);
}
 
Example #4
Source File: GenericResourceDescriptionManagerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCreateDeltaAndIsAffected() {
	GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager();
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	eClass.setName("Test");
	eClass.getESuperTypes().add(EcorePackage.Literals.EPACKAGE);
	Resource resource = new XMIResourceImpl(URI.createFileURI("test.ecore"));
	resource.getContents().add(eClass);

	EPackage copyOfEPackage = EcoreUtil.copy(EcorePackage.eINSTANCE);
	Resource ecoreResource = new XMIResourceImpl(URI.createURI(copyOfEPackage.getNsURI()));
	ecoreResource.getContents().add(copyOfEPackage);
	
	IResourceDescription oldDescription = new CopiedResourceDescription(manager.getResourceDescription(ecoreResource));
	oldDescription.getExportedObjects();
	copyOfEPackage.setName("ecore_new");
	IResourceDescription newDescription = manager.getResourceDescription(ecoreResource);
	
	Delta delta = manager.createDelta(oldDescription, newDescription);
	assertTrue(delta.haveEObjectDescriptionsChanged());
	
	IResourceDescription referrerDescription = manager.getResourceDescription(resource);
	assertTrue(manager.isAffected(delta, referrerDescription));
}
 
Example #5
Source File: EcoreUtil2Test.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testGetAllReferencedObjects() {
	EClass a = createEClass("a");
	EClass b = createEClass("b");
	
	EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
	pack.setName("empty");
	pack.setNsPrefix("empty");
	pack.setNsURI("empty");
	pack.getEClassifiers().add(a);
	pack.getEClassifiers().add(b);
	
	EReference ref = EcoreFactory.eINSTANCE.createEReference();
	a.getEStructuralFeatures().add(ref);
	ref.setUpperBound(1);
	ref.setEType(b);
	EObject objA = pack.getEFactoryInstance().create(a);
	EObject objB = pack.getEFactoryInstance().create(b);
	List<EObject> res = EcoreUtil2.getAllReferencedObjects(objA, ref);
	assertNotNull(res);
	assertTrue(res.isEmpty());
	res = EcoreUtil2.getAllReferencedObjects(objA, ref);
	assertNotNull(res);
	objA.eSet(ref, objB);
}
 
Example #6
Source File: EcoreUtil2Test.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testIsAssignableFrom() {
	EClass superCls = EcoreFactory.eINSTANCE.createEClass();
	superCls.setName("MySuper");
	superCls.getESuperTypes().add(EcorePackage.eINSTANCE.getEObject());

	EClass subCls = EcoreFactory.eINSTANCE.createEClass();
	subCls.setName("MySub");
	subCls.getESuperTypes().add(superCls);
	
	assertFalse(EcoreUtil2.isAssignableFrom(null, null));
	assertFalse(EcoreUtil2.isAssignableFrom(superCls, null));
	assertFalse(EcoreUtil2.isAssignableFrom(null, superCls));
	
	assertTrue(EcoreUtil2.isAssignableFrom(superCls, superCls));
	assertTrue(EcoreUtil2.isAssignableFrom(superCls, subCls));
	assertFalse(EcoreUtil2.isAssignableFrom(subCls, superCls));
	
	assertTrue(EcoreUtil2.isAssignableFrom(EcorePackage.eINSTANCE.getEObject(), superCls));
	assertTrue(EcoreUtil2.isAssignableFrom(EcorePackage.eINSTANCE.getEObject(), subCls));
}
 
Example #7
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass1, final EClass eClass2) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass1 == eC */
  if (!Objects.equal(eClass1, eC)) {
    sneakyThrowRuleFailedException("eClass1 == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #8
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass1, final EClass eClass2) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass1 == eC */
  if (!Objects.equal(eClass1, eC)) {
    sneakyThrowRuleFailedException("eClass1 == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #9
Source File: ValidationJobSchedulerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(final URI uri) {
	return new AbstractResourceDescription() {

		@Override
		public Iterable<QualifiedName> getImportedNames() {
			return Collections.emptyList();
		}

		@Override
		public Iterable<IReferenceDescription> getReferenceDescriptions() {
			return Collections.emptyList();
		}

		@Override
		public URI getURI() {
			return uri;
		}

		@Override
		protected List<IEObjectDescription> computeExportedObjects() {
			return Collections.singletonList(EObjectDescription.create(exportedName, EcoreFactory.eINSTANCE.createEObject()));
		}
		
	};
}
 
Example #10
Source File: EcoreResourceDescriptionManagerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #11
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 #12
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass1, final EClass eClass2) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass1 == eC */
  if (!Objects.equal(eClass1, eC)) {
    sneakyThrowRuleFailedException("eClass1 == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #13
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass, final EObject object) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass == eC */
  if (!Objects.equal(eClass, eC)) {
    sneakyThrowRuleFailedException("eClass == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #14
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 #15
Source File: DefaultEcoreElementFactoryTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #16
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 #17
Source File: ScopesTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testWithDifferentElements() throws Exception {
	EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
	attr.setName("Foo");
	EDataType datatype = EcoreFactory.eINSTANCE.createEDataType();
	datatype.setName("Bar");
	
	ArrayList<EObject> list = new ArrayList<EObject>();
	list.add(attr);
	list.add(EcoreFactory.eINSTANCE.createEObject());
	list.add(datatype);
	
	Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor(list);
	Iterator<IEObjectDescription> iterator = iterable.iterator();
	IEObjectDescription next = iterator.next();
	assertEquals(FOO, next.getName());
	assertEquals(attr,next.getEObjectOrProxy());
	next = iterator.next();
	assertEquals(BAR, next.getName());
	assertEquals(datatype,next.getEObjectOrProxy());
	assertFalse(iterator.hasNext());
}
 
Example #18
Source File: InjectableValidatorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testArbitraryEPackage() throws Exception {
	EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
	xtextResource.getContents().add(ePackage);
	assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), null));
	assertFalse(languageSpecificValidator.validate(ePackage, new BasicDiagnostic(), context));
	assertEquals(xtextResource.getLanguageName(), context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));		

	context.clear();
	assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), null));
	assertFalse(languageAgnosticValidator.validate(ePackage, new BasicDiagnostic(), context));
	assertNull(context.get(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME));		
}
 
Example #19
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 #20
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 #21
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 #22
Source File: DefaultEcoreElementFactoryTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testValueConverterException() throws Exception {
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	final ILeafNode node = new LeafNode();
	final ValueConverterException expected = new ValueConverterException("Foo", node, null);
	
	Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

		@Override
		public Object apply(String lexerRule, INode nodeParam) {
			if ("foo".equals(lexerRule) && node.equals(nodeParam)) {
				throw expected;
			}
			fail();
			return null;
		}
	};

	DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
	factory.setConverterService(new MockedConverterService(toValueImpl));
	try {
		factory.set(eClass, "abstract", null, "foo", node);
		fail("Expected ValueConverterException");
	} catch (ValueConverterException ex) {
		assertSame(expected, ex);
	}
}
 
Example #23
Source File: ResourceDescriptionsBasedContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	eClass = EcoreFactory.eINSTANCE.createEClass();
	eClass.setName("SomeName");
	uri = URI.createURI("myURI");
	((InternalEObject)eClass).eSetProxyURI(uri.appendFragment("SomeName"));
	resourceDescription = new ResourceDescription(uri);
	container = createContainer();
	selectableDelegate = new AbstractCompoundSelectable() {
		@Override
		protected Iterable<? extends ISelectable> getSelectables() {
			return getAllResourceDescriptions();
		}
	};
}
 
Example #24
Source File: SerializationUtilTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private EReference addEReference(EClass from, EClass to, String name, boolean isTransient) {
	EReference ref = EcoreFactory.eINSTANCE.createEReference();
	ref.setName("ref2");
	ref.setEType(to);
	ref.setContainment(true);
	if (isTransient) {
		ref.setTransient(true);
		ref.setDerived(true);
	}
	ref.setChangeable(true);
	from.getEStructuralFeatures().add(ref);
	return ref;
}
 
Example #25
Source File: ValidatorTesterTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testError2Fail() {
	boolean caught = false;
	try {
		tester.validate(EcoreFactory.eINSTANCE.createEAnnotation()).assertError("234242");
	}
	catch (AssertionError err) {
		caught = true;
	}
	assertTrue(caught);
}
 
Example #26
Source File: CompositeNodeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testIsAdapterForType() {
	EObject object = EcoreFactory.eINSTANCE.createEObject();
	CompositeNodeWithSemanticElement node = createCompositeNode();
	object.eAdapters().add(node);
	AdapterFactory adapterFactory = new EcoreAdapterFactory();
	Adapter adapter = adapterFactory.adapt(object, INode.class);
	assertSame(node, adapter);
	// the following line may not throw a ClassCastException
	Adapter secondAdapter = adapterFactory.adapt(object, new Object());
	assertNull(secondAdapter);
}
 
Example #27
Source File: LeafNodeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Test public void testGetSemanticElement() {
	ICompositeNode rootNode = builder.newRootNode("input");
	ICompositeNode parent = builder.newCompositeNode(null, 0, rootNode);
	EObject semanticElement = EcoreFactory.eINSTANCE.createEObject();
	builder.associateWithSemanticElement(parent, semanticElement);
	LeafNode leafNode = createNode();
	builder.addChild(parent, leafNode);
	assertSame(semanticElement, leafNode.getSemanticElement());
}
 
Example #28
Source File: LeafNodeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Test public void testGetGrammarElement() {
	LeafNode leafNode = createNode();
	EObject grammarElement = EcoreFactory.eINSTANCE.createEObject();
	leafNode.basicSetGrammarElement(grammarElement);
	assertSame(grammarElement, leafNode.getGrammarElement());
}
 
Example #29
Source File: AbstractCompositeNodeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testActsAsAdapter() {
	EObject object = EcoreFactory.eINSTANCE.createEObject();
	ICompositeNode composite = createCompositeNode();
	object.eAdapters().add((Adapter) composite);
	assertSame(object, composite.getSemanticElement());
	assertSame(object, ((Adapter) composite).getTarget());
	object.eAdapters().clear();
	assertNull(composite.getSemanticElement());
}
 
Example #30
Source File: GenericUnloaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EPackage createExample() {
	ResourceSetImpl resourceSet = new ResourceSetImpl();
	Resource resource = new XMIResourceImpl(URI.createURI("test"));
	resourceSet.getResources().add(resource);
	EPackage root = EcoreFactory.eINSTANCE.createEPackage();
	resource.getContents().add(root);
	EClass child = EcoreFactory.eINSTANCE.createEClass();
	root.getEClassifiers().add(child);
	return root;
}