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

The following are top voted examples for showing how to use org.eclipse.emf.ecore.EEnumLiteral. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: BIMplatform   File: IfcStepStreamingDeserializer.java   Source Code and License 6 votes vote down vote up
private void readEnum(String val, VirtualObject object, EStructuralFeature structuralFeature) throws DeserializeException, MetaDataException, DatabaseException {
	if (val.equals(".T.")) {
		object.setAttribute(structuralFeature, Boolean.TRUE);
	} else if (val.equals(".F.")) {
		object.setAttribute(structuralFeature, Boolean.FALSE);
	} else if (val.equals(".U.")) {
		object.eUnset(structuralFeature);
	} else {
		if (structuralFeature.getEType() instanceof EEnumImpl) {
			String realEnumValue = val.substring(1, val.length() - 1);
			EEnumLiteral enumValue = (((EEnumImpl) structuralFeature.getEType()).getEEnumLiteral(realEnumValue));
			if (enumValue == null) {
				throw new DeserializeException(lineNumber, "Enum type " + structuralFeature.getEType().getName() + " has no literal value '" + realEnumValue + "'");
			}
			object.setAttribute(structuralFeature, enumValue.getLiteral());
		} else {
			throw new DeserializeException(lineNumber, "Value " + val + " indicates enum type but " + structuralFeature.getEType().getName() + " expected");
		}
	}
}
 
Example 2
Project: BIMplatform   File: PackageMetaData.java   Source Code and License 6 votes vote down vote up
public EEnumLiteral getEEnumLiteral(String enumName, String literalName) {
	EClassifier eClassifier = ePackage.getEClassifier(enumName);
	if (eClassifier == null) {
		throw new RuntimeException("Classifier " + enumName + " not found in package " + ePackage.getName());
	}
	if (eClassifier instanceof EEnum) {
		EEnum eEnum = (EEnum)eClassifier;
		EEnumLiteral literal = eEnum.getEEnumLiteral(literalName);
		if (literal == null) {
			throw new RuntimeException("No enum literal " + literalName + " found on " + ePackage.getName() + "." + enumName);
		}
		return literal;
	} else {
		throw new RuntimeException("Classifier " + enumName + " is not of type enum");
	}
}
 
Example 3
Project: JavaGraph   File: EcoreToType.java   Source Code and License 6 votes vote down vote up
private Enum visitEnum(TypeModel mm, EEnum eEnum) {
    Id enumID = EcoreUtil.idFromClassifier(eEnum);

    if (mm.hasEnum(enumID)) {
        return mm.getEnum(enumID);
    }

    Enum cmEnum = mm.getEnum(enumID, true);

    for (EEnumLiteral eEnumLiteral : eEnum.getELiterals()) {
        Name litName = Name.getName(eEnumLiteral.getName());
        cmEnum.addLiteral(litName);
    }

    return cmEnum;
}
 
Example 4
Project: OCCI-Studio   File: OCCIExtension2Ecore.java   Source Code and License 6 votes vote down vote up
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 5
Project: IfcPlugins   File: IfcXmlDeserializer.java   Source Code and License 6 votes vote down vote up
private Object parsePrimitive(EClassifier eType, String text) throws DeserializeException {
	if (eType == EcorePackage.eINSTANCE.getEString()) {
		return text;
	} else if (eType == EcorePackage.eINSTANCE.getEInt()) {
		return Integer.parseInt(text);
	} else if (eType == EcorePackage.eINSTANCE.getELong()) {
		return Long.parseLong(text);
	} else if (eType == EcorePackage.eINSTANCE.getEDouble()) {
		return Double.parseDouble(text);
	} else if (eType == EcorePackage.eINSTANCE.getEBoolean()) {
		return Boolean.parseBoolean(text);
	} else if (eType instanceof EEnum) {
		EEnumLiteral eEnumLiteral = ((EEnum) eType).getEEnumLiteral(text.toUpperCase());
		if (eEnumLiteral == null) {
			if (text.equals("unknown")) {
				return null;
			} else {
				throw new DeserializeException("Unknown enum literal " + text + " in enum " + ((EEnum) eType).getName());
			}
		}
		return eEnumLiteral.getInstance();
	} else {
		throw new DeserializeException("Unimplemented primitive type: " + eType.getName());
	}
}
 
