Java Code Examples for org.eclipse.emf.ecore.EEnumLiteral.setValue()

The following are Jave code examples for showing how to use setValue() of the org.eclipse.emf.ecore.EEnumLiteral class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OCCI-Studio   File: OCCIExtension2Ecore.java   Source Code and License Vote up 6 votes
private EEnum createEnumerationType(EnumerationType type) {
	EEnum eenum = EcoreFactory.eINSTANCE.createEEnum();
	eenum.setName(type.getName());
	int value = 0;
	for (EnumerationLiteral literal : type.getLiterals()) {
		EEnumLiteral eenumliteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
		eenum.getELiterals().add(eenumliteral);
		eenumliteral.setName(literal.getName());
		eenumliteral.setLiteral(literal.getName());
		eenumliteral.setValue(value);
		value++;
		if (literal.getDocumentation() != null) {
			attachInfo(eenumliteral, literal.getDocumentation());
		}
	}
	if (type.getDocumentation() != null) {
		attachInfo(eenum, type.getDocumentation());
	}
	return eenum;
}
 
Example 2
Project: BIMserver   File: Schema.java   Source Code and License Vote up 6 votes
public EEnumLiteral createEEnumLiteral(EEnum eEnum, String name) {
	EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
	if (eEnum.getELiterals().size() == 0) {
		eEnumLiteral.setValue(0);
	} else {
		int largestValue = Integer.MIN_VALUE;
		for (EEnumLiteral existingLiteral : eEnum.getELiterals()) {
			if (existingLiteral.getValue() > largestValue) {
				largestValue = existingLiteral.getValue();
			}
		}
		eEnumLiteral.setValue(largestValue + 1);
	}
	eEnum.getELiterals().add(eEnumLiteral);
	eEnumLiteral.setName(name);
	return eEnumLiteral;
}
 
Example 3
Project: BIMserver   File: Express2EMF.java   Source Code and License Vote up 6 votes
private void createTristate() {
	tristate = eFactory.createEEnum();
	tristate.setName("Tristate");
	EEnumLiteral trueLiteral = eFactory.createEEnumLiteral();
	trueLiteral.setName("TRUE");
	trueLiteral.setValue(0);
	EEnumLiteral falseLiteral = eFactory.createEEnumLiteral();
	falseLiteral.setName("FALSE");
	falseLiteral.setValue(1);
	EEnumLiteral undefinedLiteral = eFactory.createEEnumLiteral();
	undefinedLiteral.setName("UNDEFINED");
	undefinedLiteral.setValue(2);
	tristate.getELiterals().add(trueLiteral);
	tristate.getELiterals().add(falseLiteral);
	tristate.getELiterals().add(undefinedLiteral);
	schemaPack.getEClassifiers().add(tristate);
}
 
Example 4
Project: anatlyzer   File: WitnessGenerator.java   Source Code and License Vote up 5 votes
/**
 * It makes a shallow copy of an enumerate literal.
 * @param literal
 */
private EEnumLiteral clone (EEnumLiteral literal) {
	EEnumLiteral copy = EcoreFactory.eINSTANCE.createEEnumLiteral();
	copy.setLiteral(literal.getLiteral());
	copy.setName   (literal.getName());
	copy.setValue  (literal.getValue());
	return copy;
}
 
Example 5
Project: anatlyzer   File: WitnessGenerator.java   Source Code and License Vote up 5 votes
/**
 * It makes a shallow copy of an enumerate literal.
 * @param literal
 */
private EEnumLiteral clone (EEnumLiteral literal) {
	EEnumLiteral copy = EcoreFactory.eINSTANCE.createEEnumLiteral();
	copy.setLiteral(literal.getLiteral());
	copy.setName   (literal.getName());
	copy.setValue  (literal.getValue());
	return copy;
}
 
Example 6
Project: BIMserver   File: Schema.java   Source Code and License Vote up 5 votes
public EEnumLiteral createEEnumLiteral(EEnum eEnum, String name, int value) {
	EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
	eEnumLiteral.setValue(value);
	eEnum.getELiterals().add(eEnumLiteral);
	eEnumLiteral.setName(name);
	return eEnumLiteral;
}
 
Example 7
Project: BIMserver   File: Express2EMF.java   Source Code and License Vote up 5 votes
private void addEnumerations() {
	Iterator<DefinedType> typeIter = schema.getTypes().iterator();
	while (typeIter.hasNext()) {
		DefinedType type = typeIter.next();
		if (type instanceof EnumerationType) {
			EEnum enumeration = eFactory.createEEnum();
			enumeration.setName(type.getName());

			EEnumLiteral nullValue = eFactory.createEEnumLiteral();
			nullValue.setName("NULL");
			nullValue.setLiteral("NULL");
			nullValue.setValue(0);
			enumeration.getELiterals().add(nullValue);

			int counter = 1;
			Iterator<String> values = ((EnumerationType) type).getElements().iterator();
			while (values.hasNext()) {
				String stringVal = values.next();
				if (!stringVal.equals("NULL")) {
					EEnumLiteral value = eFactory.createEEnumLiteral();
					value.setName(stringVal);
					value.setLiteral(stringVal);
					value.setValue(counter);
					counter++;
					enumeration.getELiterals().add(value);
				}
			}
			schemaPack.getEClassifiers().add(enumeration);
		}
	}
}
 
