Java Code Examples for org.eclipse.emf.ecore.EEnum

The following examples show how to use org.eclipse.emf.ecore.EEnum. These examples are extracted from open source projects. 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 Project: bonita-studio   Author: bonitasoft   File: MaterializingBackwardConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Enumerator resolveLiteral(Object literal) {
	if (EEnumLiteral.class.isInstance(literal)) {
		final EEnum sourceEnum = EEnumLiteral.class.cast(literal).getEEnum();
		final String value = sourceEnum.getEPackage().getEFactoryInstance()
			.convertToString(sourceEnum, literal);
		final EEnum targetEnum = (EEnum) resolveEClassifier(sourceEnum);
		return (Enumerator) targetEnum.getEPackage().getEFactoryInstance()
			.createFromString(targetEnum, value);
	} else if (Enumerator.class.isInstance(literal)) {
		return Enumerator.class.cast(literal);
	} else if (literal == null) {
		return null;
	}
	throw new IllegalArgumentException(MessageFormat.format(
		"Unexpected literal {0} of type {1} cannot be converted to an Enumerator", literal, literal.getClass())); //$NON-NLS-1$
}
 
Example #2
Source Project: n4js   Author: eclipse   File: PackageJsonUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static <T extends Enumerator> T parseEnumLiteral(EEnum emfEnumType, Class<T> javaEnumType,
		String enumLiteralStr) {
	EEnumLiteral emfLit = enumLiteralStr != null ? emfEnumType.getELiterals().stream()
			.filter(lit -> lit.getName().equalsIgnoreCase(enumLiteralStr))
			.findFirst().orElse(null) : null;
	if (emfLit == null) {
		return null;
	}
	final Enumerator javaLit = emfLit.getInstance();
	@SuppressWarnings("unchecked")
	T javaLitCasted = javaEnumType.isInstance(javaLit) ? (T) javaLit : null;
	return javaLitCasted;
}
 
Example #3
Source Project: BIMserver   Author: opensourceBIM   File: Schema.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public EEnum createEEnum(EPackage ePackage, String name) {
	EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
	changes.add(new NewEnumChange(eEnum));
	ePackage.getEClassifiers().add(eEnum);
	eEnum.setName(name);
	return eEnum;
}
 
Example #4
Source Project: xtext-core   Author: eclipse   File: XtextScopeProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected IScope createEnumLiteralsScope(EEnum eEnum) {
	return new SimpleScope(IScope.NULLSCOPE,Iterables.transform(eEnum.getELiterals(), new Function<EEnumLiteral, IEObjectDescription>() {
						@Override
						public IEObjectDescription apply(EEnumLiteral param) {
							return EObjectDescription.create(QualifiedName.create(param.getName()), param);
						}
					}));
}
 
Example #5
Source Project: BIMserver   Author: opensourceBIM   File: Step0031.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void migrate(Schema schema, DatabaseSession databaseSession) {
	EEnum serviceStatus = schema.getEEnum("store", "ServiceStatus");
	schema.createEEnumLiteral(serviceStatus, "NO_AUTHENTICATION");
	
	EEnum pluginBundleType = schema.getEEnum("store", "PluginBundleType");
	schema.createEEnumLiteral(pluginBundleType, "LOCAL_DEV");
}
 
Example #6
Source Project: uima-uimaj   Author: apache   File: Ecore2UimaTypeSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Eenum 2 uima type.
 *
 * @param aEEnum the a E enum
 * @param aUimaNamespace the a uima namespace
 * @param aOptions the a options
 * @return the type description
 * @throws URISyntaxException the URI syntax exception
 */