Example 6
Project: xtext-core   File: GrammarParserTest.java   Source Code and License 6 votes vote down vote up
@Test public void testEnum_01() throws Exception {
	String modelAsString =
		"grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" +
		"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/1'\n" +
		"Model: enumValue=MyEnum;\n" +
		"enum MyEnum: Value1;";
	Grammar grammar = (Grammar) getModel(modelAsString);
	assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
	checkEnums(grammar);
	EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
	assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/1", pack.getNsURI());
	EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
	assertNotNull(eEnum);
	assertEquals(1, eEnum.getELiterals().size());
	EEnumLiteral value = eEnum.getELiterals().get(0);
	assertEquals("Value1", value.getName());
	assertEquals(0, value.getValue());
	assertEquals("Value1", value.getLiteral());
}
 
Example 7
Project: xtext-core   File: GrammarParserTest.java   Source Code and License 6 votes vote down vote up
@Test public void testEnum_02() throws Exception {
	String modelAsString =
		"grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" +
		"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/2'\n" +
		"Model: enumValue=MyEnumRule;\n" +
		"enum MyEnumRule returns MyEnum: Value1;";
	Grammar grammar = (Grammar) getModel(modelAsString);
	assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
	checkEnums(grammar);
	EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
	assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/2", pack.getNsURI());
	EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
	assertNotNull(eEnum);
	assertEquals(1, eEnum.getELiterals().size());
	EEnumLiteral value = eEnum.getELiterals().get(0);
	assertEquals("Value1", value.getName());
	assertEquals(0, value.getValue());
	assertEquals("Value1", value.getLiteral());
}
 
Example 8
Project: xtext-core   File: GrammarParserTest.java   Source Code and License 6 votes vote down vote up
@Test public void testEnum_03() throws Exception {
	String modelAsString =
		"grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" +
		"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/3'\n" +
		"Model: enumValue=MyEnumRule;\n" +
		"enum MyEnumRule returns MyEnum: Value1 = 'value';";
	Grammar grammar = (Grammar) getModel(modelAsString);
	assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
	checkEnums(grammar);
	EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
	assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/3", pack.getNsURI());
	EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
	assertNotNull(eEnum);
	assertEquals(1, eEnum.getELiterals().size());
	EEnumLiteral value = eEnum.getELiterals().get(0);
	assertEquals("Value1", value.getName());
	assertEquals(0, value.getValue());
	assertEquals("value", value.getLiteral());
}
 
Example 9
Project: xtext-core   File: GrammarParserTest.java   Source Code and License 6 votes vote down vote up
@Test public void testEnum_07() throws Exception {
	String modelAsString =
		"grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" +
		"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/7'\n" +
		"Model: enumValue=MyEnum;\n" +
		"enum MyEnum: Value | Value;";
	Grammar grammar = (Grammar) getModel(modelAsString);
	assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
	checkEnums(grammar);
	EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
	assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/7", pack.getNsURI());
	EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
	assertNotNull(eEnum);
	assertEquals(1, eEnum.getELiterals().size());
	EEnumLiteral value = eEnum.getELiterals().get(0);
	assertEquals("Value", value.getName());
	assertEquals(0, value.getValue());
	assertEquals("Value", value.getLiteral());
}
 
