Java Code Examples for org.eclipse.emf.ecore.EAttribute#setEType()

The following examples show how to use org.eclipse.emf.ecore.EAttribute#setEType() . 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: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeSpecialAttributeAssignment(String specialAttribute, int priorityFactor, Iterable<String> processedFeatures,
		Function<IEObjectDescription, ICompletionProposal> factory, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if(!contains(processedFeatures, specialAttribute)) {
		EAttribute dummyAttribute = EcoreFactory.eINSTANCE.createEAttribute();
		dummyAttribute.setName(specialAttribute);
		dummyAttribute.setEType(EcorePackage.Literals.ESTRING);
		acceptor.accept(createFeatureProposal(dummyAttribute, priorityFactor, factory, context));
	}
}
 
Example 2
Source File: Schema.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public EAttribute createEAttribute(EClass eClass, String name, EDataType eDataType, Multiplicity multiplicity) {
	EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
	eAttribute.setName(name);
	if (multiplicity == Multiplicity.MANY) {
		eAttribute.setUpperBound(-1);
	}
	if (!isNew(eClass)) {
		changes.add(new NewAttributeChange(this, eClass.getEAllStructuralFeatures().size(), eAttribute));
	}
	eAttribute.setEType(eDataType);
	eClass.getEStructuralFeatures().add(eAttribute);
	return eAttribute;
}
 
Example 3
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private EAttribute x(DefinedType type, EClass testType) {
	EAttribute wrapperAttrib = eFactory.createEAttribute();
	wrapperAttrib.setName("wrappedValue");
	if (type.getDomain() instanceof IntegerType) {
		wrapperAttrib.setEType(ePackage.getELong());
	} else if (type.getDomain() instanceof RealType) {
		wrapperAttrib.setEType(ePackage.getEDouble());
	} else if (type.getDomain() instanceof StringType) {
		wrapperAttrib.setEType(ePackage.getEString());
	} else if (type.getDomain() instanceof BooleanType) {
		wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate"));
	} else if (type.getDomain() instanceof NumberType) {
		wrapperAttrib.setEType(ePackage.getEDouble());
	} else if (type.getDomain() instanceof BinaryType) {
		wrapperAttrib.setEType(ePackage.getEByteArray());
	} else if (type.getDomain() instanceof LogicalType) {
		wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate"));
	}
	wrapperAttrib.setUnsettable(true);
	testType.getEStructuralFeatures().add(wrapperAttrib);
	if (wrapperAttrib.getEType() == ePackage.getEDouble()) {
		EAttribute doubleStringAttribute = eFactory.createEAttribute();
		doubleStringAttribute.setEType(ePackage.getEString());
		doubleStringAttribute.setName("wrappedValueAsString");
		doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
		doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
		doubleStringAttribute.setUnsettable(true);
		testType.getEStructuralFeatures().add(doubleStringAttribute);
	}
	return wrapperAttrib;
}
 
Example 4
Source File: TypeHierarchyHelperTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private void addAttribute(EClassInfo eClass, EDataType eType, String name) {
	EAttribute feature = EcoreFactory.eINSTANCE.createEAttribute();
	feature.setName(name);
	feature.setEType(eType);
	eClass.getEClass().getEStructuralFeatures().add(feature);
}
 