Example 8
Project: xtext-core   File: Xtext2EcoreTransformer.java   Source Code and License Vote up 4 votes
private void deriveEnums(EnumRule rule) {
	EEnum returnType = (EEnum) rule.getType().getClassifier();
	if (returnType != null) {
		List<EnumLiteralDeclaration> decls = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
		for(EnumLiteralDeclaration decl : decls) {
			if (decl.getEnumLiteral() == null) {
				List<INode> nodes = NodeModelUtils.findNodesForFeature(decl, XtextPackage.Literals.ENUM_LITERAL_DECLARATION__ENUM_LITERAL);
				if (!nodes.isEmpty()) {
					if (nodes.size() > 1)
						throw new IllegalStateException("Unexpected nodes found: " + nodes);
					INode node = nodes.get(0);
					String text = node.getText();
					EEnumLiteral literal = null;
					if (rule.getType().getMetamodel() instanceof ReferencedMetamodel) {
						literal = returnType.getEEnumLiteral(text);
					} else {
						EEnumLiteral existing = returnType.getEEnumLiteral(text);
						if (existing == null) {
							literal = EcoreFactory.eINSTANCE.createEEnumLiteral();
							int index = returnType.getELiterals().size();
							returnType.getELiterals().add(literal);
							literal.setName(text);
							literal.setValue(index);
							if (decl.getLiteral() != null) {
								literal.setLiteral(decl.getLiteral().getValue());
							} else {
								literal.setLiteral(text);
							}
						} else {
							literal = existing;
						}
						SourceAdapter.adapt(literal, decl);
					}
					if (literal == null) {
						reportError(new TransformationException(TransformationErrorCode.InvalidFeature, "Enum literal '" + text + "' does not exist.", decl));
					} else {
						decl.setEnumLiteral(literal);
					}
				}
			}
			if (decl.getLiteral() == null && decl.getEnumLiteral() != null) {
				Keyword kw = XtextFactory.eINSTANCE.createKeyword();
				kw.setValue(decl.getEnumLiteral().getLiteral());
				decl.setLiteral(kw);
			}
		}
	}
}
 
Example 9
Project: caml2tosca   File: ToscaUtil.java   Source Code and License Vote up 4 votes
public static String createPropertiesDefinition(Classifier classifier) throws Exception {		
	EPackage _package = EcoreFactory.eINSTANCE.createEPackage();
	EClass propertyDefinition = EcoreFactory.eINSTANCE.createEClass();
	GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
	ExtendedMetaData extendedMetaData = genModel.getExtendedMetaData();
	
	List<EStructuralFeature> features = new ArrayList<EStructuralFeature>();
	String propertiesDefinition = "";
	
	for(Property property : classifier.getAttributes()) {
		// consider attributes only if they aren't members of an association
		if(property.getAssociation() == null) {
			EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute();
			attribute.setName(property.getName());
			attribute.setUnsettable(true);
			
			// create an EEnum in case of enumeration
			if(property.getType() instanceof Enumeration) {
				Enumeration enumeration = (Enumeration) property.getType(); 
				EEnum eenumeration = EcoreFactory.eINSTANCE.createEEnum();
				eenumeration.setName(enumeration.getName());
				
				int literalValue = 0;
				for(EnumerationLiteral literal : enumeration.getOwnedLiterals()) {
					EEnumLiteral eliteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
					eliteral.setName(literal.getName());
					eliteral.setValue(literalValue);
					literalValue++;
					eenumeration.getELiterals().add(eliteral);
				}
				
				_package.getEClassifiers().add(eenumeration);
				attribute.setEType(eenumeration);
			}
			else {
				attribute.setEType(XMLTypePackage.eINSTANCE.getString());
			}
			propertyDefinition.getEStructuralFeatures().add(attribute);
			extendedMetaData.setFeatureKind(attribute, ExtendedMetaData.ELEMENT_FEATURE);
			features.add(attribute);
		}
	}
	
	if(!features.isEmpty()) {
		// first step: create an Ecore metamodel		
		URI uri = URI.createFileURI(new File(Path + classifier.getName() + Ecore_Model_Fragment).getAbsolutePath());
		Resource resource = Resource_Set.createResource(uri);

		_package.setName(classifier.getName() + "Properties");
		_package.setNsPrefix(classifier.getName() + "Properties");
		_package.setNsURI("http://" + classifier.getName() + "Properties");
		resource.getContents().add(_package);
		propertyDefinition.setName("Properties");
		_package.getEClassifiers().add(propertyDefinition);
		
		// second step: derive the GenModel from the metamodel
		genModel.setComplianceLevel(GenJDKLevel.JDK70_LITERAL);		 
		genModel.setModelDirectory("");
		genModel.setModelName(_package.getName());
		genModel.initialize(Collections.singleton(_package));
			
		// third step: export the XSD from the GenModel			
		XSDExporter modelExporter = new XSDExporter();
		modelExporter.setGenModel(genModel);
		modelExporter.getEPackages().add(_package);
		EPackageConvertInfo convertInfo = modelExporter.getEPackageConvertInfo(_package);
		convertInfo.setConvert(true);
		EPackageExportInfo exportInfo = modelExporter.getEPackageExportInfo(_package);
		exportInfo.setArtifactLocation(Path + classifier.getName() + Xsd_Model_Fragment);
		modelExporter.export(null); 
		
		// the name of the properties definition; it allows node types to reference it
		propertiesDefinition = classifier.getName() + "Properties";
	}
	return propertiesDefinition;
}