private static TypeDescription eenum2UimaType(EEnum aEEnum, String aUimaNamespace, Map aOptions)
        throws URISyntaxException {
  TypeDescription type = uimaFactory.createTypeDescription();
  // set name
  if (aUimaNamespace != null) {
    type.setName(aUimaNamespace + "." + aEEnum.getName());
  } else {
    type.setName(aEEnum.getName());
  }
  // set supetype to String
  type.setSupertypeName(CAS.TYPE_NAME_STRING);
  // try to get desecription from EAnnotation
  EAnnotation eannot = aEEnum.getEAnnotation("http://uima.apache.org");
  if (eannot != null) {
    type.setDescription((String) eannot.getDetails().get("description"));
  }
  // set allowed values
  EList literals = aEEnum.getELiterals();
  AllowedValue[] vals = new AllowedValue[literals.size()];
  for (int i = 0; i < literals.size(); i++) {
    EEnumLiteral literal = (EEnumLiteral) literals.get(i);
    vals[i] = uimaFactory.createAllowedValue();
    vals[i].setString(literal.getName());
    EAnnotation literalAnnot = literal.getEAnnotation("http://uima.apache.org");
    if (literalAnnot != null) {
      vals[i].setDescription((String) literalAnnot.getDetails().get("description"));
    }
  }
  type.setAllowedValues(vals);
  return type;
}
 
Example #7
Source Project: xtext-core   Author: eclipse   File: Bug378967TestPackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getSecondEnum()
{
  return secondEnumEEnum;
}
 
Example #8
Source Project: xtext-eclipse   Author: eclipse   File: Bug286935TestLanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getStateType()
{
  return stateTypeEEnum;
}
 
Example #9
Source Project: xtext-eclipse   Author: eclipse   File: Bug287941TestLanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getBooleanOperator()
{
  return booleanOperatorEEnum;
}
 
Example #10
Source Project: xtext-eclipse   Author: eclipse   File: Bug332217TestLanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getCellType()
{
  return cellTypeEEnum;
}
 
Example #11
Source Project: BIMserver   Author: opensourceBIM   File: IfcSchemaToJson.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
private void convert(OutputStream outputStream, File docs, EPackage ePackage) throws IOException {
	IfcDoc ifcDoc = null;
	if (docs != null) {
		ifcDoc = new IfcDoc(docs);
	}
	
	ObjectMapper objectMapper = new ObjectMapper();
	ObjectNode root = objectMapper.createObjectNode();
	ObjectNode classes = objectMapper.createObjectNode();
	root.set("classes", classes);
	for (EClassifier eClassifier : ePackage.getEClassifiers()) {
		ObjectNode classifierNode = objectMapper.createObjectNode();
		classes.set(eClassifier.getName(), classifierNode);
		if (eClassifier instanceof EEnum) {
			
		} else if (eClassifier instanceof EClass) {
			EClass eClass = (EClass)eClassifier;
			String domain = "geometry";
			if (ifcDoc != null) {
				domain = ifcDoc.getDomain(eClass.getName());
			}
			classifierNode.put("domain", domain);
			ArrayNode superClassesNode = objectMapper.createArrayNode();
			classifierNode.set("superclasses", superClassesNode);
			
			for (EClass superClass : eClass.getESuperTypes()) {
				superClassesNode.add(superClass.getName());
			}

			ObjectNode fieldsNode = objectMapper.createObjectNode();
			classifierNode.set("fields", fieldsNode);
			for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
				ObjectNode fieldNode = objectMapper.createObjectNode();
				fieldsNode.set(eStructuralFeature.getName(), fieldNode);
				fieldNode.put("type", convertType(eStructuralFeature.getEType()));
				fieldNode.put("reference", eStructuralFeature instanceof EReference);
				fieldNode.put("many", eStructuralFeature.isMany());
				fieldNode.put("inverse", eStructuralFeature.getEAnnotation("inverse") != null);
			}
		}
	}
	objectMapper.writerWithDefaultPrettyPrinter().writeValue(outputStream, root);
}
 
Example #12
Source Project: neoscada   Author: eclipse   File: ProtocolPackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getType ()
{
    return typeEEnum;
}
 