Example 10
Project: xtext-core   File: GrammarParserTest.java   Source Code and License 6 votes vote down vote up
@Test public void testEnum_08() throws Exception {
	String modelAsString =
		"grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" +
		"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8'\n" +
		"Model: enumValue=MyEnum;\n" +
		"enum MyEnum: Value | Value = 'foo';";
	Grammar grammar = (Grammar) getModel(modelAsString);
	assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
	checkEnums(grammar);
	EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
	assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8", pack.getNsURI());
	EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
	assertNotNull(eEnum);
	assertEquals(1, eEnum.getELiterals().size());
	EEnumLiteral value = eEnum.getELiterals().get(0);
	assertEquals("Value", value.getName());
	assertEquals(0, value.getValue());
	assertEquals("Value", value.getLiteral());
}
 
Example 11
Project: bts   File: EnumTemplateVariableResolver.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> resolveValues(TemplateVariable variable,
		XtextTemplateContext castedContext) {
	String enumerationName = (String) variable.getVariableType()
			.getParams().iterator().next();
	Grammar grammar = getGrammar(castedContext);
	if (grammar == null)
		return Collections.emptyList();
	EEnum enumeration = (EEnum) getEClassifierForGrammar(enumerationName, grammar);
	if (enumeration == null) {
		return Collections.emptyList();
	}
	return Lists.transform(enumeration.getELiterals(), new Function<EEnumLiteral, String>() {
		public String apply(EEnumLiteral enumLiteral) {
			return enumLiteral.getLiteral();
		}
	});
}
 
Example 12
Project: OpenSPIFe   File: DynamicProfileDependency.java   Source Code and License 6 votes vote down vote up
private Object combine(Object previousValue, Object value) {
	if (previousValue instanceof Number && value instanceof Number) {
		return normalize(((Number)previousValue).doubleValue() + ((Number)value).doubleValue());
	} else if (previousValue instanceof Amount && value instanceof Amount) {
		return ((Amount)previousValue).plus(((Amount)value));
	} else if (previousValue instanceof String && value instanceof String) {
		return value;
	} else if (previousValue instanceof EEnumLiteral && value instanceof EEnumLiteral) {
		return value;
	} else if (previousValue instanceof Boolean && value instanceof Boolean) {
		return value;
	} else {
		LogUtil.errorOnce(profileKey+": unrecognized value pair '"+previousValue+"' & '"+value+"'");
	}
	return null;
}
 
Example 13
Project: OpenSPIFe   File: TestPlanIORoundTrip.java   Source Code and License 6 votes vote down vote up
protected EActivity createActivityRandomly(EActivityDef def) {
	EActivity activity = PlanFactory.getInstance().createActivity(def, null);
	for (EStructuralFeature feature : def.getEAllStructuralFeatures()) {
		if (!feature.isChangeable()) {
			continue;
		}
		Object value = activity.getData().eGet(feature);
		EClassifier type = feature.getEType();
		if (type instanceof EEnum) {
			EList<EEnumLiteral> literals = ((EEnum)type).getELiterals();
			int index = (int) (Math.random() * literals.size());
			value = literals.get(index);
			if (feature.isMany()) {
				value = Collections.singletonList(value);
			}
		} else if (EcorePackage.Literals.ESTRING == type) {
			value = "String "+Math.random();
		}
		activity.getData().eSet(feature, value);
	}
	return activity;
}
 
Example 14
Project: OpenSPIFe   File: PlanElementRowHeaderEditPart.java   Source Code and License 6 votes vote down vote up
@Override
public Image getImage(Object element) {
	if (element instanceof DynamicActivityGroup) {
		DynamicActivityGroup dag = (DynamicActivityGroup) element;
		Object value = dag.getValue();
		if (value instanceof EEnumLiteral) {
			return null;
		}
		IItemLabelProvider lp = EMFUtils.adapt(value, IItemLabelProvider.class);
		if (lp != null) {
			Object image = lp.getImage(value);
			return ExtendedImageRegistry.getInstance().getImage(image);
		}
		return null;
	}
	return delegate.getImage(element);
}
 
