Java Code Examples for org.eclipse.emf.ecore.EClass#setName()

The following examples show how to use org.eclipse.emf.ecore.EClass#setName() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
Source File: NamesAreUniqueValidationHelperTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testErrorMessage_02() {
	EClass eClass = createEClass();
	eClass.setName("EClassName");
	IEObjectDescription description = EObjectDescription.create(QualifiedName.create(eClass.getName()), eClass);
	String errorMessage = helper.getDuplicateNameErrorMessage(description, EcorePackage.Literals.ECLASS, EcorePackage.Literals.ENAMED_ELEMENT__NAME);
	assertEquals("Duplicate EClass 'EClassName'", errorMessage);
}
 
Example 9
Source File: NamesAreUniqueValidationHelperTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testErrorMessage_01() {
	EClass eClass = createEClass();
	eClass.setName("EClassName");
	IEObjectDescription description = EObjectDescription.create(QualifiedName.create(eClass.getName()), eClass);
	String errorMessage = helper.getDuplicateNameErrorMessage(description, EcorePackage.Literals.ECLASSIFIER, EcorePackage.Literals.ENAMED_ELEMENT__NAME);
	assertEquals("Duplicate EClassifier 'EClassName'", errorMessage);
}
 
Example 10
Source File: NamesAreUniqueValidationHelperTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testManyUnique_context() {
	List<ENamedElement> elements = new ArrayList<>();
	for(int i = 0; i < MANY; i++) {
		EClass c = createEClass();
		c.setName("i" + i);
		elements.add(c);
	}
	maxCallCount = 0;
	helper.checkUniqueNames(
			new LocalUniqueNameContext(elements, this), this);
}
 
Example 11
Source File: SimpleAttributeResolverTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetNameMatches() {
	EClass clazzMatch = factory.createEClass();
	EClass clazzNoMatch = factory.createEClass();
	clazzMatch.setName("ClassName");
	clazzNoMatch.setName("NoMatchClassName");
	Iterable<EObject> res = nameResolver.getMatches(Arrays.<EObject>asList(clazzMatch, clazzNoMatch), "ClassName");
	assertNotNull("res", res);
	Iterator<EObject> iter = res.iterator();
	assertTrue(iter.hasNext());
	assertEquals(clazzMatch, iter.next());
	assertFalse(iter.hasNext());
}
 
Example 12
Source File: XSDSchemaReader.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void createGroup(XSModelGroupDecl modelGroupDecl) {
	EClass eClass = ecoreFactory.createEClass();
	eClass.setName(modelGroupDecl.getName());
	ePackage.getEClassifiers().add(eClass);
	for (XSParticle particle : modelGroupDecl.getModelGroup().getChildren()) {
		XSTerm term = particle.getTerm();
		if (term.isElementDecl()) {
			String name = term.asElementDecl().getName();
			EClassifier subClass = ePackage.getEClassifier(name);
			if (subClass != null && subClass instanceof EClass) {
				((EClass) subClass).getESuperTypes().add(eClass);
			}
		}
	}
}
 
Example 13
Source File: Schema.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public EClass createEClass(EPackage ePackage, String name, EClass... superClasses) {
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	eClass.setName(name);
	changes.add(new NewClassChange(eClass));
	for (EClass superClass : superClasses) {
		eClass.getESuperTypes().add(superClass);
	}
	ePackage.getEClassifiers().add(eClass);
	return eClass;
}
 
Example 14
Source File: SimpleAttributeResolverTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetNameValueTwice() {
	EClass clazz = factory.createEClass();
	clazz.setName("ClassName");
	assertEquals(0, clazz.eAdapters().size());
	String name = nameResolver.getValue(clazz);
	assertEquals(1, clazz.eAdapters().size());
	clazz.setName("ClassName2");
	assertEquals(0, clazz.eAdapters().size());
	name = nameResolver.getValue(clazz);
	assertEquals("ClassName2", name);
}
 
Example 15
Source File: EcoreResourceDescriptionManagerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testMissingName() {
	Resource resource = new XMIResourceImpl();
	EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
	ePackage.setNsURI("http://test");
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	eClass.setName("Test");
	ePackage.getEClassifiers().add(eClass);
	resource.getContents().add(ePackage);
	Map<QualifiedName, IEObjectDescription> index = createIndex(resource);
	checkEntry(index, ePackage, true, "http://test");
	checkEntry(index, eClass, true, "http://test", "Test");
	assertEquals(2,index.size());
}
 