Example #13
Source Project: BIMserver   Author: opensourceBIM   File: SetWrappedAttributeChange.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException,
		BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
	
	Query query = new Query(packageMetaData);
	QueryPart queryPart = query.createQueryPart();
	queryPart.addOid(oid);
	
	HashMapVirtualObject object = transaction.get(oid);
	
	if (object == null) {
		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}

	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	EReference eReference = packageMetaData.getEReference(eClass.getName(), attributeName);
	if (eReference == null) {
		throw new UserException("No reference with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (value instanceof List && eReference.isMany()) {
		List sourceList = (List)value;
		if (!eReference.isMany()) {
			throw new UserException("Attribute is not of type 'many'");
		}
		List list = (List)object.eGet(eReference);
		for (Object o : sourceList) {
			if (eReference.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
				List asStringList = (List)object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
				asStringList.add(String.valueOf(o));
			}
			list.add(o);
		}
	} else {
		if (eReference.isMany()) {
			throw new UserException("Attribute is not of type 'single'");
		}
		if (eReference.getEType() instanceof EEnum) {
			EEnum eEnum = (EEnum) eReference.getEType();
			object.set(eReference.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
		} else {
			EClass typeEClass = (EClass) packageMetaData.getEClassifier(type);
			if (typeEClass.getEAnnotation("wrapped") == null) {
				throw new UserException("Not a wrapped type");
			}
			HashMapWrappedVirtualObject wrappedObject = new HashMapWrappedVirtualObject(typeEClass);
			if (typeEClass == Ifc2x3tc1Package.eINSTANCE.getIfcBoolean()) {
				if ((Boolean)value == true) {
					value = Tristate.TRUE;
				} else {
					value = Tristate.FALSE;
				}
			}
			wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValue").getName(), value);
			object.set(eReference.getName(), wrappedObject);
			if (value instanceof Double) {
				wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValueAsString").getName(), String.valueOf((Double)value));
			}
		}
	}
}
 
Example #14
Source Project: xtext-core   Author: eclipse   File: Xtext2EcoreTransformer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
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 #15
Source Project: xtext-eclipse   Author: eclipse   File: Bug287941TestLanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getStringOperator()
{
  return stringOperatorEEnum;
}
 
Example #16
Source Project: bonita-studio   Author: bonitasoft   File: ProcessAbstractExpression.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
* Expression may return number value which is not directly compatible with feature type (e.g. Double when Integer is expected), or EEnumLiteral meta-object when literal instance is expected
* @generated
*/
public static Object performCast(Object value, EDataType targetType) {
	if (targetType instanceof EEnum) {
		if (value instanceof EEnumLiteral) {
			EEnumLiteral literal = (EEnumLiteral) value;
			return (literal.getInstance() != null) ? literal.getInstance() : literal;
		}
	}
	if (false == value instanceof Number || targetType == null || targetType.getInstanceClass() == null) {
		return value;
	}
	Class<?> targetClass = targetType.getInstanceClass();
	Number num = (Number) value;
	Class<?> valClass = value.getClass();
	Class<?> targetWrapperClass = targetClass;
	if (targetClass.isPrimitive()) {
		targetWrapperClass = EcoreUtil.wrapperClassFor(targetClass);
	}
	if (valClass.equals(targetWrapperClass)) {
		return value;
	}
	if (Number.class.isAssignableFrom(targetWrapperClass)) {
		if (targetWrapperClass.equals(Byte.class))
			return new Byte(num.byteValue());
		if (targetWrapperClass.equals(Integer.class))
			return new Integer(num.intValue());
		if (targetWrapperClass.equals(Short.class))
			return new Short(num.shortValue());
		if (targetWrapperClass.equals(Long.class))
			return new Long(num.longValue());
		if (targetWrapperClass.equals(BigInteger.class))
			return BigInteger.valueOf(num.longValue());
		if (targetWrapperClass.equals(Float.class))
			return new Float(num.floatValue());
		if (targetWrapperClass.equals(Double.class))
			return new Double(num.doubleValue());
		if (targetWrapperClass.equals(BigDecimal.class))
			return new BigDecimal(num.doubleValue());
	}
	return value;
}
 
Example #17
Source Project: neoscada   Author: eclipse   File: VisualInterfacePackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getAlignment ()
{
    return alignmentEEnum;
}
 
Example #18
Source Project: neoscada   Author: eclipse   File: InfrastructurePackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getSlaveStorageLayout ()
{
    return slaveStorageLayoutEEnum;
}
 
Example #19
Source Project: xtext-core   Author: eclipse   File: RootPackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getRootEnum()
{
	return rootEnumEEnum;
}
 
Example #20
Source Project: xtext-core   Author: eclipse   File: NoLiteralsPackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getNoLitEnum()
{
	return noLitEnumEEnum;
}
 
Example #21
Source Project: birt   Author: eclipse   File: AttributePackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getLeaderLineStyle( )
{
	return leaderLineStyleEEnum;
}
 
Example #22
Source Project: birt   Author: eclipse   File: AttributePackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getTickStyle( )
{
	return tickStyleEEnum;
}
 
Example #23
Source Project: xtext-core   Author: eclipse   File: Xtext2EcoreTransformer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
private boolean deriveTypeHierarchy() {
	boolean result = true;
	for (AbstractRule rule : grammar.getRules()) {
		try {
			EClassifierInfo generatedEClass = findOrCreateEClassifierInfo(rule);
			if (generatedEClass != null || !isWildcardFragment(rule)) {
				if (rule instanceof ParserRule) {
					ParserRule parserRule = (ParserRule) rule;
					if (parserRule.getAlternatives() != null) {
						if (!GrammarUtil.isDatatypeRule(parserRule)) {
							deriveTypesAndHierarchy(parserRule, generatedEClass, parserRule.getAlternatives());
						} else {
							checkSupertypeOfOverriddenDatatypeRule(rule);
						}
					}
				} else if (rule instanceof TerminalRule) {
					if (rule.getType() != null) {
						if (!(rule.getType().getClassifier() instanceof EDataType))
							throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable,
									"Return type of a terminal rule must be an EDataType.", rule.getType());
						checkSupertypeOfOverriddenDatatypeRule(rule);
					}
				} else if (rule instanceof EnumRule) {
					if (rule.getType() != null) {
						if (!(rule.getType().getClassifier() instanceof EEnum))
							throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable,
									"Return type of an enum rule must be an EEnum.", rule.getType());
						checkSupertypeOfOverriddenDatatypeRule(rule);
					}
				} else {
					throw new IllegalStateException("Unknown rule type: " + rule.eClass().getName());
				}
			}
			if (isWildcardFragment(rule)) {
				for (Grammar usedGrammar: grammar.getUsedGrammars()) {
					deriveTypeHierarchyFromOverridden((ParserRule) rule, usedGrammar);
				}
			}
		}
		catch (TransformationException e) {
			reportError(e);
			result = false;
		}
	}
	return result;
}
 