Example 15
Project: OpenSPIFe   File: GroupingTimelineContentProvider.java   Source Code and License 6 votes vote down vote up
protected String getValueString(Object value) {
	if (value instanceof EEnumLiteral) {
		return ((EEnumLiteral)value).getLiteral();
	} else if (value instanceof EObject) {
		IItemLabelProvider labeler = EMFUtils.adapt(value, IItemLabelProvider.class);
		if (labeler != null) {
			String text = labeler.getText(value);
			if (text != null) {
				return text;
			}
		}
	} else if (NULL_VALUE == value) {
		return "";
	}
	return value.toString();
}
 
Example 16
Project: OpenSPIFe   File: EAttributeTimelineContentProvider.java   Source Code and License 6 votes vote down vote up
@Override
protected Comparator getGroupingValuesComparator() {
	EClassifier eType = attributeDef.getEType();
	if (eType instanceof EEnum) {
		final EEnum eEnum = (EEnum) eType;
		return new Comparator<EEnumLiteral>() {
			@Override
			public int compare(EEnumLiteral o1, EEnumLiteral o2) {
				int v1 = eEnum.getELiterals().indexOf(o1);
				int v2 = eEnum.getELiterals().indexOf(o2);
				return v1 - v2;
			}
		};
	}
	return null;
}
 
Example 17
Project: OpenSPIFe   File: PlotRgbRegistry.java   Source Code and License 6 votes vote down vote up
public RGB getRgb(Plot plot, Object value) {
	RGB rgb = null;
	if (value instanceof EEnumLiteral) {
		rgb = getRgb(plot, (EEnumLiteral) value);
	} else if (value instanceof String) {
		rgb = getRgb(plot, (String) value);
	} else if (value instanceof Boolean) {
		rgb = getRgb(plot, (Boolean)value);
	} else if (value instanceof Amount) {
		rgb = getRgb(plot, (Amount)value);
	} else if (value instanceof Number) {
		rgb = getRgb(plot, (Number)value);
	} else if (value instanceof PowerValue) {
		return getRgb(plot, ((PowerValue)value).getStateValue());
	}
	return rgb == NULL ? null : rgb;
}
 
Example 18
Project: OpenSPIFe   File: DataPoint.java   Source Code and License 6 votes vote down vote up
public boolean isZero() {
	T value = getValue();
	if (value == null) {
		return true;
	}
	if (value instanceof Boolean) {
		Boolean b = (Boolean) value;
		return (b == Boolean.FALSE);
	}
	if (value instanceof EEnumLiteral) {
		return ((EEnumLiteral) value).getValue() == 0;
	}
	if (value instanceof Enum) {
		return ((Enum) value).ordinal() == 0;
	}
	Number number = (value instanceof Number ? (Number)value : null);
	if (value instanceof Amount) {
		Amount amount = (Amount) value;
		number = AmountUtils.getNumericValue(amount);
	}
	if (number != null) {
		return number.doubleValue() == 0;
	}
	return false;
}
 