Example 5
Source File: DefaultReferenceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCrossResourceContainment() {
	EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
	ePackage.setName("test");
	ePackage.setNsPrefix("test");
	ePackage.setNsURI("test");

	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	eClass.setName("Test");
	ePackage.getEClassifiers().add(eClass);
	
	EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute();
	nameAttribute.setName("name");
	nameAttribute.setID(true);
	nameAttribute.setEType(EcorePackage.Literals.ESTRING);
	eClass.getEStructuralFeatures().add(nameAttribute);

	EReference containmentRef = EcoreFactory.eINSTANCE.createEReference();
	containmentRef.setContainment(true);
	containmentRef.setName("crossResourceContainment");
	containmentRef.setEType(eClass);
	containmentRef.setResolveProxies(true);
	eClass.getEStructuralFeatures().add(containmentRef);
	
	EReference containerRef = EcoreFactory.eINSTANCE.createEReference();
	containerRef.setName("containerRef");
	containerRef.setEType(eClass);
	containerRef.setResolveProxies(true);
	containerRef.setEOpposite(containmentRef);
	containmentRef.setEOpposite(containerRef);
	eClass.getEStructuralFeatures().add(containerRef);

	EObject container = ePackage.getEFactoryInstance().create(eClass);
	EObject child = ePackage.getEFactoryInstance().create(eClass);
	
	Resource containerResource = new XMIResourceImpl(URI.createPlatformResourceURI("container.ecore", true));
	Resource childResource = new XMIResourceImpl(URI.createPlatformResourceURI("child.ecore", true));
	ResourceSet resourceSet = new ResourceSetImpl();
	resourceSet.getResources().add(containerResource);
	resourceSet.getResources().add(childResource);
	
	containerResource.getContents().add(container);
	childResource.getContents().add(child);
	
	container.eSet(containmentRef, child);
	assertTrue(container.eResource() != child.eResource());
	
	{ 
		IResourceDescription containerDescription = createResourceDescription(containerResource);
		IReferenceDescription onlyContainerElement = Iterables.getOnlyElement(containerDescription.getReferenceDescriptions());
		assertEquals(-1, onlyContainerElement.getIndexInList());
		assertEquals(EcoreUtil.getURI(container), onlyContainerElement.getSourceEObjectUri());
		assertEquals(containmentRef, onlyContainerElement.getEReference());
		assertEquals(EcoreUtil.getURI(child), onlyContainerElement.getTargetEObjectUri());
	}
	{
		IResourceDescription childDescription = createResourceDescription(childResource);
		IReferenceDescription onlyChildElement = Iterables.getOnlyElement(childDescription.getReferenceDescriptions());
		assertEquals(-1, onlyChildElement.getIndexInList());
		assertEquals(EcoreUtil.getURI(child), onlyChildElement.getSourceEObjectUri());
		assertEquals(containerRef, onlyChildElement.getEReference());
		assertEquals(EcoreUtil.getURI(container), onlyChildElement.getTargetEObjectUri());
	}
}
 
Example 6
Source File: DefaultReferenceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/** @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=330812 */
@Test public void testLazyLinkingProxyReferences() {
	URI resourceUri = URI.createPlatformResourceURI("test.ecore", true);
	LazyURIEncoder lazyURIEncoder = new LazyURIEncoder();

	ResourceSet resourceSet = new ResourceSetImpl();
	Resource testResource = resourceSet.createResource(resourceUri);

	EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
	ePackage.setName("test");
	ePackage.setNsPrefix("test");
	ePackage.setNsURI("test");
	testResource.getContents().add(ePackage);

	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	eClass.setName("Test");
	ePackage.getEClassifiers().add(eClass);

	EClass multiRefType = EcoreFactory.eINSTANCE.createEClass();
	((InternalEObject) multiRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE));
	eClass.getESuperTypes().add(multiRefType);

	EClass multiRefType2 = EcoreFactory.eINSTANCE.createEClass();
	URI dummyProxyUri = resourceUri.appendFragment(lazyURIEncoder.encode(eClass, EcorePackage.Literals.ECLASS__ESUPER_TYPES, null));
	((InternalEObject) multiRefType2).eSetProxyURI(dummyProxyUri);
	eClass.getESuperTypes().add(multiRefType2);

	EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute();
	nameAttribute.setName("name");
	eClass.getEStructuralFeatures().add(nameAttribute);
	EDataType singleRefType = EcoreFactory.eINSTANCE.createEDataType();
	((InternalEObject) singleRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.ESTRING));
	nameAttribute.setEType(singleRefType);

	assertTrue(multiRefType.eIsProxy());
	assertTrue(multiRefType2.eIsProxy());
	assertTrue(lazyURIEncoder.isCrossLinkFragment(testResource, EcoreUtil.getURI(multiRefType2).fragment()));
	assertTrue(singleRefType.eIsProxy());

	IResourceDescription resourceDescription = createResourceDescription(testResource);
	Iterable<IReferenceDescription> referenceDescriptions = resourceDescription.getReferenceDescriptions();
	assertEquals("Unexpected additional resources were loaded", 1, resourceSet.getResources().size());
	assertEquals("Unexpected reference was exported", 3, Iterables.size(referenceDescriptions));

	IReferenceDescription referenceDescription = Iterables.get(referenceDescriptions, 0);
	assertEquals(0, referenceDescription.getIndexInList());
	assertEquals(EcoreUtil.getURI(eClass), referenceDescription.getSourceEObjectUri());
	assertEquals(EcorePackage.Literals.ECLASS__ESUPER_TYPES, referenceDescription.getEReference());
	assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri());

	referenceDescription = Iterables.get(referenceDescriptions, 1);
	assertEquals(-1, referenceDescription.getIndexInList());
	assertEquals(EcoreUtil.getURI(nameAttribute.getEGenericType()), referenceDescription.getSourceEObjectUri());
	assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference());
	assertEquals(EcoreUtil.getURI(EcorePackage.Literals.ESTRING), referenceDescription.getTargetEObjectUri());

	referenceDescription = Iterables.get(referenceDescriptions, 2);
	assertEquals(-1, referenceDescription.getIndexInList());
	assertEquals(EcoreUtil.getURI(eClass.getEGenericSuperTypes().get(0)), referenceDescription.getSourceEObjectUri());
	assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference());
	assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri());
}
 
