org.eclipse.emf.ecore.EEnum Java Examples

The following examples show how to use org.eclipse.emf.ecore.EEnum. 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: MaterializingBackwardConverter.java    From bonita-studio with 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 File: PackageJsonUtils.java    From n4js with 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 File: Ecore2UimaTypeSystem.java    From uima-uimaj with 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 #4
Source File: Schema.java    From BIMserver with 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 #5
Source File: XtextScopeProvider.java    From xtext-core with 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 #6
Source File: Step0031.java    From BIMserver with 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 #7
Source File: AttributePackageImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getOrientation( )
{
	return orientationEEnum;
}
 
Example #8
Source File: SetWrappedAttributeChange.java    From BIMserver with 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 #9
Source File: ProtocolPackageImpl.java    From neoscada with 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 #10
Source File: Bug286935TestLanguagePackageImpl.java    From xtext-eclipse with 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 #11
Source File: IfcSchemaToJson.java    From BIMserver with 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 File: Bug287941TestLanguagePackageImpl.java    From xtext-eclipse with 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 #13
Source File: Bug287941TestLanguagePackageImpl.java    From xtext-eclipse with 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 #14
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public EEnum getEEnum(String name) {
	return (EEnum) ePackage.getEClassifier(name);
}
 
Example #15
Source File: GenModelAccess.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public static GenEnum getGenEnum(EEnum en, ResourceSet resourceSet) {
	return (GenEnum) getGenClassifier(en, resourceSet);
}
 
Example #16
Source File: Bug360834TestLanguagePackageImpl.java    From xtext-eclipse with 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 #17
Source File: Bug378967TestPackageImpl.java    From xtext-core with 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 #18
Source File: EnumAndReferenceTestLanguagePackageImpl.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getKindOfKeyword()
{
  return kindOfKeywordEEnum;
}
 
Example #19
Source File: Step0017.java    From BIMserver with 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 #20
Source File: RegionaccesstestlanguagePackageImpl.java    From xtext-core with 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 #21
Source File: Xtext2EcoreTransformer.java    From xtext-core with 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 #22
Source File: ProcessAbstractExpression.java    From bonita-studio with 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 #23
Source File: Bug289187TestLanguagePackageImpl.java    From xtext-eclipse with 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 #24
Source File: Xtext2EcoreTransformer.java    From xtext-core with 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 #25
Source File: VisualInterfacePackageImpl.java    From neoscada with 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 #26
Source File: AttributePackageImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getTickStyle( )
{
	return tickStyleEEnum;
}
 
Example #27
Source File: InfrastructurePackageImpl.java    From neoscada with 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 #28
Source File: AttributePackageImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public EEnum getLeaderLineStyle( )
{
	return leaderLineStyleEEnum;
}
 
Example #29
Source File: NoLiteralsPackageImpl.java    From xtext-core with 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 #30
Source File: RootPackageImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EEnum getRootEnum()
{
	return rootEnumEEnum;
}