Example 19
Project: OpenSPIFe   File: PowerValueImpl.java   Source Code and License 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case JSciencePackage.POWER_VALUE__STATE_NAME:
			setStateName((String)newValue);
			return;
		case JSciencePackage.POWER_VALUE__DUTY_FACTOR:
			setDutyFactor((Double)newValue);
			return;
		case JSciencePackage.POWER_VALUE__ACTUAL_WATTAGE:
			setActualWattage((Double)newValue);
			return;
		case JSciencePackage.POWER_VALUE__STATE_VALUE:
			setStateValue((EEnumLiteral)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example 20
Project: OpenSPIFe   File: PowerValueImpl.java   Source Code and License 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case JSciencePackage.POWER_VALUE__STATE_NAME:
			setStateName(STATE_NAME_EDEFAULT);
			return;
		case JSciencePackage.POWER_VALUE__DUTY_FACTOR:
			setDutyFactor(DUTY_FACTOR_EDEFAULT);
			return;
		case JSciencePackage.POWER_VALUE__ACTUAL_WATTAGE:
			setActualWattage(ACTUAL_WATTAGE_EDEFAULT);
			return;
		case JSciencePackage.POWER_VALUE__STATE_VALUE:
			setStateValue((EEnumLiteral)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example 21
Project: OpenSPIFe   File: ADParameterUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Get the value of the named AD parameter for the activity as a string.
 * Works with several types, not just strings -- enums, for example.
 * @param element
 * @param parameterName
 * @return null if the parameter is not found
 */
public static String getParameterString(EPlanElement element, String parameterName) {
	EObject data = element.getData();
    if (data==null) return null;
	EStructuralFeature feature;
       try {
        feature = getParameterFeature(data, parameterName);
       } catch (UndefinedParameterException e) {
        return null;
       }
	Object object = data.eGet(feature);
	if (object instanceof EEnumLiteral) {
		EEnumLiteral literal = (EEnumLiteral) object;
		return literal.getName();
	}
	EClassifier type = feature.getEType();
	if (type instanceof EDataType) {
		EDataType dataType = (EDataType) type;
		EPackage typePackage = dataType.getEPackage();
		EFactory factory = typePackage.getEFactoryInstance();
		String string = factory.convertToString(dataType, object);
		return string;
	}
	LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName);
	return String.valueOf(object);
}
 
Example 22
Project: OpenSPIFe   File: ADParameterUtils.java   Source Code and License 6 votes vote down vote up
public static String getObjectString(EObject object, String parameterName) {
	EStructuralFeature feature;
       try {
        feature = getParameterFeature(object, parameterName);
       } catch (UndefinedParameterException e) {
        return null;
       }
	Object value = object.eGet(feature);
	if (value instanceof EEnumLiteral) {
		EEnumLiteral literal = (EEnumLiteral) value;
		return literal.getName();
	}
	EClassifier type = feature.getEType();
	if (type instanceof EDataType) {
		EDataType dataType = (EDataType) type;
		EPackage typePackage = dataType.getEPackage();
		EFactory factory = typePackage.getEFactoryInstance();
		String string = factory.convertToString(dataType, value);
		return string;
	}
	LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName);
	return String.valueOf(value);
}
 
Example 23
Project: eclipse-avro   File: EPackageImpl.java   Source Code and License 6 votes vote down vote up
protected void fixEEnumLiterals(EEnum eEnum)
{
  Class<?> enumClass = eEnum.getInstanceClass();
  
  try
  {
    Method getter = enumClass.getMethod("get", new Class[] { Integer.TYPE });

    for (EEnumLiteral eEnumLiteral : eEnum.getELiterals())
    {
      Enumerator instance = (Enumerator)getter.invoke(null, new Object[] { eEnumLiteral.getValue() });
      eEnumLiteral.setInstance(instance);
      ((EEnumLiteralImpl)eEnumLiteral).setGeneratedInstance(true);
    }
  }
  catch (Exception e)
  {
    // Do nothing
  }
}
 
Example 24
Project: BIMserver   File: ByteBufferVirtualObject.java   Source Code and License 6 votes vote down vote up
private void writeEnum(EStructuralFeature feature, Object value) {
	if (value == null) {
		ensureCapacity(buffer.position(), 4);
		buffer.putInt(-1);
	} else {
		EEnum eEnum = (EEnum) feature.getEType();
		EEnumLiteral eEnumLiteral = eEnum.getEEnumLiteralByLiteral(((Enum<?>) value).toString());
		ensureCapacity(buffer.position(), 4);
		if (eEnumLiteral != null) {
			buffer.putInt(eEnumLiteral.getValue());
		} else {
			LOGGER.error(((Enum<?>) value).toString() + " not found");
			buffer.putInt(-1);
		}
	}
}
 
