Java Code Examples for org.eclipse.emf.ecore.EEnumLiteral#setName()
The following examples show how to use
org.eclipse.emf.ecore.EEnumLiteral#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: Schema.java From BIMserver with GNU Affero General Public License v3.0 | 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 2
Source File: Express2EMF.java From BIMserver with GNU Affero General Public License v3.0 | 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 3
Source File: Schema.java From BIMserver with GNU Affero General Public License v3.0 | 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 4
Source File: Express2EMF.java From BIMserver with GNU Affero General Public License v3.0 | 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 5
Source File: Xtext2EcoreTransformer.java From xtext-core with Eclipse Public License 2.0 | 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); } } } }