Example 7
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void doRealDerivedAttributes() {
	for (EntityDefinition entityDefinition : schema.getEntities()) {
		for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) {
			EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName());
			// EStructuralFeature derivedAttribute =
			// eFactory.createEReference();
			if (attributeName.getType() != null && !attributeName.hasSuper()) {
				// if (attributeName.getType() instanceof EntityDefinition)
				// {
				// derivedAttribute.setEType(schemaPack.getEClassifier(((EntityDefinition)
				// attributeName.getType()).getName()));
				// } else if (attributeName.getType() instanceof
				// IntegerType) {
				// derivedAttribute.setEType(schemaPack.getEClassifier("IfcInteger"));
				// } else if (attributeName.getType() instanceof RealType) {
				// derivedAttribute.setEType(schemaPack.getEClassifier("IfcReal"));
				// } else if (attributeName.getType() instanceof
				// LogicalType) {
				// derivedAttribute.setEType(schemaPack.getEClassifier("IfcLogical"));
				if (attributeName.getType() instanceof DefinedType) {
					EClassifier eType = schemaPack.getEClassifier(((DefinedType) attributeName.getType()).getName());
					boolean found = false;
					for (EClass eSuperType : eClass.getEAllSuperTypes()) {
						if (eSuperType.getEStructuralFeature(attributeName.getName()) != null) {
							found = true;
							break;
						}
					}
					if (eType.getEAnnotation("wrapped") != null) {
						if (!found) {
							EAttribute eAttribute = eFactory.createEAttribute();
							eAttribute.setDerived(true);
							eAttribute.setName(attributeName.getName());
							if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
								eAttribute.setUpperBound(3);
								eAttribute.setUnique(false);
							}
							EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
							eAttribute.setEType(type);
							eAttribute.setUnsettable(true); // TODO find out
															// if its
															// optional
							eClass.getEStructuralFeatures().add(eAttribute);
							if (type == EcorePackage.eINSTANCE.getEDouble()) {
								EAttribute doubleStringAttribute = eFactory.createEAttribute();
								doubleStringAttribute.setName(attributeName.getName() + "AsString");
								doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
								doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
								doubleStringAttribute.setUnsettable(true); // TODO
																			// find
																			// out
																			// if
																			// its
																			// optional
								doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
								eClass.getEStructuralFeatures().add(doubleStringAttribute);
							}
						}
					} else {
						if (!found) {
							EReference eReference = eFactory.createEReference();
							eReference.setName(attributeName.getName());
							eReference.setDerived(true);
							eReference.setUnsettable(true);
							eReference.setEType(eType);
							eClass.getEStructuralFeatures().add(eReference);
						}
					}
					// derivedAttribute.setEType(eType);
				}
			}
			// derivedAttribute.setName(attributeName.getName());
			// derivedAttribute.setDerived(true);
			// derivedAttribute.setTransient(true);
			// derivedAttribute.setVolatile(true);
			// if (attributeName.isCollection()) {
			// derivedAttribute.setUpperBound(-1);
			// }
			// EAnnotation annotation = eFactory.createEAnnotation();
			// annotation.setSource("http://www.iso.org/iso10303-11/EXPRESS");
			// annotation.getDetails().put("code",
			// attributeName.getExpressCode());
			// derivedAttribute.getEAnnotations().add(annotation);
			// if (eClass.getEStructuralFeature(derivedAttribute.getName())
			// == null) {
			// eClass.getEStructuralFeatures().add(derivedAttribute);
			// }
		}
	}
}
 
Example 8
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);
}