Example 25
Project: BIMserver   File: Schema.java   Source Code and License 6 votes vote down vote up
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 26
Project: BIMserver   File: Express2EMF.java   Source Code and License 6 votes vote down vote up
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 27
Project: BIMserver   File: PackageMetaData.java   Source Code and License 6 votes vote down vote up
public EEnumLiteral getEEnumLiteral(String enumName, String literalName) {
	EClassifier eClassifier = ePackage.getEClassifier(enumName);
	if (eClassifier == null) {
		throw new RuntimeException("Classifier " + enumName + " not found in package " + ePackage.getName());
	}
	if (eClassifier instanceof EEnum) {
		EEnum eEnum = (EEnum)eClassifier;
		EEnumLiteral literal = eEnum.getEEnumLiteral(literalName);
		if (literal == null) {
			throw new RuntimeException("No enum literal " + literalName + " found on " + ePackage.getName() + "." + enumName);
		}
		return literal;
	} else {
		throw new RuntimeException("Classifier " + enumName + " is not of type enum");
	}
}
 
Example 28
Project: clickwatch   File: EPackageImpl.java   Source Code and License 6 votes vote down vote up
protected void fixEEnumLiterals(EEnum eEnum)
{
  Class<?> enumClass = eEnum.getInstanceClass();
  
  try
  {
    Method getter = enumClass.getMethod("get", new Class[] { Integer.TYPE });

    for (EEnumLiteral eEnumLiteral : eEnum.getELiterals())
    {
      Enumerator instance = (Enumerator)getter.invoke(null, new Object[] { eEnumLiteral.getValue() });
      eEnumLiteral.setInstance(instance);
      ((EEnumLiteralImpl)eEnumLiteral).setGeneratedInstance(true);
    }
  }
  catch (Exception e)
  {
    // Do nothing
  }
}
 
Example 29
Project: JavaGraph   File: TypeToEcore.java   Source Code and License 5 votes vote down vote up
@Override
public void visit(Enum enum1, String param) {
    if (hasElement(enum1)) {
        return;
    }

    EEnum eEnum = g_EcoreFactory.createEEnum();
    setElement(enum1, eEnum);

    eEnum.setName(enum1.getId()
        .getName()
        .toString());

    EPackage enumPackage = packageFromId(enum1.getId()
        .getNamespace());
    enumPackage.getEClassifiers()
        .add(eEnum);

    List<EEnumLiteral> eLiterals = eEnum.getELiterals();
    for (Name litName : enum1.getLiterals()) {
        EEnumLiteral eEnumLit = g_EcoreFactory.createEEnumLiteral();
        eEnumLit.setName(litName.toString());
        //eEnumLit.setLiteral(litName.toString());

        eLiterals.add(eEnumLit);
    }
}
 
Example 30
Project: gemoc-studio   File: GEnumLiteralExpressionImpl.java   Source Code and License 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setValue(EEnumLiteral newValue) {
	EEnumLiteral oldValue = value;
	value = newValue;
	if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, GexpressionsPackage.GENUM_LITERAL_EXPRESSION__VALUE, oldValue, value));
}
 