Example #24
Source Project: xtext-eclipse   Author: eclipse   File: Bug289187TestLanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getVisibility()
{
  return visibilityEEnum;
}
 
Example #25
Source Project: xtext-core   Author: eclipse   File: RegionaccesstestlanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getEnum()
{
  return enumEEnum;
}
 
Example #26
Source Project: BIMserver   Author: opensourceBIM   File: Step0017.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void migrate(Schema schema, DatabaseSession databaseSession) {
	EEnum smtpProtocol = schema.getEEnum("store", "SmtpProtocol");
	schema.createEEnumLiteral(smtpProtocol, "STARTTLS");
}
 
Example #27
Source Project: BIMserver   Author: opensourceBIM   File: PackageMetaData.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
public EEnum getEEnum(String name) {
	return (EEnum) ePackage.getEClassifier(name);
}
 
Example #28
Source Project: xtext-eclipse   Author: eclipse   File: Bug360834TestLanguagePackageImpl.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getVisibility()
{
  return visibilityEEnum;
}
 
Example #29
Source Project: birt   Author: eclipse   File: AttributePackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getRuleType( )
{
	return ruleTypeEEnum;
}
 
Example #30
Source Project: birt   Author: eclipse   File: AttributePackageImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getGroupingUnitType( )
{
	return groupingUnitTypeEEnum;
}