Example 16
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 17
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void addTwoDimensionalArray(String entityName, String attribName) {
	EClassifier finalType = null;
	if (entityName.equals("IfcBSplineSurface") && attribName.equals("ControlPointsList")) {
		finalType = schemaPack.getEClassifier("IfcCartesianPoint");
	} else if (entityName.equals("IfcCartesianPointList3D") && attribName.equals("CoordList")) {
		finalType = schemaPack.getEClassifier("IfcLengthMeasure");
	} else if (entityName.equals("IfcColourRgbList") && attribName.equals("ColourList")) {
		finalType = schemaPack.getEClassifier("IfcNormalisedRatioMeasure");
	} else if (entityName.equals("IfcIndexedTriangleTextureMap") && attribName.equals("TexCoordIndex")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else if (entityName.equals("IfcRationalBSplineSurfaceWithKnots") && attribName.equals("WeightsData")) {
		finalType = EcorePackage.eINSTANCE.getEDouble();
	} else if (entityName.equals("IfcStructuralLoadConfiguration") && attribName.equals("Locations")) {
		finalType = schemaPack.getEClassifier("IfcLengthMeasure");
	} else if (entityName.equals("IfcTessellatedFaceSet") && attribName.equals("Normals")) {
		finalType = schemaPack.getEClassifier("IfcParameterValue");
	} else if (entityName.equals("IfcTextureVertexList") && attribName.equals("TexCoordsList")) {
		finalType = schemaPack.getEClassifier("IfcParameterValue");
	} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("CoordIndex")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else if (entityName.equals("IfcCartesianPointList2D") && attribName.equals("CoordList")) {
		finalType = schemaPack.getEClassifier("IfcLengthMeasure");
	} else if (entityName.equals("IfcIndexedPolygonalFaceWithVoids") && attribName.equals("InnerCoordIndices")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("Normals")) {
		finalType = schemaPack.getEClassifier("IfcParameterValue");
	} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("NormalIndex")) {
		finalType = EcorePackage.eINSTANCE.getELong();
	} else {
		throw new RuntimeException("Unimplemented " + entityName + "." + attribName);
	}
	EClass containerClass = (EClass) schemaPack.getEClassifier("ListOf" + finalType.getName());
	if (containerClass == null) {
		containerClass = EcoreFactory.eINSTANCE.createEClass();
		containerClass.setName("ListOf" + finalType.getName());

		if (finalType.getEPackage() == EcorePackage.eINSTANCE) {
			EAttribute finalAttribute = EcoreFactory.eINSTANCE.createEAttribute();
			finalAttribute.setName("List");
			finalAttribute.setEType(finalType);
			finalAttribute.setUpperBound(-1);
			containerClass.getEAttributes().add(finalAttribute);
			
			if (finalType == EcorePackage.eINSTANCE.getEDouble()) {
				EAttribute stringAttribute = EcoreFactory.eINSTANCE.createEAttribute();
				stringAttribute.setName("ListAsString");
				stringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
				stringAttribute.setUpperBound(-1);
				containerClass.getEAttributes().add(stringAttribute);
			}
		} else {
			EReference finalReference = EcoreFactory.eINSTANCE.createEReference();
			finalReference.setName("List");
			finalReference.setEType(finalType);
			finalReference.setUpperBound(-1);
			containerClass.getEReferences().add(finalReference);
		}

		schemaPack.getEClassifiers().add(containerClass);
	}
	
	EReference eReference = EcoreFactory.eINSTANCE.createEReference();
	eReference.getEAnnotations().add(createTwoDimensionalArrayAnnotation());
	eReference.setName(attribName);
	eReference.setUpperBound(-1);
	eReference.setEType(containerClass);
	
	EClass cls = (EClass) schemaPack.getEClassifier(entityName);
	cls.getEStructuralFeatures().add(eReference);
}
 
Example 18
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 19
Source File: ModelDefinitionItemProviderTests.java    From M2Doc with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Initializes test resources.
 */
@Before
public void before() {
    final ResourceSet rs = new ResourceSetImpl();
    rs.getURIConverter().getURIHandlers().add(0, uriHandler);
    rs.getResourceFactoryRegistry().getContentTypeToFactoryMap().put("*", new XMIResourceFactoryImpl());
    final Resource res = rs
            .createResource(URI.createURI(TestMemoryURIHandler.PROTOCOL + "://resources/test.genconf", false));

    final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
    generation.setTemplateFileName("test.docx");
    res.getContents().add(generation);

    definition = GenconfPackage.eINSTANCE.getGenconfFactory().createModelDefinition();
    definition.setKey("self");
    generation.getDefinitions().add(definition);

    final EPackage ePkg1 = EcorePackage.eINSTANCE.getEcoreFactory().createEPackage();
    ePkg1.setName("package1");
    final EPackage ePkg2 = EcorePackage.eINSTANCE.getEcoreFactory().createEPackage();
    ePkg2.setName("package2");
    final EPackage ePkg3 = EcorePackage.eINSTANCE.getEcoreFactory().createEPackage();
    ePkg3.setName("package3");
    final EClass eCls1 = EcorePackage.eINSTANCE.getEcoreFactory().createEClass();
    eCls1.setName("Class1");
    final EClass eCls2 = EcorePackage.eINSTANCE.getEcoreFactory().createEClass();
    eCls2.setName("Class2");
    final EClass eCls3 = EcorePackage.eINSTANCE.getEcoreFactory().createEClass();
    eCls3.setName("Class3");

    res.getContents().add(ePkg1);
    res.getContents().add(ePkg2);
    res.getContents().add(ePkg3);

    res.getContents().add(eCls1);
    res.getContents().add(eCls2);
    res.getContents().add(eCls3);

    try {
        res.save(null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

    document = new XWPFDocument();

    properties = new TemplateCustomProperties(document);
    properties.getPackagesURIs().add(GenconfPackage.eINSTANCE.getNsURI());
}
 
Example 20
Source File: EcoreUtilN4Test.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private EClass ecl(String n) {
	EClass c = EcoreFactory.eINSTANCE.createEClass();
	c.setName(n);
	return c;
}