Example 31
Project: gemoc-studio   File: GEnumLiteralExpressionImpl.java   Source Code and License 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case GexpressionsPackage.GENUM_LITERAL_EXPRESSION__VALUE:
			setValue((EEnumLiteral)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example 32
Project: gemoc-studio   File: GEnumLiteralExpressionImpl.java   Source Code and License 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case GexpressionsPackage.GENUM_LITERAL_EXPRESSION__VALUE:
			setValue((EEnumLiteral)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example 33
Project: DarwinSPL   File: DwprofileCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<de.darwinspl.preferences.resource.dwprofile.ui.DwprofileCompletionProposal> handleEnumAttribute(de.darwinspl.preferences.resource.dwprofile.mopp.DwprofileExpectedTerminal expectedTerminal, de.darwinspl.preferences.resource.dwprofile.mopp.DwprofileExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<de.darwinspl.preferences.resource.dwprofile.ui.DwprofileCompletionProposal> result = new LinkedHashSet<de.darwinspl.preferences.resource.dwprofile.ui.DwprofileCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		de.darwinspl.preferences.resource.dwprofile.IDwprofileTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		de.darwinspl.preferences.resource.dwprofile.IDwprofileTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new de.darwinspl.preferences.resource.dwprofile.ui.DwprofileCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 34
Project: DarwinSPL   File: HyexpressionCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionCompletionProposal> handleEnumAttribute(eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionExpectedTerminal expectedTerminal, eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionCompletionProposal> result = new LinkedHashSet<eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 35
Project: DarwinSPL   File: HyvalidityformulaCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaCompletionProposal> handleEnumAttribute(eu.hyvar.context.contextValidity.resource.hyvalidityformula.mopp.HyvalidityformulaExpectedTerminal expectedTerminal, eu.hyvar.context.contextValidity.resource.hyvalidityformula.mopp.HyvalidityformulaExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaCompletionProposal> result = new LinkedHashSet<eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 36
Project: DarwinSPL   File: HydatavalueCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueCompletionProposal> handleEnumAttribute(eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavalueExpectedTerminal expectedTerminal, eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavalueExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueCompletionProposal> result = new LinkedHashSet<eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 37
Project: DarwinSPL   File: HymappingCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingCompletionProposal> handleEnumAttribute(eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingExpectedTerminal expectedTerminal, eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingCompletionProposal> result = new LinkedHashSet<eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		eu.hyvar.feature.mapping.resource.hymapping.IHymappingTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		eu.hyvar.feature.mapping.resource.hymapping.IHymappingTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 38
Project: DarwinSPL   File: HyconstraintsCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsCompletionProposal> handleEnumAttribute(eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsExpectedTerminal expectedTerminal, eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsCompletionProposal> result = new LinkedHashSet<eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 39
Project: DarwinSPL   File: HymanifestCodeCompletionHelper.java   Source Code and License 5 votes vote down vote up
protected Collection<eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestCompletionProposal> handleEnumAttribute(eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestExpectedTerminal expectedTerminal, eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestExpectedStructuralFeature expectedFeature, EEnum enumType, String prefix, EObject container) {
	Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
	Collection<eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestCompletionProposal> result = new LinkedHashSet<eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestCompletionProposal>();
	for (EEnumLiteral literal : enumLiterals) {
		String unResolvedLiteral = literal.getLiteral();
		// use token resolver to get de-resolved value of the literal
		eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestTokenResolverFactory tokenResolverFactory = metaInformation.getTokenResolverFactory();
		eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestTokenResolver tokenResolver = tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
		String resolvedLiteral = tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
		boolean matchesPrefix = matches(resolvedLiteral, prefix);
		result.add(new eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestCompletionProposal(expectedTerminal, resolvedLiteral, prefix, matchesPrefix, expectedFeature.getFeature(), container));
	}
	return result;
}
 
Example 40
Project: dynemf   File: EObjectWrapper.java   Source Code and License 5 votes vote down vote up
/**
 * Gets the value of an attribute/reference wrapped in a
 * {@link ValueWrapper}.
 * 
 * @param name the name of the attribute/reference to navigate
 * @return a new instance of ValueWrapper wrapping the result
 */
@SuppressWarnings("unchecked")
public ValueWrapper<?> property(String name) {
	if (obj == null) {
		throw new RuntimeException("Object has not been loaded (no model given)");
	}
	EFeatureWrapper efeature = eFeature(name);
	EStructuralFeature feature = efeature.result();
	Object o = obj.eGet(feature);

	if (o == null) {
		return NullValueWrapper.NULL;
	}

	if (o instanceof EObject) {
		return obj((EObject) o);
	} else if (o instanceof List<?>) {
		List<EObjectWrapper<?>> values = new LinkedList<>();
		for (EObject e : (List<EObject>) o) {
			values.add(obj(e));
		}
		return new ListWrapper((EList<EObject>) o, values);
	} else if (o instanceof EEnumLiteral) {
		return new EEnumLiteralWrapper((EEnumLiteral) o);
	} else {
		return new ValueWrapper<Object>(o);
	}
}