Java Examples for org.eclipse.emf.ecore.EEnum
The following java examples will help you to understand the usage of org.eclipse.emf.ecore.EEnum. These source code samples are taken from different open source projects.
Example 1
| Project: Reuseware-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 2
| Project: ttc2011-master File: SslCodeCompletionHelper.java View source code |
private java.util.Collection<ssl.resource.ssl.ui.SslCompletionProposal> deriveProposals(ssl.resource.ssl.mopp.SslExpectedTerminal expectedTerminal, String content, ssl.resource.ssl.ISslTextResource resource, int cursorOffset) {
ssl.resource.ssl.ISslMetaInformation metaInformation = resource.getMetaInformation();
ssl.resource.ssl.ISslLocationMap locationMap = resource.getLocationMap();
ssl.resource.ssl.ISslExpectedElement expectedElement = (ssl.resource.ssl.ISslExpectedElement) expectedTerminal.getTerminal();
if (expectedElement instanceof ssl.resource.ssl.mopp.SslExpectedCsString) {
ssl.resource.ssl.mopp.SslExpectedCsString csString = (ssl.resource.ssl.mopp.SslExpectedCsString) expectedElement;
return handleKeyword(csString, expectedTerminal.getPrefix());
} else if (expectedElement instanceof ssl.resource.ssl.mopp.SslExpectedBooleanTerminal) {
ssl.resource.ssl.mopp.SslExpectedBooleanTerminal expectedBooleanTerminal = (ssl.resource.ssl.mopp.SslExpectedBooleanTerminal) expectedElement;
return handleBooleanTerminal(expectedBooleanTerminal, expectedTerminal.getPrefix());
} else if (expectedElement instanceof ssl.resource.ssl.mopp.SslExpectedStructuralFeature) {
ssl.resource.ssl.mopp.SslExpectedStructuralFeature expectedFeature = (ssl.resource.ssl.mopp.SslExpectedStructuralFeature) expectedElement;
org.eclipse.emf.ecore.EStructuralFeature feature = expectedFeature.getFeature();
org.eclipse.emf.ecore.EClassifier featureType = feature.getEType();
java.util.List<org.eclipse.emf.ecore.EObject> elementsAtCursor = locationMap.getElementsAt(cursorOffset);
org.eclipse.emf.ecore.EObject container = null;
// container for the reference we try to complete
for (int i = 0; i < elementsAtCursor.size(); i++) {
container = elementsAtCursor.get(i);
if (!container.eIsProxy()) {
break;
}
}
// document. we need to create artificial containers.
if (container == null) {
boolean attachedArtificialContainer = false;
org.eclipse.emf.ecore.EClass containerClass = expectedTerminal.getTerminal().getRuleMetaclass();
org.eclipse.emf.ecore.EStructuralFeature[] containmentTrace = expectedTerminal.getContainmentTrace();
java.util.List<org.eclipse.emf.ecore.EObject> contentList = null;
for (org.eclipse.emf.ecore.EStructuralFeature eStructuralFeature : containmentTrace) {
if (attachedArtificialContainer) {
break;
}
org.eclipse.emf.ecore.EClass neededClass = eStructuralFeature.getEContainingClass();
// fill the content list during the first iteration of the loop
if (contentList == null) {
contentList = new java.util.ArrayList<org.eclipse.emf.ecore.EObject>();
java.util.Iterator<org.eclipse.emf.ecore.EObject> allContents = resource.getAllContents();
while (allContents.hasNext()) {
org.eclipse.emf.ecore.EObject next = allContents.next();
contentList.add(next);
}
}
// find object to attach artificial container to
for (int i = contentList.size() - 1; i >= 0; i--) {
org.eclipse.emf.ecore.EObject object = contentList.get(i);
if (neededClass.isInstance(object)) {
org.eclipse.emf.ecore.EObject newContainer = containerClass.getEPackage().getEFactoryInstance().create(containerClass);
if (eStructuralFeature.getEType().isInstance(newContainer)) {
ssl.resource.ssl.util.SslEObjectUtil.setFeature(object, eStructuralFeature, newContainer, false);
container = newContainer;
attachedArtificialContainer = true;
}
}
}
}
}
if (feature instanceof org.eclipse.emf.ecore.EReference) {
org.eclipse.emf.ecore.EReference reference = (org.eclipse.emf.ecore.EReference) feature;
if (featureType instanceof org.eclipse.emf.ecore.EClass) {
if (reference.isContainment()) {
// the FOLLOW set should contain only non-containment references
assert false;
} else {
return handleNCReference(metaInformation, container, reference, expectedTerminal.getPrefix(), expectedFeature.getTokenName());
}
}
} else if (feature instanceof org.eclipse.emf.ecore.EAttribute) {
org.eclipse.emf.ecore.EAttribute attribute = (org.eclipse.emf.ecore.EAttribute) feature;
if (featureType instanceof org.eclipse.emf.ecore.EEnum) {
org.eclipse.emf.ecore.EEnum enumType = (org.eclipse.emf.ecore.EEnum) featureType;
return handleEnumAttribute(metaInformation, expectedFeature, enumType, expectedTerminal.getPrefix(), container);
} else {
// attribute, figure out token resolver, and call deResolve())
return handleAttribute(metaInformation, expectedFeature, container, attribute, expectedTerminal.getPrefix());
}
} else {
// there should be no other subclass of EStructuralFeature
assert false;
}
} else {
// there should be no other class implementing IExpectedElement
assert false;
}
return java.util.Collections.emptyList();
}Example 3
| Project: gmf-tooling-master File: ExpressionMigrationFacade.java View source code |
private EClassifier migrateFeatureCall(FeatureCall featureCall) throws MigrationException {
ExpressionAnalyzeTrace expressionTrace = ctx.getTraces().get(featureCall);
if (false == expressionTrace instanceof FeatureCallTrace) {
throw new MigrationException(Type.UNSUPPORTED_FEATURE_CALL_TRACE, resourceName, featureCall, expressionTrace);
}
FeatureCallTrace trace = (FeatureCallTrace) expressionTrace;
switch(trace.getType()) {
case ENUM_LITERAL_REF:
EEnumLiteral enumLiteral = trace.getEnumLiteral();
assert enumLiteral != null;
write(typeManager.getQvtFQName(enumLiteral));
return enumLiteral.getEEnum();
case ENV_VAR_REF:
write(modelManager.getName(featureCall, trace));
EClassifier variableType = getEnvVariableType(featureCall.getName().getValue());
return variableType != null ? variableType : trace.getResultType();
case UNDESOLVED_TARGET_TYPE:
case UNSUPPORTED_CLASSIFIER_REF:
throw new MigrationException(Type.UNSUPPORTED_FEATURE_CALL, resourceName, featureCall.getName(), trace);
}
EClassifier targetType = trace.getTargetType();
if (featureCall.getTarget() != null) {
migrateExpression(featureCall.getTarget());
if (targetType instanceof EEnum && trace.getType() == FeatureCallTrace.Type.FEATURE_REF) {
if (skipEnumLiteralFeature(trace.getFeature())) {
return targetType;
} else if (addEnumLiteralStringRepresentation(trace.getFeature())) {
write(".repr()");
return EcorePackage.eINSTANCE.getEString();
}
}
write(".");
} else {
if (targetType instanceof EEnum && trace.getType() == FeatureCallTrace.Type.FEATURE_REF) {
if (skipEnumLiteralFeature(trace.getFeature())) {
write(Environment.SELF_VARIABLE_NAME);
return targetType;
} else if (addEnumLiteralStringRepresentation(trace.getFeature())) {
write(Environment.SELF_VARIABLE_NAME);
write(".repr()");
return EcorePackage.eINSTANCE.getEString();
}
}
if (FeatureCallTrace.Type.IMPLICIT_COLLECT_FEATURE_REF == trace.getType()) {
write(Environment.SELF_VARIABLE_NAME);
write(".");
}
}
write(modelManager.getName(featureCall, trace));
assert targetType != null;
switch(trace.getType()) {
case FEATURE_REF:
if (BuiltinMetaModel.isParameterizedType(targetType)) {
throw new MigrationException(Type.UNSUPPORTED_EXPRESSION, resourceName, featureCall, "Attribute call is not supported for the collection types: " + targetType.toString() + "." + featureCall.getName().getValue());
}
return getTypedElementQvtType(trace.getFeature());
case IMPLICIT_COLLECT_FEATURE_REF:
if (!BuiltinMetaModel.isParameterizedType(targetType)) {
throw new MigrationException(Type.UNSUPPORTED_EXPRESSION, resourceName, featureCall, "Implicit collect is not supported for simple types: " + targetType.toString() + "." + featureCall.getName().getValue());
}
convertImplicitCollectProduct(targetType);
return trace.getResultType();
default:
throw new MigrationException(Type.UNSUPPORTED_FEATURE_CALL_TRACE, resourceName, featureCall, trace);
}
}Example 4
| Project: ares-studio-master File: EnumEditingSupport.java View source code |
/* (non-Javadoc)
* @see com.hundsun.ares.studio.jres.ui.editingsupports.BaseEditingSupport#doGetCellEditor(java.lang.Object)
*/
@Override
protected CellEditor doGetCellEditor(Object element) {
EEnumComboBoxCellEditor cellEditor = (EEnumComboBoxCellEditor) super.doGetCellEditor(element);
EStructuralFeature feature = getFeature(element);
if (feature.getEType() instanceof EEnum) {
EEnum eEnum = (EEnum) feature.getEType();
cellEditor.setEEnum(eEnum, itemLableProvider);
} else {
cellEditor = null;
}
return cellEditor;
}Example 5
| Project: collaboro-master File: Controller.java View source code |
public List<ModelChange> applyChanges() {
List<ModelChange> appliedChanges = new ArrayList<ModelChange>();
if (getHistory() == null)
return appliedChanges;
for (Proposal proposal : getHistory().getHistories().get(getHistoryTracked()).getVersions().get(getVersionTracked()).getProposals()) {
if (proposal.isAccepted()) {
Solution solution = proposal.getSelected();
if (solution != null) {
for (ModelChange change : solution.getChanges()) {
if (change instanceof Add) {
Add add = (Add) change;
SyntaxElement referred = add.getReferredElement();
SyntaxElement target = add.getTarget();
if (referred instanceof ExistingAbstractSyntaxElement) {
ExistingAbstractSyntaxElement refExistingElement = (ExistingAbstractSyntaxElement) referred;
EObject refEObject = refExistingElement.getElement();
if (target instanceof NewAbstractSyntaxElement) {
NewAbstractSyntaxElement tgtNewElement = (NewAbstractSyntaxElement) target;
EObject tgtEObject = tgtNewElement.getElement();
if (tgtEObject instanceof EAttribute) {
EAttribute newAttribute = (EAttribute) tgtEObject;
if (refEObject instanceof EClass) {
EClass eClass = (EClass) refEObject;
eClass.getEStructuralFeatures().add(newAttribute);
appliedChanges.add(change);
}
}
if (tgtEObject instanceof EClass) {
EClass eClass = (EClass) tgtEObject;
if (refEObject instanceof EPackage) {
EPackage ePackage = (EPackage) refEObject;
ePackage.getEClassifiers().add(eClass);
appliedChanges.add(change);
}
}
if (tgtEObject instanceof EEnum) {
EEnum eEnum = (EEnum) tgtEObject;
if (refEObject instanceof EPackage) {
EPackage ePackage = (EPackage) refEObject;
ePackage.getEClassifiers().add(eEnum);
appliedChanges.add(change);
}
}
}
}
} else if (change instanceof Delete) {
Delete delete = (Delete) change;
SyntaxElement referred = delete.getReferredElement();
SyntaxElement target = delete.getTarget();
if (referred instanceof ExistingAbstractSyntaxElement) {
ExistingAbstractSyntaxElement refExistingElement = (ExistingAbstractSyntaxElement) referred;
EObject refEObject = refExistingElement.getElement();
if (target instanceof ExistingAbstractSyntaxElement) {
ExistingAbstractSyntaxElement toDelete = (ExistingAbstractSyntaxElement) target;
EObject tgtEObject = toDelete.getElement();
if (tgtEObject instanceof EAttribute) {
EAttribute eAttribute = (EAttribute) tgtEObject;
if (refEObject instanceof EClass) {
EClass eClass = (EClass) refEObject;
eClass.getEStructuralFeatures().remove(eAttribute);
appliedChanges.add(change);
}
}
if (tgtEObject instanceof EClass) {
EClass eClass = (EClass) tgtEObject;
if (refEObject instanceof EPackage) {
EPackage ePackage = (EPackage) refEObject;
ePackage.getEClassifiers().remove(eClass);
appliedChanges.add(change);
}
}
if (tgtEObject instanceof EEnum) {
EEnum eEnum = (EEnum) tgtEObject;
if (refEObject instanceof EPackage) {
EPackage ePackage = (EPackage) refEObject;
ePackage.getEClassifiers().remove(eEnum);
appliedChanges.add(change);
}
}
}
}
}
}
}
}
}
modelManager.saveEcoreModel();
return appliedChanges;
}Example 6
| Project: emf.texo-master File: GenUtils.java View source code |
/**
* Based on the literal a default value is returned. If the literal is null then a zero length string is returned.
*
* @param literal
* the literal defining the default value to create
* @return a valid (from a type perspective) java default value
*/
public static String getStaticDefaultValue(AnnotationManager annotationManager, EDataType eDataType, final String literal) {
if (eDataType instanceof EEnum) {
return getStaticDefaultValue(annotationManager, (EEnum) eDataType, literal);
}
if (isObjectTypeWithEnumBaseType(eDataType)) {
final EEnum enumDataType = ModelUtils.getEnumBaseDataTypeIfObject(eDataType);
return getStaticDefaultValue(annotationManager, enumDataType, literal);
}
// first check if there the type extends a base Ecore/XML type (is often
// the case)
final EDataType baseType = getEcoreXMLDataType(eDataType);
if (baseType != null && !useFactoryFor(baseType)) {
// get an object variant of the default value
final Object value;
if (literal == null) {
value = baseType.getDefaultValue();
} else {
try {
value = EcoreUtil.createFromString(baseType, literal);
} catch (final Exception e) {
return "Exception: " + e.getMessage() + " literal:" + literal;
}
}
if (value == null) {
//$NON-NLS-1$
return "null";
}
// object
if (baseType.getInstanceClass() == null) {
return Literals.toLiteral(value.getClass(), value);
}
return Literals.toLiteral(baseType.getInstanceClass(), value);
}
// always an object type at this point
if (literal == null) {
return GenConstants.NULL;
}
// the current data type is an ecore type
if (baseType == eDataType) {
return createEcoreFactoryCall(baseType, literal);
}
// finally use the modelfactory createFromString
return createModelFactoryCall(annotationManager, eDataType, literal);
}Example 7
| Project: modellipse-master File: SemanticPostAction.java View source code |
@Override
protected CellEditor getCellEditor(Object element) {
EStructuralFeature feature = (EStructuralFeature) element;
EClassifier eType = feature.getEType();
if (eType instanceof EEnum) {
return createEnumerationEditor(feature);
}
String instanceTypeName = eType.getInstanceClassName();
if (instanceTypeName.equals(String.class.getCanonicalName())) {
return new TextCellEditor(((TableViewer) getViewer()).getTable());
} else if (instanceTypeName.equals(Integer.class.getCanonicalName())) {
return new TextCellEditor(((TableViewer) getViewer()).getTable());
} else if (instanceTypeName.equals("boolean")) {
return createBooleanEditor(feature);
}
return new TextCellEditor(((TableViewer) getViewer()).getTable());
}Example 8
| Project: ocl-master File: DelegatesTest.java View source code |
protected void initModel(@NonNull ResourceSet resourceSet, @NonNull String testModelName) {
URI uri = getTestModelURI(testModelName);
testResource = resourceSet.getResource(uri, true);
acme = testResource.getContents().get(0);
companyClass = acme.eClass();
companyPackage = companyClass.getEPackage();
companyFactory = companyPackage.getEFactoryInstance();
companyName = (EAttribute) companyClass.getEStructuralFeature("name");
companyEmployees = (EReference) companyClass.getEStructuralFeature("employees");
companySize = (EAttribute) companyClass.getEStructuralFeature("size");
employeeClass = companyEmployees.getEReferenceType();
employeeName = (EAttribute) employeeClass.getEStructuralFeature("name");
employeeManager = (EReference) employeeClass.getEStructuralFeature("manager");
employeeDirectReports = (EReference) employeeClass.getEStructuralFeature("directReports");
employeeAllReports = (EReference) employeeClass.getEStructuralFeature("allReports");
employeeReportsTo = getOperation(employeeClass, "reportsTo");
sizeKind = (EEnum) companySize.getEAttributeType();
sizeSmall = sizeKind.getEEnumLiteral("small").getInstance();
sizeMedium = sizeKind.getEEnumLiteral("medium").getInstance();
sizeLarge = sizeKind.getEEnumLiteral("large").getInstance();
employees = new java.util.HashMap<String, EObject>();
// MetamodelManagerResourceAdapter.getAdapter(companyPackage.eResource(), metamodelManager);
}Example 9
| Project: tefkat-master File: Evaluator.java View source code |
private List evalEnumExpr(Context context, Binding binding, Expression expr) throws ResolutionException, NotGroundException {
List values = new ArrayList();
List args = ((EnumConstant) expr).getArg();
Expression enumExpr = (Expression) args.get(0);
Expression literalExpr = (Expression) args.get(1);
List enumObjs = eval(context, binding, enumExpr);
List literalObjs = eval(context, binding, literalExpr);
for (final Iterator eItr = enumObjs.iterator(); eItr.hasNext(); ) {
Object eObj = eItr.next();
EEnum enumeration = null;
if (eObj instanceof String) {
eObj = ModelUtils.findClassifierByName(ruleEval.nameMap, (String) eObj);
}
if (eObj instanceof EEnum) {
enumeration = (EEnum) eObj;
}
if (null != enumeration) {
for (final Iterator lItr = literalObjs.iterator(); lItr.hasNext(); ) {
Object lObj = lItr.next();
if (lObj instanceof String) {
EEnumLiteral eLit = enumeration.getEEnumLiteral((String) lObj);
if (null != eLit) {
values.add(eLit.getInstance());
}
}
}
}
}
return values;
}Example 10
| Project: emf-master File: EcoreValidationTest.java View source code |
@Test
public void testEcoreValidator() {
// Validate that the Ecore package instance itself is okay.
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(EcorePackage.eINSTANCE);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// An annotation with an empty string for the source isn't valid.
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAnnotation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_SOURCE_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAnnotation, EcorePackage.Literals.EANNOTATION__SOURCE }, diagnostic.getChildren().get(0));
}
// An annotation with a source containing a space isn't valid.
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("a b");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAnnotation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_SOURCE_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAnnotation, EcorePackage.Literals.EANNOTATION__SOURCE }, diagnostic.getChildren().get(0));
}
// Two map entries with the same key are not valid.
//
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
{
EObject entry = EcoreFactory.eINSTANCE.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY);
entry.eSet(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY__KEY, "a");
@SuppressWarnings("unchecked") Map.Entry<String, String> stringToStringMapEntry = (Map.Entry<String, String>) entry;
eAnnotation.getDetails().add(stringToStringMapEntry);
}
{
EObject entry = EcoreFactory.eINSTANCE.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY);
entry.eSet(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY__KEY, "a");
@SuppressWarnings("unchecked") Map.Entry<String, String> stringToStringMapEntry = (Map.Entry<String, String>) entry;
eAnnotation.getDetails().add(stringToStringMapEntry);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAnnotation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MAP_ENTRY_UNIQUE, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eAnnotation, EcorePackage.Literals.EANNOTATION__DETAILS, eAnnotation.getDetails().get(1), eAnnotation.getDetails().get(0) }, diagnostic.getChildren().get(0));
}
// A named element without a name is invalid, unless strict element names are disabled.
//
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ENAMED_ELEMENT__NAME }, diagnostic.getChildren().get(0));
diagnostic = Diagnostician.INSTANCE.validate(eClass, Collections.singletonMap(EcoreValidator.STRICT_NAMED_ELEMENT_NAMES, Boolean.FALSE));
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// An instance type name with type arguments is valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("_<_>");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// An instance type name that's just an empty string is not valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_INSTANCE_TYPE_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASSIFIER__INSTANCE_TYPE_NAME }, diagnostic.getChildren().get(0));
}
// An instance type name with unbalanced "<" is not valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("_<_");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_INSTANCE_TYPE_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASSIFIER__INSTANCE_TYPE_NAME }, diagnostic.getChildren().get(0));
}
// An instance type name with unbalanced "[" is not valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("_[");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_INSTANCE_TYPE_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASSIFIER__INSTANCE_TYPE_NAME }, diagnostic.getChildren().get(0));
}
// A class that is an interface must also be abstract.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInterface(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.INTERFACE_IS_ABSTRACT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASS__ABSTRACT }, diagnostic.getChildren().get(0));
}
// A class can't have more than one attribute that is an ID.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setID(true);
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("b");
eAttribute.setID(true);
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("c");
eAttribute.setID(true);
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.AT_MOST_ONE_ID, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEAttributes().get(0), eClass.getEAttributes().get(1), eClass.getEAllAttributes().get(2), EcorePackage.Literals.ECLASS__EALL_ATTRIBUTES }, diagnostic.getChildren().get(0));
}
// A class can't have two attributes with the same name.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_FEATURE_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEAttributes().get(0), eClass.getEAttributes().get(1), EcorePackage.Literals.ECLASS__EALL_STRUCTURAL_FEATURES }, diagnostic.getChildren().get(0));
}
// A class can't have two attributes with the matching names.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("A_");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.WARNING, EcoreValidator.UNIQUE_FEATURE_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEAttributes().get(0), eClass.getEAttributes().get(1), EcorePackage.Literals.ECLASS__EALL_STRUCTURAL_FEATURES }, diagnostic.getChildren().get(0));
}
// A class can't have two operations with matching signatures.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("a");
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("x");
eParameter.setEType(XMLTypePackage.Literals.HEX_BINARY);
eOperation.getEParameters().add(eParameter);
}
eClass.getEOperations().add(eOperation);
}
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("a");
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("x");
eParameter.setEType(XMLTypePackage.Literals.BASE64_BINARY);
eOperation.getEParameters().add(eParameter);
}
eClass.getEOperations().add(eOperation);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_OPERATION_SIGNATURES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEOperations().get(0), eClass.getEOperations().get(1), EcorePackage.Literals.ECLASS__EALL_OPERATIONS }, diagnostic.getChildren().get(0));
}
// A class can't have circular super types.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.getESuperTypes().add(eClass);
eClass.setName("_");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.NO_CIRCULAR_SUPER_TYPES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASS__EALL_SUPER_TYPES }, diagnostic.getChildren().get(0));
}
// A map entry class must have a key feature and a value feature.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceClassName("java.util.Map$Entry");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_MAP_ENTRY_CLASS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASS__EALL_STRUCTURAL_FEATURES }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_MAP_ENTRY_CLASS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, EcorePackage.Literals.ECLASS__EALL_STRUCTURAL_FEATURES }, diagnostic.getChildren().get(1));
}
// Two enum literals can't have the same name nor matching names.
{
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
eEnum.setName("_");
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("a");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("a");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("A");
eEnum.getELiterals().add(eEnumLiteral);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eEnum);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_ENUMERATOR_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eEnum, eEnum.getELiterals().get(0), eEnum.getELiterals().get(1), eEnum.getELiterals().get(2), EcorePackage.Literals.EENUM__ELITERALS }, diagnostic.getChildren().get(0));
}
// Two enum literals can't have the same literals.
{
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
eEnum.setName("_");
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("a");
eEnumLiteral.setLiteral("x");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("b");
eEnumLiteral.setLiteral("x");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("c");
eEnumLiteral.setLiteral("x");
eEnum.getELiterals().add(eEnumLiteral);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eEnum);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_ENUMERATOR_LITERALS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eEnum, eEnum.getELiterals().get(0), eEnum.getELiterals().get(1), eEnum.getELiterals().get(2), EcorePackage.Literals.EENUM__ELITERALS }, diagnostic.getChildren().get(0));
}
// Two parameters cannot have the same name.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("a");
eParameter.setEType(EcorePackage.Literals.ESTRING);
eOperation.getEParameters().add(eParameter);
}
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("a");
eParameter.setEType(EcorePackage.Literals.ESTRING);
eOperation.getEParameters().add(eParameter);
}
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("a");
eParameter.setEType(EcorePackage.Literals.ESTRING);
eOperation.getEParameters().add(eParameter);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_PARAMETER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eOperation, eOperation.getEParameters().get(0), eOperation.getEParameters().get(1), eOperation.getEParameters().get(2), EcorePackage.Literals.EOPERATION__EPARAMETERS }, diagnostic.getChildren().get(0));
}
// Two type parameters cannot have the same name.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eOperation.getETypeParameters().add(eTypeParameter);
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eOperation.getETypeParameters().add(eTypeParameter);
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eOperation.getETypeParameters().add(eTypeParameter);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_TYPE_PARAMETER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eOperation, eOperation.getETypeParameters().get(0), eOperation.getETypeParameters().get(1), eOperation.getETypeParameters().get(2), EcorePackage.Literals.EOPERATION__ETYPE_PARAMETERS }, diagnostic.getChildren().get(0));
}
// Two type parameters cannot have the same name.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eClass.getETypeParameters().add(eTypeParameter);
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eClass.getETypeParameters().add(eTypeParameter);
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eClass.getETypeParameters().add(eTypeParameter);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_TYPE_PARAMETER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getETypeParameters().get(0), eClass.getETypeParameters().get(1), eClass.getETypeParameters().get(2), EcorePackage.Literals.ECLASSIFIER__ETYPE_PARAMETERS }, diagnostic.getChildren().get(0));
}
// A void operation must have upper bound 1.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
eOperation.setUpperBound(2);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.NO_REPEATING_VOID, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eOperation, EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND }, diagnostic.getChildren().get(0));
}
// A package must have an nsURI.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsPrefix("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, EcorePackage.Literals.EPACKAGE__NS_URI }, diagnostic.getChildren().get(0));
}
// A null string is not a well formed nsURI for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("");
ePackage.setNsPrefix("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, EcorePackage.Literals.EPACKAGE__NS_URI }, diagnostic.getChildren().get(0));
}
// A string with a space is not a well formed nsURI for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("a b");
ePackage.setNsPrefix("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, EcorePackage.Literals.EPACKAGE__NS_URI }, diagnostic.getChildren().get(0));
}
// A prefix that starts with "xml" is not a well formed nsPrefix for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("xml");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_PREFIX, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, EcorePackage.Literals.EPACKAGE__NS_PREFIX }, diagnostic.getChildren().get(0));
}
// A prefix that isn't an NCName because it contains a ":" is not a well formed nsPrefix for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("a:b");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_PREFIX, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, EcorePackage.Literals.EPACKAGE__NS_PREFIX }, diagnostic.getChildren().get(0));
}
// A null prefix that an NCName and is not a well formed nsPrefix for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_PREFIX, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, EcorePackage.Literals.EPACKAGE__NS_PREFIX }, diagnostic.getChildren().get(0));
}
// Two subpackages cannot have the same name.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("a");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("b");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("c");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_SUBPACKAGE_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getESubpackages().get(0), ePackage.getESubpackages().get(1), ePackage.getESubpackages().get(2), EcorePackage.Literals.EPACKAGE__ESUBPACKAGES }, diagnostic.getChildren().get(0));
}
// Two classifiers cannot have the same name nor matching names.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("a");
ePackage.getEClassifiers().add(eClass);
}
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("a");
ePackage.getEClassifiers().add(eClass);
}
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
ePackage.getEClassifiers().add(eClass);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_CLASSIFIER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getEClassifiers().get(0), ePackage.getEClassifiers().get(1), ePackage.getEClassifiers().get(2), EcorePackage.Literals.EPACKAGE__ECLASSIFIERS }, diagnostic.getChildren().get(0));
}
// Two packages cannot have the same namespace URI.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("_");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_NS_URIS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getESubpackages().get(0), EcorePackage.Literals.EPACKAGE__ESUBPACKAGES }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_NS_URIS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage.getESubpackages().get(0), ePackage, EcorePackage.Literals.EPACKAGE__ESUBPACKAGES }, diagnostic.getChildren().get(1));
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("_");
eAttribute.setEType(EcorePackage.Literals.ERESOURCE);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TRANSIENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.ESTRUCTURAL_FEATURE__TRANSIENT }, diagnostic.getChildren().get(0));
}
// There are many ways for opposites to be inconsistent so we'll test them all.
LOOP: for (int i = 0; i < 100; ++i) {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
EClass A;
EReference a;
EClass B;
EReference b;
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
ePackage.getEClassifiers().add(eClass);
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("b");
eClass.getEStructuralFeatures().add(eReference);
b = eReference;
}
A = eClass;
}
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
ePackage.getEClassifiers().add(eClass);
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("a");
eClass.getEStructuralFeatures().add(eReference);
a = eReference;
}
B = eClass;
}
switch(i) {
// Valid unidirectional references.
case 0:
{
a.setEType(A);
b.setEType(B);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// Valid bidirectional references.
case 1:
{
a.setEType(A);
a.setEOpposite(b);
b.setEType(B);
b.setEOpposite(a);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// The opposite must be a feature of the reference's type.
case 2:
{
// <-- Bad type that doesn't have a b feature
a.setEType(B);
a.setEOpposite(b);
b.setEType(B);
b.setEOpposite(a);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_NOT_FROM_TYPE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b, B, EcorePackage.Literals.EREFERENCE__EOPPOSITE }, diagnostic.getChildren().get(0));
break;
}
// The opposite of the opposite must be the feature itself.
case 3:
{
a.setEType(A);
a.setEOpposite(b);
b.setEType(B);
// b.setEOpposite(a); <-- No opposite for the opposite
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_NOT_MATCHING, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b, null, EcorePackage.Literals.EREFERENCE__EOPPOSITE }, diagnostic.getChildren().get(0));
break;
}
// Valid bidirectional container/containment references.
case 4:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// A container reference must have upper bound 1.
case 5:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
// <-- Bad upper bound.
b.setUpperBound(2);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.SINGLE_CONTAINER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { b, EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND }, diagnostic.getChildren().get(0));
break;
}
// Valid bidirectional references that are transient at both ends.
case 6:
{
a.setEType(A);
a.setEOpposite(b);
a.setTransient(true);
b.setEType(B);
b.setEOpposite(a);
b.setTransient(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// Valid bidirectional references with one transient end that doesn't resolve proxy.
case 7:
{
a.setEType(A);
a.setEOpposite(b);
a.setTransient(true);
b.setEType(B);
b.setEOpposite(a);
b.setResolveProxies(false);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// Valid bidirectional references with on transient end that's a container.
case 8:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
b.setTransient(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// The opposite of a transient bidirectional reference must either be transient as, non-proxy resolving, or a container.
case 9:
{
a.setEType(A);
a.setEOpposite(b);
a.setTransient(true);
// a.setContainment(true); <-- Must be a containment for b to be a container and hence be valid.
b.setEType(B);
b.setEOpposite(a);
// b.setTransient(true); <-- Must be transient.
// b.setResolveProxies(false); <-- Or must not resolve proxies.
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_BAD_TRANSIENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b, EcorePackage.Literals.EREFERENCE__EOPPOSITE, EcorePackage.Literals.ESTRUCTURAL_FEATURE__TRANSIENT }, diagnostic.getChildren().get(0));
break;
}
// Both sides can't be containment.
case 10:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
b.setContainment(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_BOTH_CONTAINMENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { b, a, EcorePackage.Literals.EREFERENCE__EOPPOSITE, EcorePackage.Literals.EREFERENCE__CONTAINMENT }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_BOTH_CONTAINMENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b, EcorePackage.Literals.EREFERENCE__EOPPOSITE, EcorePackage.Literals.EREFERENCE__CONTAINMENT }, diagnostic.getChildren().get(1));
break;
}
default:
{
break LOOP;
}
}
}
// The lower bound of a typed element must be >= 0.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setLowerBound(-1);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.VALID_LOWER_BOUND, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.ETYPED_ELEMENT__LOWER_BOUND }, diagnostic.getChildren().get(0));
}
// The upper bound of a typed elements must be -2, -1, or >= 1 not 3.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setUpperBound(-3);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.VALID_UPPER_BOUND, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND }, diagnostic.getChildren().get(0));
}
// The upper bound of a typed element cannot be 0.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setUpperBound(0);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.VALID_UPPER_BOUND, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND }, diagnostic.getChildren().get(0));
}
// The lower bound of a typed element must be less than or equal to the upper bound, unless the upper bound is -1, or -2.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setLowerBound(2);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.ETYPED_ELEMENT__LOWER_BOUND, EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND }, diagnostic.getChildren().get(0));
}
// An attribute must have a type that's a data type.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
// <-- Bad class type.
eAttribute.setEType(EcorePackage.Literals.EOBJECT);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.ERROR, diagnostic.getSeverity());
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_CLASS_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute.getEGenericType(), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(1));
}
// A generic type used as the type of an attribute must not refer to a class.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Bad class type.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eAttribute.setEGenericType(eGenericType);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.ERROR, diagnostic.getSeverity());
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_CLASS_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType, EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(1));
}
// A reference must have a type that's a class.
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
eReference.setEType(EcorePackage.Literals.ESTRING);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eReference);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference, EcorePackage.Literals.EREFERENCE__EREFERENCE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_DATA_TYPE_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference.getEGenericType(), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(1));
}
// A generic type used as the type of a reference must not refer to a data type.
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eReference.setEGenericType(eGenericType);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eReference);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference, EcorePackage.Literals.EREFERENCE__EREFERENCE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_DATA_TYPE_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference.getEGenericType(), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(1));
}
// A reference with a valid key that's a feature of the reference's type.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
EAttribute a;
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
a = eAttribute;
}
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
eReference.setEType(eClass);
eReference.getEKeys().add(a);
eClass.getEStructuralFeatures().add(eReference);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// Reference with a key that isn't a feature of the type.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
EAttribute a;
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
a = eAttribute;
}
EReference r;
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
// <-- Reference's type doesn't have the key attribute as a feature.
eReference.setEType(EcorePackage.Literals.EOBJECT);
eReference.getEKeys().add(a);
eClass.getEStructuralFeatures().add(eReference);
r = eReference;
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_KEYS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { r, a, EcorePackage.Literals.EREFERENCE__EKEYS }, diagnostic.getChildren().get(0));
}
// A generic type can act as a wildcard only when used as the type argument of a generic type, not when used as the type of a type element.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eOperation.setEGenericType(eGenericType);
// eGenericType.setETypeParameter(...); // <-- Neither a type parameter
// eGenericType.setEClassifier(...); // <-- Nor a classifier.
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_WILDCARD_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType, EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_PARAMETER }, diagnostic.getChildren().get(0));
}
// A generic type must not reference both a classifier and a type parameter.
{
ETypeParameter T;
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
T = eTypeParameter;
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("U");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both a type parameter
eGenericType.setETypeParameter(T);
// <-- And a classifier.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eTypeParameter.getEBounds().add(eGenericType);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_NO_TYPE_PARAMETER_AND_CLASSIFIER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getETypeParameters().get(1).getEBounds().get(0), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_PARAMETER }, diagnostic.getChildren().get(0));
}
// A generic super type must refer to a class.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Bad reference to data type.
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eClass.getEGenericSuperTypes().add(eGenericType);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_CLASS_REQUIRED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getEGenericSuperTypes().get(0), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(0));
}
// No two generic super types may reference the same class.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both refer to EObject.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eClass.getEGenericSuperTypes().add(eGenericType);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both refer to EObject.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eClass.getEGenericSuperTypes().add(eGenericType);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_SUPER_TYPES_DUPLICATE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEGenericSuperTypes().get(0), eClass.getEGenericSuperTypes().get(1), EcorePackage.Literals.ECLASS__EGENERIC_SUPER_TYPES }, diagnostic.getChildren().get(0));
}
// A generic type used as a type argument can be a wildcard.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic type used as a valid wildcard can have a lower bound.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeLowerBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeLowerBound.setEClassifier(EcorePackage.Literals.EOBJECT);
eGenericTypeArgument.setEUpperBound(eGenericTypeLowerBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic type used as a valid wildcard can have an upper bound.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
eGenericTypeArgument.setEUpperBound(eGenericTypeUpperBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic type can't have both an upper and lower bound.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeLowerBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeLowerBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- A lower bound.
eGenericTypeArgument.setELowerBound(eGenericTypeLowerBound);
}
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- And an upper bound.
eGenericTypeArgument.setEUpperBound(eGenericTypeUpperBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS_NO_LOWER_AND_UPPER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute.getEGenericType().getETypeArguments().get(0), EcorePackage.Literals.EGENERIC_TYPE__ELOWER_BOUND, EcorePackage.Literals.EGENERIC_TYPE__EUPPER_BOUND }, diagnostic.getChildren().get(0));
}
// A generic type can't have an upper bound except when used as a type argument.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- Can't have bounds in this context.
eGenericType.setEUpperBound(eGenericTypeUpperBound);
}
eClass.getEGenericSuperTypes().add(eGenericType);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS_NOT_ALLOWED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getEGenericSuperTypes().get(0), EcorePackage.Literals.EGENERIC_TYPE__EUPPER_BOUND }, diagnostic.getChildren().get(0));
}
// A generic type with bounds can't also refer to a type parameter or classifier
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Can't have classifier with bounds.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- Can't have bounds with classifier.
eGenericTypeArgument.setEUpperBound(eGenericTypeUpperBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS_NO_BOUNDS_WITH_TYPE_PARAMETER_OR_CLASSIFIER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute.getEGenericType().getETypeArguments().get(0), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(0));
}
// Generic type with arguments must have a classifier.
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
// Can't have arguments because there is no classifier.
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eGenericType);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_NONE_ALLOWED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS }, diagnostic.getChildren().get(0));
}
// Generic type with classifier that specifies type parameters must have corresponding arguments,
// but it's only a warning, analogous to a raw type warning, to have no arguments when there are type parameters.
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eGenericType);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.WARNING, EcoreValidator.CONSISTENT_ARGUMENTS_NONE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS }, diagnostic.getChildren().get(0));
}
// Generic type's classifier cannot specify a primitive type except as the generic type of a typed element.
{
EClass aClass = EcoreFactory.eINSTANCE.createEClass();
aClass.setName("AClass");
ETypeParameter e = EcoreFactory.eINSTANCE.createETypeParameter();
e.setName("E");
aClass.getETypeParameters().add(e);
EClass bClass = EcoreFactory.eINSTANCE.createEClass();
bClass.setName("BClass");
EGenericType superType = EcoreFactory.eINSTANCE.createEGenericType();
superType.setEClassifier(aClass);
EGenericType typeArgument = EcoreFactory.eINSTANCE.createEGenericType();
typeArgument.setEClassifier(EcorePackage.Literals.EINT);
superType.getETypeArguments().add(typeArgument);
bClass.getEGenericSuperTypes().add(superType);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(bClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_PRIMITIVE_TYPE_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { typeArgument, EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER }, diagnostic.getChildren().get(0));
}
// A generic type with classifier that specifies type parameters and that has arguments must have a matching number of them.
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
// <-- A second argument is not allowed.
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eGenericType);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_INCORRECT_NUMBER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS }, diagnostic.getChildren().get(0));
}
// Generic type must not reference an out of scope type parameter
{
ETypeParameter T;
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("f");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eOperation.getETypeParameters().add(eTypeParameter);
T = eTypeParameter;
}
eClass.getEOperations().add(eOperation);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setETypeParameter(T);
eAttribute.setEGenericType(eGenericType);
}
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_TYPE_PARAMETER_NOT_IN_SCOPE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getEStructuralFeatures().get(0).getEGenericType(), EcorePackage.Literals.EGENERIC_TYPE__ETYPE_PARAMETER }, diagnostic.getChildren().get(0));
}
// Generic type must not make a forward reference to a type parameter
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setETypeParameter(eTypeParameter);
eTypeParameter.getEBounds().add(eBound);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_TYPE_PARAMETER_NOT_IN_SCOPE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getETypeParameters().get(0).getEBounds().get(0), EcorePackage.Literals.EGENERIC_TYPE__ETYPE_PARAMETER }, diagnostic.getChildren().get(0));
}
// Type parameter can be used as the type argument of the
// bound
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setEClassifier(eClass);
eTypeParameter.getEBounds().add(eBound);
EGenericType typeArgument = EcoreFactory.eINSTANCE.createEGenericType();
typeArgument.setETypeParameter(eTypeParameter);
eBound.getETypeArguments().add(typeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic super type can validly use type arguments.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(B);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic super type must not have wildcard type arguments.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(B);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_WILDCARD_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { B.getEGenericSuperTypes().get(0).getETypeArguments().get(0), EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_PARAMETER }, diagnostic.getChildren().get(0));
}
// Generic super types can pass template parameters in complex ways with redundant diamond inheritance.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
EClass C;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("C");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(B);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
C = eClass;
}
assertEquals(2, C.getEAllGenericSuperTypes().size());
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(C);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// Generic super types can pass instantiate template parameters in complex ways with redundant diamond inheritance.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
EClass C;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("C");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Use EString for A here.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(B);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both use EString for B and hence indirectly for A.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
C = eClass;
}
assertEquals(2, C.getEAllGenericSuperTypes().size());
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(C);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// Generic super types can pass instantiate template parameters in complex ways with redundant diamond inheritance.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
EClass C;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("C");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Use EString for A here.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(B);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both use EInteger for B and hence indirectly for A.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EINTEGER_OBJECT);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
C = eClass;
}
assertEquals(3, C.getEAllGenericSuperTypes().size());
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(C);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_SUPER_TYPES_CONFLICT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { C, C.getEAllGenericSuperTypes().get(1), C.getEAllGenericSuperTypes().get(0), EcorePackage.Literals.ECLASS__EALL_GENERIC_SUPER_TYPES }, diagnostic.getChildren().get(0));
}
LOOP: for (int i = 0; i < 100; ++i) {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
// interface X {}
//
EClass X;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("X");
ePackage.getEClassifiers().add(eClass);
X = eClass;
}
// interface Y extends X {}
//
EClass Y;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Y");
eClass.getESuperTypes().add(X);
ePackage.getEClassifiers().add(eClass);
Y = eClass;
}
// interface Container<E> {}
//
EClass Container;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Container");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("E");
eClass.getETypeParameters().add(eTypeParameter);
}
ePackage.getEClassifiers().add(eClass);
Container = eClass;
}
// interface A<T extends Container<?>> {}
//
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setEClassifier(Container);
{
EGenericType eTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
if (i == 2 || i == 3) {
// <-- Container<?> or Container<X>
eTypeArgument.setEClassifier(X);
}
eBound.getETypeArguments().add(eTypeArgument);
}
eTypeParameter.getEBounds().add(eBound);
}
}
ePackage.getEClassifiers().add(eClass);
A = eClass;
}
// interface B<T extends Container<EString>> extends A<T> {}
//
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
ETypeParameter T;
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
//
if (i != 1) {
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setEClassifier(Container);
{
EGenericType eTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
if (i == 2) {
// <-- Container<X> is fine
eTypeArgument.setEClassifier(X);
} else if (i == 3) {
// <-- Container<Y> is an error
eTypeArgument.setEClassifier(Y);
} else {
// <-- Container<EString> is fine.
eTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
}
eBound.getETypeArguments().add(eTypeArgument);
}
eTypeParameter.getEBounds().add(eBound);
}
eClass.getETypeParameters().add(eTypeParameter);
T = eTypeParameter;
}
{
EGenericType eGenericSuperType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericSuperType.setEClassifier(A);
{
EGenericType eTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eTypeArgument.setETypeParameter(T);
eGenericSuperType.getETypeArguments().add(eTypeArgument);
}
eClass.getEGenericSuperTypes().add(eGenericSuperType);
}
ePackage.getEClassifiers().add(eClass);
B = eClass;
}
switch(i) {
case 0:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
case 1:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_INVALID_SUBSTITUTION, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { B.getEGenericSuperTypes().get(0), B.getEGenericSuperTypes().get(0).getETypeArguments().get(0), A.getETypeParameters().get(0), EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS }, diagnostic.getChildren().get(0));
break;
}
case 2:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
case 3:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_INVALID_SUBSTITUTION, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { B.getEGenericSuperTypes().get(0), B.getEGenericSuperTypes().get(0).getETypeArguments().get(0), A.getETypeParameters().get(0), EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS }, diagnostic.getChildren().get(0));
break;
}
default:
{
break LOOP;
}
}
}
}Example 11
| Project: fsmls-master File: EEnumItemProvider.java View source code |
/**
* This handles model notifications by calling {@link #updateChildren} to update any cached
* children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void notifyChanged(Notification notification) {
updateChildren(notification);
switch(notification.getFeatureID(EEnum.class)) {
case EcorePackage.EENUM__ELITERALS:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
return;
}
super.notifyChanged(notification);
}Example 12
| Project: org.eclipse.emf-master File: EcoreValidationTest.java View source code |
public void testEcoreValidator() {
// Validate that the Ecore package instance itself is okay.
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(EcorePackage.eINSTANCE);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// An annotation with an empty string for the source isn't valid.
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAnnotation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_SOURCE_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAnnotation }, diagnostic.getChildren().get(0));
}
// An annotation with a source containing a space isn't valid.
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("a b");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAnnotation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_SOURCE_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAnnotation }, diagnostic.getChildren().get(0));
}
// Two map entries with the same key are not valid.
//
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
{
EObject entry = EcoreFactory.eINSTANCE.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY);
entry.eSet(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY__KEY, "a");
@SuppressWarnings("unchecked") Map.Entry<String, String> stringToStringMapEntry = (Map.Entry<String, String>) entry;
eAnnotation.getDetails().add(stringToStringMapEntry);
}
{
EObject entry = EcoreFactory.eINSTANCE.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY);
entry.eSet(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY__KEY, "a");
@SuppressWarnings("unchecked") Map.Entry<String, String> stringToStringMapEntry = (Map.Entry<String, String>) entry;
eAnnotation.getDetails().add(stringToStringMapEntry);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAnnotation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MAP_ENTRY_UNIQUE, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eAnnotation, EcorePackage.Literals.EANNOTATION__DETAILS, eAnnotation.getDetails().get(1), eAnnotation.getDetails().get(0) }, diagnostic.getChildren().get(0));
}
// A named element without a name is invalid, unless strict element names are disabled.
//
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
diagnostic = Diagnostician.INSTANCE.validate(eClass, Collections.singletonMap(EcoreValidator.STRICT_NAMED_ELEMENT_NAMES, Boolean.FALSE));
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// An instance type name with type arguments is valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("_<_>");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// An instance type name that's just an empty string is not valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_INSTANCE_TYPE_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
}
// An instance type name with unbalanced "<" is not valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("_<_");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_INSTANCE_TYPE_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
}
// An instance type name with unbalanced "[" is not valid.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceTypeName("_[");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_INSTANCE_TYPE_NAME, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
}
// A class that is an interface must also be abstract.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInterface(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.INTERFACE_IS_ABSTRACT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
}
// A class can't have more than one attribute that is an ID.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setID(true);
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("b");
eAttribute.setID(true);
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.AT_MOST_ONE_ID, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEAttributes().get(1), eClass.getEAttributes().get(0) }, diagnostic.getChildren().get(0));
}
// A class can't have two attributes with the same name.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_FEATURE_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEAttributes().get(1), eClass.getEAttributes().get(0) }, diagnostic.getChildren().get(0));
}
// A class can't have two attributes with the matching names.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("A_");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.WARNING, EcoreValidator.UNIQUE_FEATURE_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEAttributes().get(1), eClass.getEAttributes().get(0) }, diagnostic.getChildren().get(0));
}
// A class can't have two operations with matching signatures.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("a");
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("x");
eParameter.setEType(XMLTypePackage.Literals.HEX_BINARY);
eOperation.getEParameters().add(eParameter);
}
eClass.getEOperations().add(eOperation);
}
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("a");
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("x");
eParameter.setEType(XMLTypePackage.Literals.BASE64_BINARY);
eOperation.getEParameters().add(eParameter);
}
eClass.getEOperations().add(eOperation);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_OPERATION_SIGNATURES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEOperations().get(1), eClass.getEOperations().get(0) }, diagnostic.getChildren().get(0));
}
// A class can't have circular super types.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.getESuperTypes().add(eClass);
eClass.setName("_");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.NO_CIRCULAR_SUPER_TYPES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
}
// A map entry class must have a key feature and a value feature.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
eClass.setInstanceClassName("java.util.Map$Entry");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_MAP_ENTRY_CLASS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_MAP_ENTRY_CLASS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass }, diagnostic.getChildren().get(1));
}
// Two enum literals can't have the same name nor matching names.
{
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
eEnum.setName("_");
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("a");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("a");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("A");
eEnum.getELiterals().add(eEnumLiteral);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eEnum);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_ENUMERATOR_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eEnum, eEnum.getELiterals().get(1), eEnum.getELiterals().get(0) }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.WARNING, EcoreValidator.UNIQUE_ENUMERATOR_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eEnum, eEnum.getELiterals().get(2), eEnum.getELiterals().get(0) }, diagnostic.getChildren().get(1));
}
// Two enum literals can't have the same literals.
{
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
eEnum.setName("_");
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("a");
eEnumLiteral.setLiteral("x");
eEnum.getELiterals().add(eEnumLiteral);
}
{
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
eEnumLiteral.setName("b");
eEnumLiteral.setLiteral("x");
eEnum.getELiterals().add(eEnumLiteral);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eEnum);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_ENUMERATOR_LITERALS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eEnum, eEnum.getELiterals().get(1), eEnum.getELiterals().get(0) }, diagnostic.getChildren().get(0));
}
// Two parameters cannot have the same name.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("a");
eParameter.setEType(EcorePackage.Literals.ESTRING);
eOperation.getEParameters().add(eParameter);
}
{
EParameter eParameter = EcoreFactory.eINSTANCE.createEParameter();
eParameter.setName("a");
eParameter.setEType(EcorePackage.Literals.ESTRING);
eOperation.getEParameters().add(eParameter);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_PARAMETER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eOperation, eOperation.getEParameters().get(1), eOperation.getEParameters().get(0) }, diagnostic.getChildren().get(0));
}
// Two type parameters cannot have the same name.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eOperation.getETypeParameters().add(eTypeParameter);
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eOperation.getETypeParameters().add(eTypeParameter);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_TYPE_PARAMETER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eOperation, eOperation.getETypeParameters().get(1), eOperation.getETypeParameters().get(0) }, diagnostic.getChildren().get(0));
}
// Two type parameters cannot have the same name.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eClass.getETypeParameters().add(eTypeParameter);
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("A");
eClass.getETypeParameters().add(eTypeParameter);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_TYPE_PARAMETER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getETypeParameters().get(1), eClass.getETypeParameters().get(0) }, diagnostic.getChildren().get(0));
}
// A void operation must have upper bound 1.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
eOperation.setUpperBound(2);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.NO_REPEATING_VOID, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eOperation }, diagnostic.getChildren().get(0));
}
// A package must have an nsURI.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsPrefix("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage }, diagnostic.getChildren().get(0));
}
// A null string is not a well formed nsURI for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("");
ePackage.setNsPrefix("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage }, diagnostic.getChildren().get(0));
}
// A string with a space is not a well formed nsURI for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("a b");
ePackage.setNsPrefix("");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_URI, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage }, diagnostic.getChildren().get(0));
}
// A prefix that starts with "xml" is not a well formed nsPrefix for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("xml");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_PREFIX, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage }, diagnostic.getChildren().get(0));
}
// A prefix that isn't an NCName because it contains a ":" is not a well formed nsPrefix for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("a:b");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_PREFIX, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage }, diagnostic.getChildren().get(0));
}
// A null prefix that an NCName and is not a well formed nsPrefix for a package.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.WELL_FORMED_NS_PREFIX, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage }, diagnostic.getChildren().get(0));
}
// Two subpackages cannot have the same name.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("a");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("b");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_SUBPACKAGE_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getESubpackages().get(1), ePackage.getESubpackages().get(0) }, diagnostic.getChildren().get(0));
}
// Two classifiers cannot have the same name nor matching names.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("a");
ePackage.getEClassifiers().add(eClass);
}
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("a");
ePackage.getEClassifiers().add(eClass);
}
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
ePackage.getEClassifiers().add(eClass);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_CLASSIFIER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getEClassifiers().get(1), ePackage.getEClassifiers().get(0) }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.WARNING, EcoreValidator.UNIQUE_CLASSIFIER_NAMES, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getEClassifiers().get(2), ePackage.getEClassifiers().get(0) }, diagnostic.getChildren().get(1));
}
// Two packages cannot have the same namespace URI.
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EPackage eSubpackage = EcoreFactory.eINSTANCE.createEPackage();
eSubpackage.setName("a");
eSubpackage.setNsURI("_");
eSubpackage.setNsPrefix("");
ePackage.getESubpackages().add(eSubpackage);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_NS_URIS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage, ePackage.getESubpackages().get(0) }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.UNIQUE_NS_URIS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { ePackage.getESubpackages().get(0), ePackage }, diagnostic.getChildren().get(1));
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("_");
eAttribute.setEType(EcorePackage.Literals.ERESOURCE);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TRANSIENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute }, diagnostic.getChildren().get(0));
}
// There are many ways for opposites to be inconsistent so we'll test them all.
LOOP: for (int i = 0; i < 100; ++i) {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
EClass A;
EReference a;
EClass B;
EReference b;
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
ePackage.getEClassifiers().add(eClass);
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("b");
eClass.getEStructuralFeatures().add(eReference);
b = eReference;
}
A = eClass;
}
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
ePackage.getEClassifiers().add(eClass);
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("a");
eClass.getEStructuralFeatures().add(eReference);
a = eReference;
}
B = eClass;
}
switch(i) {
// Valid unidirectional references.
case 0:
{
a.setEType(A);
b.setEType(B);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// Valid bidirectional references.
case 1:
{
a.setEType(A);
a.setEOpposite(b);
b.setEType(B);
b.setEOpposite(a);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// The opposite must be a feature of the reference's type.
case 2:
{
// <-- Bad type that doesn't have a b feature
a.setEType(B);
a.setEOpposite(b);
b.setEType(B);
b.setEOpposite(a);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_NOT_FROM_TYPE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b, B }, diagnostic.getChildren().get(0));
break;
}
// The opposite of the opposite must be the feature itself.
case 3:
{
a.setEType(A);
a.setEOpposite(b);
b.setEType(B);
// b.setEOpposite(a); <-- No opposite for the opposite
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_NOT_MATCHING, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b, null }, diagnostic.getChildren().get(0));
break;
}
// Valid bidirectional container/containment references.
case 4:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// A container reference must have upper bound 1.
case 5:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
// <-- Bad upper bound.
b.setUpperBound(2);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.SINGLE_CONTAINER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { b }, diagnostic.getChildren().get(0));
break;
}
// Valid bidirectional references that are transient at both ends.
case 6:
{
a.setEType(A);
a.setEOpposite(b);
a.setTransient(true);
b.setEType(B);
b.setEOpposite(a);
b.setTransient(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// Valid bidirectional references with one transient end that doesn't resolve proxy.
case 7:
{
a.setEType(A);
a.setEOpposite(b);
a.setTransient(true);
b.setEType(B);
b.setEOpposite(a);
b.setResolveProxies(false);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// Valid bidirectional references with on transient end that's a container.
case 8:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
b.setTransient(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
// The opposite of a transient bidirectional reference must either be transient as, non-proxy resolving, or a container.
case 9:
{
a.setEType(A);
a.setEOpposite(b);
a.setTransient(true);
// a.setContainment(true); <-- Must be a containment for b to be a container and hence be valid.
b.setEType(B);
b.setEOpposite(a);
// b.setTransient(true); <-- Must be transient.
// b.setResolveProxies(false); <-- Or must not resolve proxies.
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_BAD_TRANSIENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b }, diagnostic.getChildren().get(0));
break;
}
// Both sides can't be containment.
case 10:
{
a.setEType(A);
a.setEOpposite(b);
a.setContainment(true);
b.setEType(B);
b.setEOpposite(a);
b.setContainment(true);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_BOTH_CONTAINMENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { b, a }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_OPPOSITE_BOTH_CONTAINMENT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { a, b }, diagnostic.getChildren().get(1));
break;
}
default:
{
break LOOP;
}
}
}
// The lower bound of a typed element must be >= 0.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setLowerBound(-1);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.VALID_LOWER_BOUND, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute }, diagnostic.getChildren().get(0));
}
// The upper bound of a typed elements must be -2, -1, or >= 1 not 3.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setUpperBound(-3);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.VALID_UPPER_BOUND, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute }, diagnostic.getChildren().get(0));
}
// The upper bound of a typed element cannot be 0.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setUpperBound(0);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.VALID_UPPER_BOUND, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute }, diagnostic.getChildren().get(0));
}
// The lower bound of a typed element must be less than or equal to the upper bound, unless the upper bound is -1, or -2.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eAttribute.setLowerBound(2);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute }, diagnostic.getChildren().get(0));
}
// An attribute must have a type that's a data type.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
// <-- Bad class type.
eAttribute.setEType(EcorePackage.Literals.EOBJECT);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.ERROR, diagnostic.getSeverity());
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_CLASS_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute.getEGenericType() }, diagnostic.getChildren().get(1));
}
// A generic type used as the type of an attribute must not refer to a class.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Bad class type.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eAttribute.setEGenericType(eGenericType);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.ERROR, diagnostic.getSeverity());
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute, EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_CLASS_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType }, diagnostic.getChildren().get(1));
}
// A reference must have a type that's a class.
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
eReference.setEType(EcorePackage.Literals.ESTRING);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eReference);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference, EcorePackage.Literals.EREFERENCE__EREFERENCE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_DATA_TYPE_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference.getEGenericType() }, diagnostic.getChildren().get(1));
}
// A generic type used as the type of a reference must not refer to a data type.
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eReference.setEGenericType(eGenericType);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eReference);
assertEquals(2, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EObjectValidator.EOBJECT__EVERY_MULTIPCITY_CONFORMS, EObjectValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference, EcorePackage.Literals.EREFERENCE__EREFERENCE_TYPE }, diagnostic.getChildren().get(0));
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_DATA_TYPE_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eReference.getEGenericType() }, diagnostic.getChildren().get(1));
}
// A reference with a valid key that's a feature of the reference's type.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
EAttribute a;
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
a = eAttribute;
}
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
eReference.setEType(eClass);
eReference.getEKeys().add(a);
eClass.getEStructuralFeatures().add(eReference);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// Reference with a key that isn't a feature of the type.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
EAttribute a;
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
eAttribute.setEType(EcorePackage.Literals.ESTRING);
eClass.getEStructuralFeatures().add(eAttribute);
a = eAttribute;
}
EReference r;
{
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("r");
// <-- Reference's type doesn't have the key attribute as a feature.
eReference.setEType(EcorePackage.Literals.EOBJECT);
eReference.getEKeys().add(a);
eClass.getEStructuralFeatures().add(eReference);
r = eReference;
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_KEYS, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { r, a }, diagnostic.getChildren().get(0));
}
// A generic type can act as a wildcard only when used as the type argument of a generic type, not when used as the type of a type element.
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("_");
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eOperation.setEGenericType(eGenericType);
// eGenericType.setETypeParameter(...); // <-- Neither a type parameter
// eGenericType.setEClassifier(...); // <-- Nor a classifier.
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eOperation);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_WILDCARD_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType }, diagnostic.getChildren().get(0));
}
// A generic type must not reference both a classifier and a type parameter.
{
ETypeParameter T;
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
T = eTypeParameter;
}
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("U");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both a type parameter
eGenericType.setETypeParameter(T);
// <-- And a classifier.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eTypeParameter.getEBounds().add(eGenericType);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_NO_TYPE_PARAMETER_AND_CLASSIFIER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getETypeParameters().get(1).getEBounds().get(0) }, diagnostic.getChildren().get(0));
}
// A generic super type must refer to a class.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Bad reference to data type.
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eClass.getEGenericSuperTypes().add(eGenericType);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_CLASS_REQUIRED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getEGenericSuperTypes().get(0) }, diagnostic.getChildren().get(0));
}
// No two generic super types may reference the same class.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both refer to EObject.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eClass.getEGenericSuperTypes().add(eGenericType);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both refer to EObject.
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
eClass.getEGenericSuperTypes().add(eGenericType);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_SUPER_TYPES_DUPLICATE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass, eClass.getEGenericSuperTypes().get(1), eClass.getEGenericSuperTypes().get(0) }, diagnostic.getChildren().get(0));
}
// A generic type used as a type argument can be a wildcard.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic type used as a valid wildcard can have a lower bound.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeLowerBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeLowerBound.setEClassifier(EcorePackage.Literals.EOBJECT);
eGenericTypeArgument.setEUpperBound(eGenericTypeLowerBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic type used as a valid wildcard can have an upper bound.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
eGenericTypeArgument.setEUpperBound(eGenericTypeUpperBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic type can't have both an upper and lower bound.
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeLowerBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeLowerBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- A lower bound.
eGenericTypeArgument.setELowerBound(eGenericTypeLowerBound);
}
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- And an upper bound.
eGenericTypeArgument.setEUpperBound(eGenericTypeUpperBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS_NO_LOWER_AND_UPPER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute.getEGenericType().getETypeArguments().get(0) }, diagnostic.getChildren().get(0));
}
// A generic type can't have an upper bound except when used as a type argument.
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EOBJECT);
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- Can't have bounds in this context.
eGenericType.setEUpperBound(eGenericTypeUpperBound);
}
eClass.getEGenericSuperTypes().add(eGenericType);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS_NOT_ALLOWED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getEGenericSuperTypes().get(0) }, diagnostic.getChildren().get(0));
}
// A generic type with bounds can't also refer to a type parameter or classifier
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
eAttribute.setEGenericType(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Can't have classifier with bounds.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
{
EGenericType eGenericTypeUpperBound = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeUpperBound.setEClassifier(EcorePackage.Literals.EOBJECT);
// <-- Can't have bounds with classifier.
eGenericTypeArgument.setEUpperBound(eGenericTypeUpperBound);
}
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eAttribute);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_BOUNDS_NO_BOUNDS_WITH_TYPE_PARAMETER_OR_CLASSIFIER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eAttribute.getEGenericType().getETypeArguments().get(0) }, diagnostic.getChildren().get(0));
}
// Generic type with arguments must have a classifier.
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
// Can't have arguments because there is no classifier.
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eGenericType);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_NONE_ALLOWED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType }, diagnostic.getChildren().get(0));
}
// Generic type with classifier that specifies type parameters must have corresponding arguments,
// but it's only a warning, analogous to a raw type warning, to have no arguments when there are type parameters.
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eGenericType);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.WARNING, EcoreValidator.CONSISTENT_ARGUMENTS_NONE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType }, diagnostic.getChildren().get(0));
}
// Generic type's classifier cannot specify a primitive type except as the generic type of a typed element.
{
EClass aClass = EcoreFactory.eINSTANCE.createEClass();
aClass.setName("AClass");
ETypeParameter e = EcoreFactory.eINSTANCE.createETypeParameter();
e.setName("E");
aClass.getETypeParameters().add(e);
EClass bClass = EcoreFactory.eINSTANCE.createEClass();
bClass.setName("BClass");
EGenericType superType = EcoreFactory.eINSTANCE.createEGenericType();
superType.setEClassifier(aClass);
EGenericType typeArgument = EcoreFactory.eINSTANCE.createEGenericType();
typeArgument.setEClassifier(EcorePackage.Literals.EINT);
superType.getETypeArguments().add(typeArgument);
bClass.getEGenericSuperTypes().add(superType);
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(bClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_PRIMITIVE_TYPE_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { typeArgument }, diagnostic.getChildren().get(0));
}
// A generic type with classifier that specifies type parameters and that has arguments must have a matching number of them.
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EJAVA_CLASS);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
// <-- A second argument is not allowed.
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eGenericType);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_INCORRECT_NUMBER, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eGenericType }, diagnostic.getChildren().get(0));
}
// Generic type must not reference an out of scope type parameter
{
ETypeParameter T;
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
eOperation.setName("f");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eOperation.getETypeParameters().add(eTypeParameter);
T = eTypeParameter;
}
eClass.getEOperations().add(eOperation);
}
{
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("a");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setETypeParameter(T);
eAttribute.setEGenericType(eGenericType);
}
eClass.getEStructuralFeatures().add(eAttribute);
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_TYPE_PARAMETER_NOT_IN_SCOPE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getEStructuralFeatures().get(0).getEGenericType() }, diagnostic.getChildren().get(0));
}
// Generic type must not make a forward reference to a type parameter
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setETypeParameter(eTypeParameter);
eTypeParameter.getEBounds().add(eBound);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_TYPE_PARAMETER_NOT_IN_SCOPE, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { eClass.getETypeParameters().get(0).getEBounds().get(0) }, diagnostic.getChildren().get(0));
}
// Type parameter can be used as the type argument of the
// bound
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("_");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setEClassifier(eClass);
eTypeParameter.getEBounds().add(eBound);
EGenericType typeArgument = EcoreFactory.eINSTANCE.createEGenericType();
typeArgument.setETypeParameter(eTypeParameter);
eBound.getETypeArguments().add(typeArgument);
}
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic super type can validly use type arguments.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(B);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// A generic super type must not have wildcard type arguments.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(B);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_TYPE_WILDCARD_NOT_PERMITTED, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { B.getEGenericSuperTypes().get(0).getETypeArguments().get(0) }, diagnostic.getChildren().get(0));
}
// Generic super types can pass template parameters in complex ways with redundant diamond inheritance.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
EClass C;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("C");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(B);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
C = eClass;
}
assertEquals(2, C.getEAllGenericSuperTypes().size());
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(C);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// Generic super types can pass instantiate template parameters in complex ways with redundant diamond inheritance.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
EClass C;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("C");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Use EString for A here.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(B);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both use EString for B and hence indirectly for A.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
C = eClass;
}
assertEquals(2, C.getEAllGenericSuperTypes().size());
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(C);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
}
// Generic super types can pass instantiate template parameters in complex ways with redundant diamond inheritance.
{
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
A = eClass;
}
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eGenericTypeArgument.setETypeParameter(eClass.getETypeParameters().get(0));
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
B = eClass;
}
EClass C;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("C");
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(A);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Use EString for A here.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
{
EGenericType eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(B);
eClass.getEGenericSuperTypes().add(eGenericType);
{
EGenericType eGenericTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
// <-- Both use EInteger for B and hence indirectly for A.
eGenericTypeArgument.setEClassifier(EcorePackage.Literals.EINTEGER_OBJECT);
eGenericType.getETypeArguments().add(eGenericTypeArgument);
}
}
C = eClass;
}
assertEquals(3, C.getEAllGenericSuperTypes().size());
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(C);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_SUPER_TYPES_CONFLICT, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { C, C.getEAllGenericSuperTypes().get(1), C.getEAllGenericSuperTypes().get(0) }, diagnostic.getChildren().get(0));
}
LOOP: for (int i = 0; i < 100; ++i) {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("_");
ePackage.setNsURI("_");
ePackage.setNsPrefix("");
// interface X {}
//
EClass X;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("X");
ePackage.getEClassifiers().add(eClass);
X = eClass;
}
// interface Y extends X {}
//
EClass Y;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Y");
eClass.getESuperTypes().add(X);
ePackage.getEClassifiers().add(eClass);
Y = eClass;
}
// interface Container<E> {}
//
EClass Container;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Container");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("E");
eClass.getETypeParameters().add(eTypeParameter);
}
ePackage.getEClassifiers().add(eClass);
Container = eClass;
}
// interface A<T extends Container<?>> {}
//
EClass A;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("A");
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
eClass.getETypeParameters().add(eTypeParameter);
{
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setEClassifier(Container);
{
EGenericType eTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
if (i == 2 || i == 3) {
// <-- Container<?> or Container<X>
eTypeArgument.setEClassifier(X);
}
eBound.getETypeArguments().add(eTypeArgument);
}
eTypeParameter.getEBounds().add(eBound);
}
}
ePackage.getEClassifiers().add(eClass);
A = eClass;
}
// interface B<T extends Container<EString>> extends A<T> {}
//
EClass B;
{
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("B");
ETypeParameter T;
{
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE.createETypeParameter();
eTypeParameter.setName("T");
//
if (i != 1) {
EGenericType eBound = EcoreFactory.eINSTANCE.createEGenericType();
eBound.setEClassifier(Container);
{
EGenericType eTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
if (i == 2) {
// <-- Container<X> is fine
eTypeArgument.setEClassifier(X);
} else if (i == 3) {
// <-- Container<Y> is an error
eTypeArgument.setEClassifier(Y);
} else {
// <-- Container<EString> is fine.
eTypeArgument.setEClassifier(EcorePackage.Literals.ESTRING);
}
eBound.getETypeArguments().add(eTypeArgument);
}
eTypeParameter.getEBounds().add(eBound);
}
eClass.getETypeParameters().add(eTypeParameter);
T = eTypeParameter;
}
{
EGenericType eGenericSuperType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericSuperType.setEClassifier(A);
{
EGenericType eTypeArgument = EcoreFactory.eINSTANCE.createEGenericType();
eTypeArgument.setETypeParameter(T);
eGenericSuperType.getETypeArguments().add(eTypeArgument);
}
eClass.getEGenericSuperTypes().add(eGenericSuperType);
}
ePackage.getEClassifiers().add(eClass);
B = eClass;
}
switch(i) {
case 0:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
case 1:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_INVALID_SUBSTITUTION, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { B.getEGenericSuperTypes().get(0), B.getEGenericSuperTypes().get(0).getETypeArguments().get(0), A.getETypeParameters().get(0) }, diagnostic.getChildren().get(0));
break;
}
case 2:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(Diagnostic.OK, diagnostic.getSeverity());
break;
}
case 3:
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ePackage);
assertEquals(1, diagnostic.getChildren().size());
assertDiagnostic(Diagnostic.ERROR, EcoreValidator.CONSISTENT_ARGUMENTS_INVALID_SUBSTITUTION, EcoreValidator.DIAGNOSTIC_SOURCE, new Object[] { B.getEGenericSuperTypes().get(0), B.getEGenericSuperTypes().get(0).getETypeArguments().get(0), A.getETypeParameters().get(0) }, diagnostic.getChildren().get(0));
break;
}
default:
{
break LOOP;
}
}
}
}Example 13
| Project: FURCAS-master File: RoseEcoreBuilder.java View source code |
protected void visitClass(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) {
if (objectName == null || objectName.length() == 0) {
String quid = roseNode.getRoseId();
if (quid != null) {
quid = quid.substring(1, quid.length() - 1);
}
objectName = "Unnamed" + quid;
error(RoseImporterPlugin.INSTANCE.getString("_UI_UnnamedClass_message", new Object[] { objectName }));
}
// Map to EClass, EEnum or EInerface.
// Note that we do not map structure and primitive type class.
//
RoseNode stereoTypeNode = roseNode.findNodeWithKey(RoseStrings.STEREOTYPE);
if (stereoTypeNode != null) {
String stereoTypeValue = stereoTypeNode.getValue();
stereoTypeValue = stereoTypeValue.substring(1, stereoTypeValue.length() - 1);
if (stereoTypeValue.equals(RoseStrings.INTERFACE)) {
// Map to an EClass.
//
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
allClasses.add(eClass);
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eClass.setName(classifierName);
roseNode.setNode(eClass);
setEClassProperties(roseNode, eClass);
eClass.setInterface(true);
eClass.setAbstract(true);
build(roseNode, parent, eClass);
} else if (stereoTypeValue.equalsIgnoreCase(RoseStrings.ENUMERATION)) {
// Map to an EEnum.
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eEnum.setName(classifierName);
roseNode.setNode(eEnum);
setEEnumProperties(roseNode, eEnum);
build(roseNode, parent, eEnum);
} else if (stereoTypeValue.equalsIgnoreCase("datatype") || stereoTypeValue.equalsIgnoreCase("primitive")) {
// Map to an EDataType.
//
EDataType eDataType = EcoreFactory.eINSTANCE.createEDataType();
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eDataType.setName(classifierName);
roseNode.setNode(eDataType);
setEDataTypeProperties(roseNode, eDataType);
build(roseNode, parent, eDataType);
String uml2MOFCorbaType = roseNode.getUML2MOFCorbaType();
if (uml2MOFCorbaType != null) {
uml2MOFCorbaType = uml2MOFCorbaType.trim();
int start = uml2MOFCorbaType.indexOf("typedef ");
if (start != -1) {
uml2MOFCorbaType = uml2MOFCorbaType.substring(8);
int end = uml2MOFCorbaType.lastIndexOf(" ");
if (end != -1) {
uml2MOFCorbaType = uml2MOFCorbaType.substring(0, end);
}
}
if (uml2MOFCorbaType != null && uml2MOFCorbaType.length() != 0) {
roseUtil.typeTable.put(eDataType, uml2MOFCorbaType);
}
}
} else if (stereoTypeValue.equalsIgnoreCase("javatype")) {
// Map to an EDataType.
//
EDataType eDataType = EcoreFactory.eINSTANCE.createEDataType();
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
int index = objectName.lastIndexOf(".");
classifierName = validName(upperCaseName(index == -1 ? objectName : objectName.substring(index + 1)));
}
int index = objectName.lastIndexOf(".");
eDataType.setName(validName(upperCaseName(index == -1 ? objectName : objectName.substring(index + 1))));
eDataType.setInstanceClassName(objectName);
roseNode.setNode(eDataType);
setEDataTypeProperties(roseNode, eDataType);
build(roseNode, parent, eDataType);
} else if (stereoTypeValue.equalsIgnoreCase("abstract")) {
// Map to an EClass.
//
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
allClasses.add(eClass);
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eClass.setName(classifierName);
roseNode.setNode(eClass);
setEClassProperties(roseNode, eClass);
build(roseNode, parent, eClass);
} else if (stereoTypeValue.equalsIgnoreCase("MapEntry")) {
// Map to an EClass.
//
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
allClasses.add(eClass);
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eClass.setName(classifierName);
roseNode.setNode(eClass);
setEClassProperties(roseNode, eClass);
eClass.setInstanceClassName("java.util.Map$Entry");
build(roseNode, parent, eClass);
} else if (stereoTypeValue.equalsIgnoreCase("constraint")) {
// look for an "OCL" operation and if found, extract OCL expression from Semantics node
// first, find owning class
String x = objectName;
x = x + "";
} else {
warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnrecognizedStereotype_message", new Object[] { stereoTypeValue, objectName }));
// Map to an eClass.
//
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
allClasses.add(eClass);
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eClass.setName(classifierName);
roseNode.setNode(eClass);
setEClassProperties(roseNode, eClass);
build(roseNode, parent, eClass);
}
} else {
// Map to an eClass.
//
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
allClasses.add(eClass);
String classifierName = roseNode.getClassifierName();
if (classifierName == null || classifierName.length() == 0) {
classifierName = validName(upperCaseName(objectName));
}
eClass.setName(classifierName);
roseNode.setNode(eClass);
setEClassProperties(roseNode, eClass);
build(roseNode, parent, eClass);
}
}Example 14
| Project: org.eclipse.xpand-master File: EmfRegistryMetaModel.java View source code |
@Override
protected Type createNew(EObject param) {
if (param == null) {
return null;
}
if (param instanceof EGenericType) {
EGenericType genericType = (EGenericType) param;
if (typeSystem != null) {
Type innerType = getTypeForEClassifier(genericType.getETypeArguments().get(0));
return new EmfListType(innerType, typeSystem, BuiltinMetaModel.LIST);
} else {
param = genericType.getEClassifier();
}
}
if (!(param instanceof EClassifier))
return null;
EClassifier ele = (EClassifier) param;
if (ele.getName() == null) {
return null;
}
if (ele instanceof EClass) {
return new EClassType(EmfRegistryMetaModel.this, getFullyQualifiedName(ele), (EClass) ele);
} else if (ele instanceof EEnum) {
return new EEnumType(EmfRegistryMetaModel.this, getFullyQualifiedName(ele), (EEnum) ele);
} else if (ele instanceof EDataType) {
if (typeSystem != null) {
if (stringTypes.contains(ele)) {
return typeSystem.getStringType();
} else if (booleanTypes.contains(ele)) {
return typeSystem.getBooleanType();
} else if (intTypes.contains(ele)) {
return typeSystem.getIntegerType();
} else if (realTypes.contains(ele)) {
return typeSystem.getRealType();
} else if (objectTypes.contains(ele)) {
return typeSystem.getObjectType();
} else if (listTypes.contains(ele)) {
return new EmfListType(typeSystem.getObjectType(), typeSystem, BuiltinMetaModel.LIST);
}
}
EDataType dataType = (EDataType) ele;
if (dataType.getInstanceClassName() != null) {
// fall back to qualified Java name for EDatatypes
Type t = internalJbmm.getTypeForName(dataType.getInstanceClassName().replace(".", "::"));
if (t == null) {
// for primitives
t = typeSystem.getTypeForName(dataType.getInstanceClassName().replace(".", "::"));
}
return t;
} else {
return typeSystem.getObjectType();
}
}
return null;
}Example 15
| Project: ASEME-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 16
| Project: ecore-master File: AbstractOCCISemanticSequencer.java View source code |
@Override
public void createSequence(EObject context, EObject semanticObject) {
if (semanticObject.eClass().getEPackage() == EcorePackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case EcorePackage.EANNOTATION:
sequence_DataTypeAnnotations(context, (EAnnotation) semanticObject);
return;
case EcorePackage.EDATA_TYPE:
sequence_DataTypeDecl(context, (EDataType) semanticObject);
return;
case EcorePackage.EENUM:
sequence_EnumTypeDecl(context, (EEnum) semanticObject);
return;
case EcorePackage.EENUM_LITERAL:
sequence_EnumLiteralDecl(context, (EEnumLiteral) semanticObject);
return;
case EcorePackage.ESTRING_TO_STRING_MAP_ENTRY:
sequence_DataTypeAnnotation(context, (Entry<?, ?>) semanticObject);
return;
}
else if (semanticObject.eClass().getEPackage() == OCCIPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case OCCIPackage.ACTION:
sequence_ActionDecl(context, (Action) semanticObject);
return;
case OCCIPackage.ATTRIBUTE:
if (context == grammarAccess.getAttributeDeclRule()) {
sequence_AttributeDecl(context, (Attribute) semanticObject);
return;
} else if (context == grammarAccess.getParameterDeclRule()) {
sequence_ParameterDecl(context, (Attribute) semanticObject);
return;
} else
break;
case OCCIPackage.ATTRIBUTE_STATE:
sequence_StateDecl(context, (AttributeState) semanticObject);
return;
case OCCIPackage.CONFIGURATION:
sequence_ConfigurationDecl(context, (Configuration) semanticObject);
return;
case OCCIPackage.EXTENSION:
sequence_ExtensionDecl(context, (Extension) semanticObject);
return;
case OCCIPackage.KIND:
sequence_KindDecl(context, (Kind) semanticObject);
return;
case OCCIPackage.LINK:
sequence_LinkDecl(context, (Link) semanticObject);
return;
case OCCIPackage.MIXIN:
sequence_MixinDecl(context, (Mixin) semanticObject);
return;
case OCCIPackage.RESOURCE:
sequence_ResourceDecl(context, (Resource) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}Example 17
| Project: EMF-IncQuery-master File: EMFPatternLanguageJavaValidator.java View source code |
@Check
public void checkEnumValues(EnumValue value) {
if (value.eContainer() instanceof PathExpressionHead) {
// If container is PathExpression check for enum type assignability
EEnum enumType = value.getEnumeration();
if (enumType == null && value.getLiteral() != null) {
enumType = value.getLiteral().getEEnum();
}
PathExpressionHead expression = (PathExpressionHead) value.eContainer();
try {
EEnum expectedType = EMFPatternLanguageScopeHelper.calculateEnumerationType(expression);
if (enumType != null && !expectedType.equals(enumType)) {
error(String.format("Inconsistent enumeration types: found %s but expected %s", enumType.getName(), expectedType.getName()), value, EMFPatternLanguagePackage.Literals.ENUM_VALUE__ENUMERATION, EMFIssueCodes.INVALID_ENUM_LITERAL);
}
} catch (ResolutionException e) {
error(String.format("Invalid enumeration constant %s", enumType.getName()), value, EMFPatternLanguagePackage.Literals.ENUM_VALUE__ENUMERATION, EMFIssueCodes.INVALID_ENUM_LITERAL);
}
}
}Example 18
| Project: EMFTools-master File: MecoreWrapper.java View source code |
private void wrapMEnum(MEnum mEnum, EPackage ePackage) {
EEnum eEnum = findOrCreateEEnum(mEnum, ePackage);
eEnum.setName(mEnum.getName());
int count = 0;
for (MEnumLiteral literal : mEnum.getLiterals()) {
wrapMEnumLiteral(literal, eEnum, count++);
}
wrapMAnnotations(mEnum, eEnum);
primaryMapping.put(mEnum, eEnum);
}Example 19
| Project: gmf-tooling.uml2tools-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 20
| Project: melanee-core-master File: PLMAbstractExpression.java View source code |
/**
* 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 21
| Project: qvto-master File: CompletionProposalUtil.java View source code |
public static final void addPackageContentsProposals(Collection<ICompletionProposal> proposals, QvtCompletionData data, EPackage pack) {
for (EClassifier classifier : pack.getEClassifiers()) {
String classifierName = classifier.getName();
if (classifierName == null) {
continue;
}
String imageCategory = CategoryImageConstants.CLASSIFIER;
if (classifier instanceof EClass) {
imageCategory = CategoryImageConstants.CLASS;
classifierName = escapeNameIfNecessary(classifierName);
} else if (classifier instanceof EEnum) {
imageCategory = CategoryImageConstants.ENUM;
} else if (classifier instanceof EDataType) {
imageCategory = CategoryImageConstants.DATATYPE;
}
QvtCompletionProposal info = CompletionProposalUtil.createCompletionProposal(classifierName, imageCategory, data);
CompletionProposalUtil.addProposalIfNecessary(proposals, info, data);
}
for (EPackage subPack : pack.getESubpackages()) {
QvtCompletionProposal info = CompletionProposalUtil.createCompletionProposal(subPack.getName(), CategoryImageConstants.PACKAGE, data);
CompletionProposalUtil.addProposalIfNecessary(proposals, info, data);
}
}Example 22
| Project: ui-bindings-master File: EnumBindingDecorator.java View source code |
@Override
public void init(IValueBinding binding) {
super.init(binding);
final EClassifier attributeType = binding.getDataType().getEType();
if (!(attributeType instanceof EEnum)) {
getBinding().addErrorCondition("Attribute is not an enumeration");
return;
}
myEnumeration = (EEnum) attributeType;
for (final IEnumDecoratorProviderEntry e : myProvider.getBaseMappings()) {
final String uiValue = e.getUi();
final String modelValue = e.getModel();
uiToModelMappings.put(uiValue, modelValue);
uiSequence.add(uiValue);
if (!modelToUIMappings.containsKey(modelValue)) {
modelToUIMappings.put(modelValue, uiValue);
}
}
if (myProvider.isAddingDefaultMappings()) {
for (final EEnumLiteral e : myEnumeration.getELiterals()) {
final String modelValue = e.getName();
final String uiValue = e.getLiteral();
uiToModelMappings.put(uiValue, modelValue);
uiSequence.add(uiValue);
if (!modelToUIMappings.containsKey(modelValue)) {
modelToUIMappings.put(modelValue, uiValue);
}
}
}
}Example 23
| Project: extFM-Tooling-master File: MtextCodeCompletionHelper.java View source code |
public void run() {
if (feature instanceof org.eclipse.emf.ecore.EReference) {
org.eclipse.emf.ecore.EReference reference = (org.eclipse.emf.ecore.EReference) feature;
if (featureType instanceof org.eclipse.emf.ecore.EClass) {
if (reference.isContainment()) {
// the FOLLOW set should contain only non-containment references
assert false;
} else {
proposals.addAll(handleNCReference(expectedTerminal, container, reference, expectedTerminal.getPrefix(), expectedFeature.getTokenName()));
}
}
} else if (feature instanceof org.eclipse.emf.ecore.EAttribute) {
org.eclipse.emf.ecore.EAttribute attribute = (org.eclipse.emf.ecore.EAttribute) feature;
if (featureType instanceof org.eclipse.emf.ecore.EEnum) {
org.eclipse.emf.ecore.EEnum enumType = (org.eclipse.emf.ecore.EEnum) featureType;
proposals.addAll(handleEnumAttribute(expectedTerminal, expectedFeature, enumType, expectedTerminal.getPrefix(), container));
} else {
// handle EAttributes (derive default value depending on the type of the
// attribute, figure out token resolver, and call deResolve())
proposals.addAll(handleAttribute(expectedTerminal, expectedFeature, container, attribute, expectedTerminal.getPrefix()));
}
} else {
// there should be no other subclass of EStructuralFeature
assert false;
}
}Example 24
| Project: k3-master File: ModelGeneratorUtil.java View source code |
public void setEObjectAttributes(EObject eObject, Random random, Set<RuntimeException> exceptionLog, boolean ignoreAndLog) {
Map<EClassifier, IAttributeSetter<?>> attributeSetters = attributeHandler.getAttributeSetters();
for (EAttribute attribute : eObject.eClass().getEAllAttributes()) {
EClassifier attributeType = attribute.getEAttributeType();
if (!isValid(attribute, eObject, exceptionLog, ignoreAndLog)) {
continue;
}
// the attribute setter used to create new attributes
IAttributeSetter<?> attributeSetter = null;
// is there a setter for this attribute?
if (attributeSetters.containsKey(attributeType)) {
attributeSetter = attributeSetters.get(attributeType);
} else if (isEnum(attributeType)) {
attributeSetter = attributeHandler.getEEnumSetter((EEnum) attributeType);
}
// was there a fitting attribute setter?
if (attributeSetter != null) {
if (attribute.isMany()) {
int numberOfAttributes = computeFeatureAmount(attribute, random);
addPerCommand(eObject, attribute, attributeSetter.createNewAttributes(numberOfAttributes), exceptionLog, ignoreAndLog);
} else {
setPerCommand(eObject, attribute, attributeSetter.createNewAttribute(), exceptionLog, ignoreAndLog);
}
}
}
}Example 25
| Project: ThingML-master File: ThingmlCodeCompletionHelper.java View source code |
public void run() {
if (feature instanceof org.eclipse.emf.ecore.EReference) {
org.eclipse.emf.ecore.EReference reference = (org.eclipse.emf.ecore.EReference) feature;
if (featureType instanceof org.eclipse.emf.ecore.EClass) {
if (reference.isContainment()) {
// the FOLLOW set should contain only non-containment references
assert false;
} else {
proposals.addAll(handleNCReference(expectedTerminal, container, reference, expectedTerminal.getPrefix(), expectedFeature.getTokenName()));
}
}
} else if (feature instanceof org.eclipse.emf.ecore.EAttribute) {
org.eclipse.emf.ecore.EAttribute attribute = (org.eclipse.emf.ecore.EAttribute) feature;
if (featureType instanceof org.eclipse.emf.ecore.EEnum) {
org.eclipse.emf.ecore.EEnum enumType = (org.eclipse.emf.ecore.EEnum) featureType;
proposals.addAll(handleEnumAttribute(expectedTerminal, expectedFeature, enumType, expectedTerminal.getPrefix(), container));
} else {
// handle EAttributes (derive default value depending on the type of the
// attribute, figure out token resolver, and call deResolve())
proposals.addAll(handleAttribute(expectedTerminal, expectedFeature, container, attribute, expectedTerminal.getPrefix()));
}
} else {
// there should be no other subclass of EStructuralFeature
assert false;
}
}Example 26
| Project: amalgamation-examples-master File: TabWidgetPropertiesEditionComponent.java View source code |
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
* org.eclipse.emf.ecore.resource.ResourceSet)
*
*/
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
setInitializing(true);
if (editingPart != null && key == partKey) {
editingPart.setContext(elt, allResource);
final TabWidget tabWidget = (TabWidget) elt;
final TabWidgetPropertiesEditionPart basePart = (TabWidgetPropertiesEditionPart) editingPart;
// init values
if (tabWidget.getName() != null && isAccessible(DroidViewsRepository.TabWidget.Properties.name))
basePart.setName(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getEString(), tabWidget.getName()));
if (tabWidget.getAlpha() != null && isAccessible(DroidViewsRepository.TabWidget.Properties.alpha))
basePart.setAlpha(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getEFloatObject(), tabWidget.getAlpha()));
if (isAccessible(DroidViewsRepository.TabWidget.Properties.nextFocusDown)) {
// init part
nextFocusDownSettings = new EObjectFlatComboSettings(tabWidget, DroidPackage.eINSTANCE.getLayout_NextFocusDown());
basePart.initNextFocusDown(nextFocusDownSettings);
// set the button mode
basePart.setNextFocusDownButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(DroidViewsRepository.TabWidget.Properties.nextFocusLeft)) {
// init part
nextFocusLeftSettings = new EObjectFlatComboSettings(tabWidget, DroidPackage.eINSTANCE.getLayout_NextFocusLeft());
basePart.initNextFocusLeft(nextFocusLeftSettings);
// set the button mode
basePart.setNextFocusLeftButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(DroidViewsRepository.TabWidget.Properties.nextFocusRight)) {
// init part
nextFocusRightSettings = new EObjectFlatComboSettings(tabWidget, DroidPackage.eINSTANCE.getLayout_NextFocusRight());
basePart.initNextFocusRight(nextFocusRightSettings);
// set the button mode
basePart.setNextFocusRightButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(DroidViewsRepository.TabWidget.Properties.nextFocusUp)) {
// init part
nextFocusUpSettings = new EObjectFlatComboSettings(tabWidget, DroidPackage.eINSTANCE.getLayout_NextFocusUp());
basePart.initNextFocusUp(nextFocusUpSettings);
// set the button mode
basePart.setNextFocusUpButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(DroidViewsRepository.TabWidget.Properties.visibility)) {
basePart.initVisibility((EEnum) DroidPackage.eINSTANCE.getLayout_Visibility().getEType(), tabWidget.getVisibility());
}
if (isAccessible(DroidViewsRepository.TabWidget.Properties.orientation)) {
basePart.initOrientation((EEnum) DroidPackage.eINSTANCE.getAbstractLinearLayout_Orientation().getEType(), tabWidget.getOrientation());
}
if (tabWidget.getGravity() != null && isAccessible(DroidViewsRepository.TabWidget.Properties.gravity))
basePart.setGravity(tabWidget.getGravity());
// init filters
basePart.addFilterToNextFocusDown(new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
return //$NON-NLS-1$
(element instanceof String && element.equals("")) || (element instanceof View);
}
});
// Start of user code for additional businessfilters for nextFocusDown
// End of user code
basePart.addFilterToNextFocusLeft(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
return //$NON-NLS-1$
(element instanceof String && element.equals("")) || (element instanceof View);
}
});
// Start of user code for additional businessfilters for nextFocusLeft
// End of user code
basePart.addFilterToNextFocusRight(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
return //$NON-NLS-1$
(element instanceof String && element.equals("")) || (element instanceof View);
}
});
// Start of user code for additional businessfilters for nextFocusRight
// End of user code
basePart.addFilterToNextFocusUp(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
return //$NON-NLS-1$
(element instanceof String && element.equals("")) || (element instanceof View);
}
});
// Start of user code for additional businessfilters for nextFocusUp
// End of user code
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}Example 27
| Project: cdo-master File: CoreTypeMappings.java View source code |
@Override
protected Object getDefaultValue() {
// return getFeature().getDefaultValue();
EEnum eenum = (EEnum) getFeature().getEType();
String defaultValueLiteral = getFeature().getDefaultValueLiteral();
if (defaultValueLiteral != null) {
EEnumLiteral literal = eenum.getEEnumLiteralByLiteral(defaultValueLiteral);
return literal.getValue();
}
Enumerator enumerator = (Enumerator) eenum.getDefaultValue();
return enumerator.getValue();
}Example 28
| Project: ecoretools-master File: TableObjectManager.java View source code |
/** * Computes the EStructuralFeature type. When the type is an enumeration * this function will initialize the literals array * * @see EcorePackage#EBOOLEAN , EcorePackage#ESTRING , EcorePackage#EINT or * EcorePackage#EEnum * @see #BOOL * @see #INT * @see #STR * @see #ENUM * * @return An integer code which determine the type */ public int getEType() { if (type instanceof EEnum) { return ENUM; } else if (type instanceof EDataType) { Class<?> clazz = type.getInstanceClass(); if (clazz == int.class || clazz == Integer.class) { return INT; } else if (clazz == double.class || clazz == Double.class) { return DBL; } else if (clazz == BigInteger.class) { return B_INT; } else if (clazz == String.class) { return STR; } else if (clazz == boolean.class || clazz == Boolean.class) { return BOOL; } else { return 0; } } else if (type instanceof EClass) { return REF; } else { return 0; } }
Example 29
| Project: emf-databinding-example-master File: PersistenceMappingSchemaGenerator.java View source code |
/** process annotation packages */
private List<Element> processAnnotationEPackage(EPackage epackage) {
final ArrayList<Element> elemList = new ArrayList<Element>();
final List<EClassifier> eclassifiers = new ArrayList<EClassifier>(epackage.getEClassifiers());
Collections.sort(eclassifiers, new ENamedElementComparator());
for (EClassifier eClassifier : eclassifiers) {
if (isIgnorable(eClassifier) || isUnsupported(eClassifier)) {
continue;
}
String schemaTypeName = eClassifier.getName();
if (eClassifier instanceof EClass) {
final EClass eClass = (EClass) eClassifier;
if (eClass.isAbstract()) {
continue;
}
final List<EStructuralFeature> eStructuralFeatures = eClass.getEAllStructuralFeatures();
if (eStructuralFeatures.isEmpty()) {
continue;
}
// the schema.
if (oneMappableFeature(eClass)) {
/*
* final EStructuralFeature eStructuralFeature = (EStructuralFeature)
* eClass.getEStructuralFeatures().get(0); final EClassifier eType =
* eStructuralFeature.getEType(); schemaTypeName = (String)
* schemaTypeNamesByAnnotationType.get(eType.getName()); if (schemaTypeName ==
* null) { schemaTypeName = eType.getName(); }
* schemaTypeNamesByAnnotationType.put(eClassifier.getName(), schemaTypeName);
*/
continue;
}
final Element complexTypeElement = createSchemaComplexType(eClass.getName());
elemList.add(complexTypeElement);
final Element choiceElement = complexTypeElement.addElement("xsd:choice");
addZeroUnbounded(choiceElement);
processStructuralFeatures(choiceElement, eStructuralFeatures);
if (choiceElement.getChildren().size() == 0) {
complexTypeElement.getChildren().remove(choiceElement);
}
} else if (eClassifier instanceof EEnum) {
elemList.add(processEnum((EEnum) eClassifier));
} else {
throw new RuntimeException("Unexpected EClassifier: " + eClassifier.eClass().getName());
}
schemaTypeNamesByAnnotationType.put(eClassifier.getName(), schemaTypeName);
}
return elemList;
}Example 30
| Project: MMI-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 31
| Project: MMINT-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 32
| Project: dresdenocl-master File: OclCodeCompletionHelper.java View source code |
public void run() {
if (feature instanceof EReference) {
EReference reference = (EReference) feature;
if (featureType instanceof EClass) {
if (reference.isContainment()) {
// the FOLLOW set should contain only non-containment references
assert false;
} else {
proposals.addAll(handleNCReference(expectedTerminal, container, reference, expectedTerminal.getPrefix(), expectedFeature.getTokenName()));
}
}
} else if (feature instanceof EAttribute) {
EAttribute attribute = (EAttribute) feature;
if (featureType instanceof EEnum) {
EEnum enumType = (EEnum) featureType;
proposals.addAll(handleEnumAttribute(expectedTerminal, expectedFeature, enumType, expectedTerminal.getPrefix(), container));
} else {
// handle EAttributes (derive default value depending on the type of the
// attribute, figure out token resolver, and call deResolve())
proposals.addAll(handleAttribute(expectedTerminal, expectedFeature, container, attribute, expectedTerminal.getPrefix()));
}
} else {
// there should be no other subclass of EStructuralFeature
assert false;
}
}Example 33
| Project: emf-fragments-master File: FStoreImpl.java View source code |
private Object getUserValue(Object internalValue, EStructuralFeature userFeature) {
if (userFeature != null && userFeature.getEType() instanceof EEnum) {
return EcoreUtil.createFromString((EDataType) userFeature.getEType(), internalValue.toString());
} else if (internalValue != null && internalValue instanceof DynamicEObjectImpl) {
FInternalObjectImpl internalObject = (FInternalObjectImpl) internalValue;
return getUserObject(internalObject);
} else {
return internalValue;
}
}Example 34
| Project: etl-java-master File: EMFTermParser.java View source code |
/**
* {@inheritDoc}
*/
@Override
protected Object parseValue(EObject rc, EStructuralFeature f, Token value) {
final EStructuralFeature field = f;
final EClassifier type = field.getEType();
if (type instanceof EEnum) {
return ((EEnum) type).getEEnumLiteral(value.text()).getInstance();
} else if (type instanceof EDataType) {
final EDataType dt = (EDataType) type;
final Class<?> c = dt.getInstanceClass();
if (c == int.class || c == Integer.class) {
return new Integer(LiteralUtils.parseInt(value.text()));
} else if (c == String.class) {
return value.text();
} else {
return dt.getEPackage().getEFactoryInstance().createFromString(dt, value.text());
}
} else {
throw new ParserException("Unsupported type for value: " + type);
}
}Example 35
| Project: eu.geclipse.core-master File: ResourcesTypeAdapter.java View source code |
// end EObject checkProxy()
/**
* The attach point that handles the {@link Combo} widget which is responsible for the
* Resources <b>OperatingSystem</b> element. This attach point provides a {@link SelectionListener}
* that listens to changes in the text box and commits this changes to the underlying
* model.
*
* @param widget The Text widget responsible for Resources Operating System element.
*/
public void attachToOSType(final Combo widget) {
Integer featureID = Integer.valueOf(JsdlPackage.RESOURCES_TYPE__OPERATING_SYSTEM);
this.comboFeaturesMap.put(featureID, widget);
/* Populate the Combo Box with the CPU Architecture Literals */
EEnum cFEnum = JsdlPackage.Literals.OPERATING_SYSTEM_TYPE_ENUMERATION;
// Adding Empty String to allow disabling O/S Type.
widget.add(EMPTY_STRING);
for (int i = 0; i < cFEnum.getELiterals().size(); i++) {
widget.add(cFEnum.getEEnumLiteral(i).toString());
}
String[] sortedTypes = widget.getItems();
Arrays.sort(sortedTypes);
widget.setItems(sortedTypes);
widget.addSelectionListener(new SelectionListener() {
public void widgetSelected(final SelectionEvent e) {
String selectedOSName = widget.getItem(widget.getSelectionIndex());
if (selectedOSName == EMPTY_STRING) {
deleteElement(ResourcesTypeAdapter.this.operatingSystemType);
ResourcesTypeAdapter.this.operatingSystemType = null;
} else {
checkOSElement();
ResourcesTypeAdapter.this.operatingSystemTypeType.setOperatingSystemName(OperatingSystemTypeEnumeration.get(selectedOSName));
ResourcesTypeAdapter.this.operatingSystemType.setOperatingSystemType(ResourcesTypeAdapter.this.operatingSystemTypeType);
}
ResourcesTypeAdapter.this.contentChanged();
}
public void widgetDefaultSelected(final SelectionEvent e) {
//Do Nothing
}
});
}Example 36
| Project: gremf-master File: GrEMFSchemaTransformer.java View source code |
/**
* Resolves the grEMF types of the contained EMF types of the given
* resource. Therefore, all contained elements are visited and added to the
* corresponding sets. Additionally, the transformation order of the vertex
* and edge classes is built. <br>
* Note that not all resolved edge classes necessarily are transformed to
* such type. Some may become vertex classes.
*
* @param resource
* input <code>Resource</code> whose content is resolved
*/
private void resolveResourceContent(Resource resource) {
TreeIterator<EObject> i = resource.getAllContents();
while (i.hasNext()) {
EObject eObj = i.next();
if (eObj instanceof EPackage) {
// implicitly created via EClass and EEnum
this.packages.add((EPackage) eObj);
} else if (eObj instanceof EClass) {
if (isVertexClassCertainly((EClass) eObj)) {
this.vertexClasses.add((EClass) eObj);
} else {
this.edgeClasses.add((EClass) eObj);
}
} else if (eObj instanceof EEnum) {
this.enumDomains.add((EEnum) eObj);
} else if (eObj instanceof EAttribute) {
EAttribute eAttr = (EAttribute) eObj;
if (FeatureMapUtil.isFeatureMap(eAttr)) {
this.resolveFeatureMap(new BasicFeatureMap((InternalEObject) eAttr.getEContainingClass(), eAttr.getFeatureID()));
} else {
this.attributes.add(eAttr);
}
} else if (eObj instanceof EReference) {
if (!this.incidenceClasses.contains(((EReference) eObj).getEOpposite())) {
this.incidenceClasses.add((EReference) eObj);
}
} else if (eObj instanceof EAnnotation) {
// nothing to do; done via the annotated element
}
}
}Example 37
| Project: js4emf-master File: JavascriptDelegatesTest.java View source code |
//
// Test framework
//
protected void setUp() throws Exception {
setUp("ecoreJavascriptDelegatesTest.xmi");
String registryId = JavascriptSupport.SCRIPTING_SOURCE_URI;
JavascriptDelegateFactory javascriptDelegateFactory = new JavascriptDelegateFactory();
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(registryId, javascriptDelegateFactory);
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(registryId, javascriptDelegateFactory);
EValidator.ValidationDelegate.Registry.INSTANCE.put(registryId, new JavascriptValidationDelegate());
acme = resource.getContents().get(0);
EClass companyClass = acme.eClass();
companyPackage = companyClass.getEPackage();
companyFactory = companyPackage.getEFactoryInstance();
companyName = (EAttribute) companyClass.getEStructuralFeature("name");
companyEmployees = (EReference) companyClass.getEStructuralFeature("employees");
companySize = (EAttribute) companyClass.getEStructuralFeature("size");
employeeClass = companyEmployees.getEReferenceType();
employeeName = (EAttribute) employeeClass.getEStructuralFeature("name");
employeeManager = (EReference) employeeClass.getEStructuralFeature("manager");
employeeDirectReports = (EReference) employeeClass.getEStructuralFeature("directReports");
employeeAllReports = (EReference) employeeClass.getEStructuralFeature("allReports");
employeeReportsTo = employeeClass.getEOperations().get(0);
EEnum sizeKind = (EEnum) companySize.getEAttributeType();
sizeSmall = sizeKind.getEEnumLiteral("small");
sizeMedium = sizeKind.getEEnumLiteral("medium");
sizeLarge = sizeKind.getEEnumLiteral("large");
employees = new java.util.HashMap<String, EObject>();
}Example 38
| Project: molic-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteralMessage, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, String.class.getName()));
}
}
}
return value;
}Example 39
| Project: mylyn.docs.intent.main-master File: ModelingUnitCompletionProcessor.java View source code |
/**
* Computes the {@link ICompletionProposal}s to provide for a Structural Feature value instruction.
*
* @param isResourceContribution
* indicates if we are in the scope of a resource contribution or not
* @param featureName
* the feature name
* @param beginning
* the beginning of the instruction on which completion is called
* @param featureToConsider
* the {@link EStructuralFeature} to consider
* @throws ReadOnlyException
* if permission issue occur while querying document
* @return the {@link ICompletionProposal}s to provide for a Structural feature value instruction
*/
private Collection<ICompletionProposal> doGetProposalsForStructuralFeatureValue(boolean isResourceContribution, String featureName, String beginning, EStructuralFeature featureToConsider) throws ReadOnlyException {
Collection<ICompletionProposal> proposals = Sets.newLinkedHashSet();
// attribute type
if (featureToConsider instanceof EAttribute) {
String defaultAttributeValue = "";
if (featureToConsider.getEType().getDefaultValue() != null) {
defaultAttributeValue = "Default: " + featureToConsider.getDefaultValue().toString();
}
if (featureToConsider.getEType() instanceof EEnum) {
for (EEnumLiteral literal : ((EEnum) featureToConsider.getEType()).getELiterals()) {
proposals.add(createTemplateProposal("'" + literal.getName() + "' value (of type " + featureToConsider.getEType().getName() + RIGHT_PAR, defaultAttributeValue + " - Set a simple value of type " + featureToConsider.getEType().getName(), '"' + literal.getName() + "\";", "icon/outline/modelingunit_value.gif"));
}
} else {
proposals.add(createTemplateProposal("value (of type " + featureToConsider.getEType().getName() + RIGHT_PAR, defaultAttributeValue + " - Set a simple value of type " + featureToConsider.getEType().getName(), '"' + defaultAttributeValue + "\";", "icon/outline/modelingunit_value.gif"));
}
} else {
// Propose to create a new Element of the feature type
if (!isResourceContribution) {
proposals.add(createTemplateProposal("new Element (of type " + featureToConsider.getEType().getName() + RIGHT_PAR, "Set this new Element as value for " + featureToConsider.getName(), "new " + getQualifiedName(featureToConsider.getEType().getEPackage()) + DOT + featureToConsider.getEType().getName() + "{\n\t${}\n};", MODELINGUNIT_NEW_ELEMENT_ICON));
}
// Propose to reference an already defined element
for (InstanciationInstruction instruction : traceabilityInfoQuery.getInstanciations()) {
// Instruction's name should match the beginning
boolean isMatchingInstruction = false;
boolean hasMatchingName = instruction.getName() != null && (beginning.length() == 0 || instruction.getName().startsWith(beginning));
if (hasMatchingName && !isResourceContribution) {
// Instruction's type should match the featureToConsider type
isMatchingInstruction = instruction.getMetaType() != null && (featureToConsider.getEType().equals(instruction.getMetaType().getResolvedType()) || featureToConsider.getEType() instanceof EClass && ((EClass) featureToConsider.getEType()).isSuperTypeOf(instruction.getMetaType().getResolvedType()));
} else if (hasMatchingName) {
// Resource content has not type so all instructions should be displayed
isMatchingInstruction = true;
}
if (isMatchingInstruction) {
proposals.add(createTemplateProposal("Reference to " + instruction.getName(), "Set the " + instruction.getName() + " element as value for " + featureName, instruction.getName(), "icon/outline/modelingunit_ref.png"));
}
}
// If the expected eType is an EClassifier, also propose all available classifiers
if (!isResourceContribution && featureToConsider.getEType().equals(EcorePackage.eINSTANCE.getEClassifier())) {
proposals.addAll(getProposalsForEClassifier(beginning));
}
}
return proposals;
}Example 40
| Project: Neo4EMF-master File: Neo4emfResourceUtil.java View source code |
@SuppressWarnings("unchecked")
private static void setupAttributes(EObject eObject, Node n) {
// TODO Auto-generated method stub
EList<EAttribute> atrList = eObject.eClass().getEAllAttributes();
java.util.Iterator<EAttribute> it = atrList.iterator();
while (it.hasNext()) {
EAttribute at = it.next();
if (eObject.eGet(at) != null && !at.isMany()) {
if (at.getEType() instanceof EEnum)
n.setProperty(at.getName(), eObject.eGet(at).toString());
else if (isPrimitive(at.getName()))
n.setProperty(at.getName(), eObject.eGet(at));
else
n.setProperty(at.getName(), eObject.eGet(at).toString());
} else if (eObject.eGet(at) != null && at.isMany()) {
n.setProperty(at.getName(), ((EList<EDataType>) eObject.eGet(at)).toArray());
} else if (!at.isMany()) {
if (at.getEType().getInstanceClass().isAssignableFrom(Boolean.class))
n.setProperty(at.getName(), false);
else if (at.getEType().getInstanceClass().isAssignableFrom(String.class))
n.setProperty(at.getName(), "");
else if (at.getEType().getInstanceClass().isAssignableFrom(Integer.class))
n.setProperty(at.getName(), 0);
else
n.setProperty(at.getName(), 0);
} else {
n.setProperty(at.getName(), new Object[1]);
}
}
}Example 41
| Project: TOGAF-Designer-master File: SmartEAItemPropertyDescriptor.java View source code |
protected Collection<?> getComboBoxObjects(Object object) {
if (object instanceof EObject) {
if (parentReferences != null) {
Collection<Object> result = new UniqueEList<Object>();
for (int i = 0; i < parentReferences.length; ++i) {
result.addAll(getReachableObjectsOfType((EObject) object, parentReferences[i].getEType()));
}
return result;
} else if (feature != null) {
if (feature instanceof EReference) {
Collection<EObject> result = getReachableObjectsOfType((EObject) object, feature.getEType());
if (!feature.isMany() && !result.contains(null)) {
result.add(null);
}
return result;
} else if (feature.getEType() instanceof EEnum) {
EEnum eEnum = (EEnum) feature.getEType();
List<Enumerator> enumerators = new ArrayList<Enumerator>();
for (EEnumLiteral eEnumLiteral : eEnum.getELiterals()) {
enumerators.add(eEnumLiteral.getInstance());
}
return enumerators;
} else {
EDataType eDataType = (EDataType) feature.getEType();
List<String> enumeration = ExtendedMetaData.INSTANCE.getEnumerationFacet(eDataType);
if (!enumeration.isEmpty()) {
List<Object> enumerators = new ArrayList<Object>();
for (String enumerator : enumeration) {
enumerators.add(EcoreUtil.createFromString(eDataType, enumerator));
}
return enumerators;
} else {
for (EDataType baseType = ExtendedMetaData.INSTANCE.getBaseType(eDataType); baseType != null; baseType = ExtendedMetaData.INSTANCE.getBaseType(baseType)) {
if (baseType instanceof EEnum) {
EEnum eEnum = (EEnum) baseType;
List<Enumerator> enumerators = new ArrayList<Enumerator>();
enumerators.add(null);
for (EEnumLiteral eEnumLiteral : eEnum.getELiterals()) {
enumerators.add(eEnumLiteral.getInstance());
}
return enumerators;
}
}
}
}
}
}
return null;
}Example 42
| Project: vespucci-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 43
| Project: wazaabi-master File: StyleRulesHelper.java View source code |
/**
* Builds a default EObject by iterating over the annotation 'default'
* content. When found, attributes are set using conversion mechanisms. All
* the attribute are not supposed to be set.
*
* @param annotation
* A non null EAnnotation whose 'name' is not null.
* @param eClass
* The EClass of the EObject to create
* @return An EObject if the build mechanisms succeded.
*/
protected static StyleRule buildDefault(EAnnotation annotation, EClass eClass) {
EObject result = null;
//$NON-NLS-1$
final String content = annotation.getDetails().get("default");
if (//$NON-NLS-1$
content == null || "".equals(content))
return null;
try {
Properties defaultValues = new Properties();
defaultValues.load(new ByteArrayInputStream(content.getBytes("UTF-8")));
result = EcoreUtil.create(eClass);
@SuppressWarnings("rawtypes") Iterator iterator = defaultValues.entrySet().iterator();
while (iterator.hasNext()) {
@SuppressWarnings("unchecked") Entry<String, String> entry = (Entry<String, String>) iterator.next();
EAttribute attr = getEAttribute(eClass, entry.getKey());
if (attr != null) {
EDataType attrType = attr.getEAttributeType();
if (attrType instanceof EEnum) {
EEnumLiteral eEnumLiteral = ((EEnum) attrType).getEEnumLiteral(entry.getValue());
if (eEnumLiteral != null)
result.eSet(attr, eEnumLiteral.getInstance());
} else
switch(attrType.getClassifierID()) {
case EcorePackage.EBOOLEAN:
result.eSet(attr, Boolean.parseBoolean(entry.getValue()));
break;
// TODO : continue to implement conversion mechanisms
default:
throw new RuntimeException(//$NON-NLS-1$
"No conversion mechanism for " + (((EClass) annotation.getEModelElement()).getName()) + //$NON-NLS-1$
"." + annotation.getDetails().get(//$NON-NLS-1$
"name") + //$NON-NLS-1$
".default");
}
} else
throw new RuntimeException("Unable to find an attribute for " + (((EClass) annotation.getEModelElement()).getName()) + "." + //$NON-NLS-1$
annotation.getDetails().get("name"));
}
} catch (IOException e) {
throw new RuntimeException("Unable to read default for " + (((EClass) annotation.getEModelElement()).getName()) + "." + annotation.getDetails().get("name"));
}
return (StyleRule) result;
}Example 44
| Project: bpmn2-modeler-master File: ModelDecorator.java View source code |
/** * Create a dynamic EClassifier from a type string. This will create a new * EEnum if the supertype is an EEnum, or a new EDataType if the supertype * is an EDataType. If no supertype is given, an EClass is created instead. * * @param type - a type name string that may contain additional supertype names. * @see getType(String) * @return the EClassifier. */ public EClassifier createEClassifier(String type) { EClassifier eClassifier = getEClassifier(type); if (eClassifier != null) return eClassifier; EClassifier eDataType = null; for (String st : getSuperTypes(type)) { EClassifier ec = findEClassifier(st); if (EDataType.class.isAssignableFrom(ec.getInstanceClass())) { eDataType = ec; break; } } if (eDataType == null) { if (EDataTypeConversionFactory.isFactoryFor(getType(type))) return createEDataType(type); return createEClass(type); } if (EEnum.class.isAssignableFrom(eDataType.getInstanceClass())) eClassifier = theCoreFactory.createEEnum(); else eClassifier = theCoreFactory.createEDataType(); eClassifier.setName(getType(type)); ePackage.getEClassifiers().add(eClassifier); return eClassifier; }
Example 45
| Project: CertWare-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 46
| Project: CIMTool-master File: EcoreGenerator.java View source code |
/*
* Adds packages and classifiers without parent packages to the 'result' package.
* Create an Element class from which all other classes derive.
*/
@Override
public void run() {
super.run();
EPackage result = null;
Collection<EPackage> roots = new HashSet<EPackage>();
for (EPackage p : index.ePackages.values()) {
if (p.getESuperPackage() == null && p.eContents().size() > 0) {
roots.add(p);
}
}
if (roots.size() == 1)
result = roots.iterator().next();
else {
result = EcoreFactory.eINSTANCE.createEPackage();
result.getESubpackages().addAll(roots);
}
index.root = result;
if (originalNamespace.endsWith("#")) {
EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
annotation.setSource(RDF_SERIALISATION_ANNOTATION);
annotation.getDetails().put("suffix", "#");
index.root.getEAnnotations().add(annotation);
}
if (!originalNamespace.equals(originalProfileNamespace)) {
EAnnotation pAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
pAnnotation.setSource(PROFILE_ANNOTATION);
pAnnotation.getDetails().put("nsURI", profileNamespace);
index.root.getEAnnotations().add(pAnnotation);
}
index.root.setNsPrefix("cim");
index.root.setNsURI(this.namespace);
Iterator<?> nt = datatypes.iterator();
while (nt.hasNext()) {
OntResource type = (OntResource) nt.next();
EDataType dt = index.eDataTypes.get(type.getURI());
if (dt != null && type.getIsDefinedBy() != null) {
EPackage p = index.ePackages.get(type.getIsDefinedBy().getURI());
if (p != null)
p.getEClassifiers().add(dt);
}
}
/* Create root Element class from which all other classes derive. */
EClass element = coreFactory.createEClass();
if (addRootClass) {
if (index.root.getEClassifier(ELEMENT_CLASS_NAME) != null && index.root.getEClassifier(ELEMENT_CLASS_NAME) instanceof EClass)
element = (EClass) index.root.getEClassifier(ELEMENT_CLASS_NAME);
else
element.setName(EcoreGenerator.ELEMENT_CLASS_NAME);
element.setAbstract(true);
EAttribute uri;
if (element.getEStructuralFeature(ELEMENT_CLASS_IDENTIFIER) == null || !(element.getEStructuralFeature(ELEMENT_CLASS_IDENTIFIER) instanceof EAttribute)) {
uri = coreFactory.createEAttribute();
uri.setName(EcoreGenerator.ELEMENT_CLASS_IDENTIFIER);
uri.setEType(corePackage.getEString());
element.getEStructuralFeatures().add(uri);
} else
uri = (EAttribute) element.getEStructuralFeature(ELEMENT_CLASS_IDENTIFIER);
uri.setID(true);
index.root.getEClassifiers().add(element);
}
for (Iterator<EClass> ix = index.eClasses.values().iterator(); ix.hasNext(); ) {
EClass klass = ix.next();
if (klass.getEPackage() == null)
index.root.getEClassifiers().add(klass);
/* Make all classes derive from Element. */
if (addRootClass && (klass.getESuperTypes().size() == 0) && klass != element && !isCompound(klass)) {
klass.getESuperTypes().add(element);
}
for (EReference ref : klass.getEReferences()) {
if (ref.getName() == null) {
String name = ref.getEType().getName();
if (ref.isMany())
name += "s";
log("Reference between " + klass.getName() + " and " + ref.getEType().getName() + " has no role name, setting to " + name);
ref.setName(name);
}
}
}
for (Iterator<EEnum> ix = index.eEnums.values().iterator(); ix.hasNext(); ) {
EEnum eEnum = ix.next();
if (eEnum.getEPackage() == null)
index.root.getEClassifiers().add(eEnum);
}
for (Iterator<EDataType> ix = index.eDataTypes.values().iterator(); ix.hasNext(); ) {
EDataType dt = ix.next();
if (dt.getEPackage() == null)
index.root.getEClassifiers().add(dt);
}
for (Iterator<EDataType> ix = index.eTypes.values().iterator(); ix.hasNext(); ) {
EDataType dt = ix.next();
if (dt.getEPackage() == null)
index.root.getEClassifiers().add(dt);
}
for (Iterator<EPackage> ix = index.ePackages.values().iterator(); ix.hasNext(); ) {
EPackage pkg = ix.next();
if (pkg.getESuperPackage() == null && pkg != index.root) {
index.root.getESubpackages().add(pkg);
}
}
if (!isEcoreSchema()) {
for (Iterator<EPackage> ix = index.ePackages.values().iterator(); ix.hasNext(); ) {
EPackage pkg = ix.next();
if (pkg.getESuperPackage() == index.root && index.root.getESubpackages().size() == 1 && pkg.getESubpackages().size() == 1) {
index.root.getESubpackages().addAll(pkg.getESubpackages());
index.root.getEClassifiers().addAll(pkg.getEClassifiers());
index.root.getEAnnotations().addAll(pkg.getEAnnotations());
if (index.root.getName() == null)
index.root.setName(pkg.getName());
index.root.getESubpackages().remove(pkg);
}
}
}
for (Iterator<EReference> ix = index.notInverted.iterator(); ix.hasNext(); ) {
EReference ref = ix.next();
if (!isCompound((EClass) ref.getEType()))
log("Non-inverted reference: " + ref.getName());
}
}Example 47
| Project: d-case_editor-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 48
| Project: eclipse-gov.redhawk.core-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 49
| Project: emf-compare-master File: AttributeChangeMerger.java View source code |
/**
* Returns the target value, that is, the value to be set when merging the given {@code diff} in the
* direction indicated by {@code rightToLeft}.
*
* @param diff
* The diff we are currently merging.
* @param rightToLeft
* Direction of the merge.
* @return The target value to be set when merging.
*/
private Object getTargetValue(AttributeChange diff, boolean rightToLeft) {
final EStructuralFeature attribute = diff.getAttribute();
final EObject targetContainer = getTargetContainer(diff, rightToLeft);
final EObject sourceContainer = getSourceContainer(diff, rightToLeft);
final Object sourceValue = safeEGet(sourceContainer, attribute);
final Object targetValue;
if (isEnumChangeOfDynamicEObject(diff, targetContainer)) {
final EEnum eEnum = getAttributeTypeEnumFromDynamicObject(targetContainer, attribute);
targetValue = eEnum.getEEnumLiteral(((ENamedElement) sourceValue).getName());
} else if (requireThreeWayTextMerge(diff)) {
targetValue = performThreeWayTextMerge(diff, rightToLeft);
} else {
targetValue = sourceValue;
}
return targetValue;
}Example 50
| Project: emf.compare-master File: AttributeChangeMerger.java View source code |
/**
* Returns the target value, that is, the value to be set when merging the given {@code diff} in the
* direction indicated by {@code rightToLeft}.
*
* @param diff
* The diff we are currently merging.
* @param rightToLeft
* Direction of the merge.
* @return The target value to be set when merging.
*/
private Object getTargetValue(AttributeChange diff, boolean rightToLeft) {
final EStructuralFeature attribute = diff.getAttribute();
final EObject targetContainer = getTargetContainer(diff, rightToLeft);
final EObject sourceContainer = getSourceContainer(diff, rightToLeft);
final Object sourceValue = safeEGet(sourceContainer, attribute);
final Object targetValue;
if (isEnumChangeOfDynamicEObject(diff, targetContainer)) {
final EEnum eEnum = getAttributeTypeEnumFromDynamicObject(targetContainer, attribute);
targetValue = eEnum.getEEnumLiteral(((ENamedElement) sourceValue).getName());
} else if (requireThreeWayTextMerge(diff)) {
targetValue = performThreeWayTextMerge(diff, rightToLeft);
} else {
targetValue = sourceValue;
}
return targetValue;
}Example 51
| Project: EPF-Composer-master File: DiagramAbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EStructuralFeature feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue("Value of type Boolean is expected");
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue("Value of type Character is expected");
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue("String value does not convert to Byte value");
}
}
} else {
value = new InvalidValue("Value of type Byte is expected");
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue("String value does not convert to Short value");
}
}
} else {
value = new InvalidValue("Value of type Short is expected");
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue("String value does not convert to Integer value");
}
}
} else {
value = new InvalidValue("Value of type Integer is expected");
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue("String value does not convert to Long value");
}
}
} else {
value = new InvalidValue("Value of type Long is expected");
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue("String value does not convert to Float value");
}
}
} else {
value = new InvalidValue("Value of type Float is expected");
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue("String value does not convert to Double value");
}
}
} else {
value = new InvalidValue("Value of type Double is expected");
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue("Unknown literal: " + value);
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue("Value of type String is expected");
}
}
}
return value;
}Example 52
| Project: gmf-runtime-master File: MetamodelManager.java View source code |
/**
* Register meta-model object.
*/
public static void register(ENamedElement element, ResourceLocator resourceLocator) {
if (element instanceof EOperation)
return;
if (element instanceof EParameter)
return;
String id = getNonCachedID(element);
String name = element.getName();
String displayName = null;
if ((resourceLocator == null) && (element instanceof EPackage)) {
// get a resource locator from the adapter factory registered
// against the IItemLabelProvider adapter type
resourceLocator = findResourceLocator((EPackage) element);
}
if (resourceLocator != null) {
if (element instanceof EClass) {
displayName = //$NON-NLS-1$
resourceLocator.getString("_UI_" + name + //$NON-NLS-1$
"_type");
} else if (element instanceof EStructuralFeature) {
EClass eClass = ((EStructuralFeature) element).getEContainingClass();
if (eClass != null)
displayName = //$NON-NLS-1$
resourceLocator.getString("_UI_" + eClass.getName() + "_" + name + //$NON-NLS-1$//$NON-NLS-2$
"_feature");
} else if (element instanceof EEnumLiteral) {
EEnum eEnum = ((EEnumLiteral) element).getEEnum();
if (eEnum != null)
displayName = //$NON-NLS-1$
resourceLocator.getString("_UI_" + eEnum.getName() + "_" + name + //$NON-NLS-1$//$NON-NLS-2$
"_literal");
}
}
if (displayName == null)
displayName = name;
METAMODEL_MAP.put(element, new MetaModelDescriptor(id, displayName));
REVERSE_METAMODEL_MAP.put(id, element);
for (Iterator i = element.eContents().iterator(); i.hasNext(); ) {
Object child = i.next();
if (child instanceof ENamedElement)
register((ENamedElement) child, resourceLocator);
}
}Example 53
| Project: hawk-drivers-master File: Express2EMF.java View source code |
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 54
| Project: org.roxgt-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversionMessage, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteralMessage, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueTypeMessage, String.class.getName()));
}
}
}
return value;
}Example 55
| Project: petals-studio-master File: InitializeModelExtensionCommand.java View source code |
/**
* Adapts a raw object so that its type is valid according to the model extension.
* @param entryValue
* @param targetFeature
* @return an adapted object (null if entryValue is null)
*/
private Object adaptValueType(Object entryValue, EStructuralFeature targetFeature) {
Object finalValue = entryValue;
if (entryValue instanceof String && targetFeature instanceof EAttribute) {
EDataType expectedType = ((EAttribute) targetFeature).getEAttributeType();
String instanceClassName = expectedType.getInstanceClassName().toLowerCase();
if (expectedType.equals(EcorePackage.Literals.EINT) || "int".equals(instanceClassName) || "java.lang.integer".equals(instanceClassName)) {
finalValue = Integer.valueOf((String) entryValue);
} else if (expectedType.equals(EcorePackage.Literals.ELONG) || "long".equals(instanceClassName) || "java.lang.long".equals(instanceClassName)) {
finalValue = Long.valueOf((String) entryValue);
} else if (instanceClassName.equals("javax.xml.namespace.qname")) {
// Extract the QName value...
String[] parts = ((String) entryValue).split(":");
String ns = null, name = null;
if (parts.length == 1) {
name = parts[0];
} else if (parts.length == 2) {
ns = parts[0];
name = parts[1];
} else {
PetalsServicesPlugin.log("Found invalid QName while intializing the model extensions.", IStatus.ERROR);
}
// ... and resolve it
QName newValue = null;
EMap<String, String> map = JbiXmlUtils.findPrefixMap(this.element);
if (map == null) {
PetalsServicesPlugin.log("Could not find the prefix map while intializing the model extensions.", IStatus.ERROR);
} else if (name != null) {
if (ns != null)
ns = map.get(ns);
newValue = ns != null ? new QName(ns, name) : new QName(name);
}
finalValue = newValue;
} else if (expectedType instanceof EEnum) {
EEnum eEnum = (EEnum) expectedType;
EEnumLiteral literal = eEnum.getEEnumLiteralByLiteral((String) entryValue);
finalValue = literal.getInstance();
} else if (expectedType.getInstanceClass().equals(boolean.class)) {
finalValue = Boolean.valueOf((String) entryValue);
}
}
return finalValue;
}Example 56
| Project: smooks-editor-master File: SmooksStuffPropertyDetailPage.java View source code |
protected AttributeFieldEditPart createAttributeUI(Composite detailsComposite, IItemPropertyDescriptor propertyDescriptor, IPropertyUICreator creator) {
final IItemPropertyDescriptor itemPropertyDescriptor = propertyDescriptor;
EAttribute feature = (EAttribute) itemPropertyDescriptor.getFeature(getModel());
AttributeFieldEditPart editPart = null;
boolean createDefault = true;
if (creator != null) {
if (creator.ignoreProperty(feature)) {
return null;
}
editPart = creator.createPropertyUI(formToolkit, detailsComposite, itemPropertyDescriptor, getModel(), feature, this.smooksModelProvider, editorPart);
if (editPart != null) {
createDefault = false;
}
}
if (createDefault) {
EClassifier typeClazz = feature.getEType();
boolean hasCreated = false;
if (typeClazz instanceof EEnum) {
editPart = createEnumFieldEditor(detailsComposite, feature, (EEnum) typeClazz, formToolkit, itemPropertyDescriptor);
hasCreated = true;
}
if (typeClazz.getInstanceClass() == String.class) {
editPart = createStringFieldEditor(detailsComposite, feature, formToolkit, itemPropertyDescriptor);
hasCreated = true;
}
if (typeClazz.getInstanceClass() == Boolean.class || typeClazz.getInstanceClass() == boolean.class) {
editPart = createBooleanFieldEditor(detailsComposite, feature, formToolkit, itemPropertyDescriptor);
hasCreated = true;
}
if (typeClazz.getInstanceClass() == Integer.class || typeClazz.getInstanceClass() == int.class) {
editPart = createIntegerFieldEditor(detailsComposite, feature, formToolkit, itemPropertyDescriptor);
hasCreated = true;
}
if (!hasCreated) {
// createStringFieldEditor(detailsComposite, feature,
// formToolkit,
// itemPropertyDescriptor);
}
}
return editPart;
}Example 57
| Project: teiid-designer-master File: EmfTestUtil.java View source code |
/**
* Builds a dummy model based on the library scenario, creating a resource set.
* DOES NOT REQUIRE THE PLUGIN ENVIRONMENT TO CREATE THE RESOURCE SET
* @param displayContents - if true, the model structure will be printed out to the console after it is built
* @return ResourceSet - the dummy resource set.
*/
public static EPackage generateMetamodel(boolean displayContents) {
//$NON-NLS-1$
final String nsURI = "http://www.metamatrix.com/metabase/3.1/metamodels/Library.xml";
//$NON-NLS-1$
final String nsPrefix = "Library";
// Create the package for the model
//$NON-NLS-1$
EPackage ePackage = createEPackage(null, "library", nsURI, nsPrefix);
EPackage.Registry.INSTANCE.put(nsURI, ePackage);
// Create necessary data types
//$NON-NLS-1$
EDataType myString = createEDataType(ePackage, "myString", java.lang.String.class);
//$NON-NLS-1$
EDataType myInt = createEDataType(ePackage, "myInt", java.lang.Integer.class);
// Create classifiers for the model
//$NON-NLS-1$
EClass book = createEClass(ePackage, "Book", false, false);
//$NON-NLS-1$
EClass library = createEClass(ePackage, "Library", false, false);
//$NON-NLS-1$
EClass writer = createEClass(ePackage, "Writer", false, false);
// Create enumeration for the model
//$NON-NLS-1$
EEnum bookCategory = createEEnum(ePackage, "BookCategory");
// Create enumeration literals for the model
//$NON-NLS-1$
addEnumLiteral(bookCategory, createEnumLiteral("MYSTERY"));
//$NON-NLS-1$
addEnumLiteral(bookCategory, createEnumLiteral("SCIENCE_FICTION"));
//$NON-NLS-1$
addEnumLiteral(bookCategory, createEnumLiteral("BIOGRAPHY"));
// Add the attributes to the book class
//$NON-NLS-1$
createEAttribute(book, "title", myString);
//$NON-NLS-1$
createEAttribute(book, "pages", myInt);
//$NON-NLS-1$
createEAttribute(book, "category", bookCategory);
// Add the attributes to the writer class
//$NON-NLS-1$
createEAttribute(writer, "name", myString);
// Add the attributes to the library class
//$NON-NLS-1$
createEAttribute(library, "name", myString);
// Create a two-way reference between books and writers in which
// a book has only one reference to a writer and a writer
// has zero or more references to books
//$NON-NLS-1$
EReference books = createEReference("books", book, 0, ETypedElement.UNBOUNDED_MULTIPLICITY, false);
//$NON-NLS-1$
EReference author = createEReference("author", writer, 1, 1, false);
author.setEOpposite(books);
books.setEOpposite(author);
book.getEReferences().add(author);
writer.getEReferences().add(books);
// Create a containment reference in which a library contains
// one or more books
//$NON-NLS-1$
EReference libBooks = createEReference("books", book, 1, ETypedElement.UNBOUNDED_MULTIPLICITY, true);
library.getEReferences().add(libBooks);
// Create a containment reference in which a library contains
// one or more writers
//$NON-NLS-1$
EReference writers = createEReference("writers", writer, 1, ETypedElement.UNBOUNDED_MULTIPLICITY, true);
library.getEReferences().add(writers);
return ePackage;
}Example 58
| Project: Xcore-master File: EcoreXcoreBuilder.java View source code |
XClassifier getXClassifier(final EClassifier eClassifier) {
final XClassifier xClassifier = eClassifier instanceof EClass ? getXClass((EClass) eClassifier) : eClassifier instanceof EEnum ? getXEnum((EEnum) eClassifier) : getXDataType((EDataType) eClassifier);
handleAnnotations(eClassifier, xClassifier);
xClassifier.setName(eClassifier.getName());
String instanceTypeName = eClassifier.getInstanceTypeName();
if (instanceTypeName != null) {
final String finalInstanceTypeName = instanceTypeName;
runnables.add(new Runnable() {
public void run() {
Diagnostic diagnostic = EcoreValidator.EGenericTypeBuilder.INSTANCE.parseInstanceTypeName(finalInstanceTypeName);
xClassifier.setInstanceType(jvmInferrer.getJvmTypeReference((EGenericType) diagnostic.getData().get(0), eClassifier));
}
});
}
for (ETypeParameter eTypeParameter : eClassifier.getETypeParameters()) {
XTypeParameter xTypeParameter = getXTypeParameter(eTypeParameter);
xClassifier.getTypeParameters().add(xTypeParameter);
}
return xClassifier;
}Example 59
| Project: gmp.graphiti-master File: AbstractGFTests.java View source code |
protected void addEnumToDiagram(IFeatureProvider fp, Diagram diagram, int x, int y, String enumName) {
// create add context
AreaContext areaContext = new AreaContext();
areaContext.setLocation(x, y);
EEnum newEEnum = createEEnum(diagram, enumName);
AddContext addContext = new AddContext(areaContext, newEEnum);
addContext.setTargetContainer(diagram);
// get add class feature
IAddFeature addFeature = fp.getAddFeature(addContext);
assertNotNull("add class feature not available", addFeature);
if (addFeature.canAdd(addContext)) {
addFeature.execute(addContext);
}
}Example 60
| Project: Henshin-Editor-master File: AttributeImpl.java View source code |
/**
* Try to cast a string value into a constant.
* @param value String value.
* @param type Attribute type.
* @return The constant or <code>null</code>.
*/
private static Object getConstant(String value, EAttribute type) {
// Enum?
if (type.getEType() instanceof EEnum) {
try {
return ((EEnum) type.getEType()).getEEnumLiteral(value);
} catch (Throwable t) {
}
}
// Special treatment for strings:
if (type.getEType().getInstanceClass() == String.class) {
String v = value.trim();
if (// double quotes
v.startsWith("\"") && v.endsWith("\"")) {
v = v.substring(1, v.length() - 1);
if (v.indexOf("\"") < 0) {
return v;
}
}
if (// single quotes
v.startsWith("'") && v.endsWith("'")) {
v = v.substring(1, v.length() - 1);
if (v.indexOf("'") < 0) {
return v;
}
}
return null;
}
// Last chance: try to load it using the factory:
try {
EFactory factory = type.getEType().getEPackage().getEFactoryInstance();
return factory.createFromString(type.getEAttributeType(), value);
} catch (Throwable t) {
}
// Seems not to be a constant:
return null;
}Example 61
| Project: Socio-technical-Security-Requirements-master File: AbstractParser.java View source code |
/**
* @generated
*/
protected Object getValidNewValue(EAttribute feature, Object value) {
EClassifier type = feature.getEType();
if (type instanceof EDataType) {
Class iClass = type.getInstanceClass();
if (Boolean.TYPE.equals(iClass)) {
if (value instanceof Boolean) {
// ok
} else if (value instanceof String) {
value = Boolean.valueOf((String) value);
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
value = new Character(s.charAt(0));
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Byte.TYPE.equals(iClass)) {
if (value instanceof Byte) {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Byte.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Short.TYPE.equals(iClass)) {
if (value instanceof Short) {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Short.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Integer.TYPE.equals(iClass)) {
if (value instanceof Integer) {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Integer.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Long.TYPE.equals(iClass)) {
if (value instanceof Long) {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Long.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Float.TYPE.equals(iClass)) {
if (value instanceof Float) {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Float.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (Double.TYPE.equals(iClass)) {
if (value instanceof Double) {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
} else if (value instanceof String) {
String s = (String) value;
if (s.length() == 0) {
value = null;
} else {
try {
value = Double.valueOf(s);
} catch (NumberFormatException nfe) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
}
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
}
} else if (type instanceof EEnum) {
if (value instanceof String) {
EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
if (literal == null) {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
} else {
value = literal.getInstance();
}
} else {
value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
}
}
}
return value;
}Example 62
| Project: sad-analyzer-master File: UimaTypeSystem2Ecore.java View source code |
private static EClassifier uimaType2EClassifier(TypeDescription aType, Map aOptions) {
// separate name into package name and class name
String fullTypeName = aType.getName();
String uimaNamespace, shortTypeName;
int lastDot = fullTypeName.lastIndexOf('.');
if (lastDot <= 0) {
uimaNamespace = null;
shortTypeName = fullTypeName;
} else {
uimaNamespace = fullTypeName.substring(0, lastDot);
shortTypeName = fullTypeName.substring(lastDot + 1);
}
// does EPackage already exist for this URI?
EPackage ePackage = uimaNamespace2EPackage(uimaNamespace);
EClassifier eclassifier;
// if aType is a "subtype" of uima.cas.String, create an EEnum for it
if (CAS.TYPE_NAME_STRING.equals(aType.getSupertypeName())) {
eclassifier = EcoreFactory.eINSTANCE.createEEnum();
AllowedValue[] vals = aType.getAllowedValues();
for (int i = 0; i < vals.length; i++) {
EEnumLiteral literal = EcoreFactory.eINSTANCE.createEEnumLiteral();
literal.setValue(i);
literal.setName(vals[i].getString());
if (vals[i].getDescription() != null && vals[i].getDescription().length() > 0) {
EAnnotation eannot = EcoreFactory.eINSTANCE.createEAnnotation();
eannot.setSource("http://uima.apache.org");
eannot.getDetails().put("description", vals[i].getDescription());
literal.getEAnnotations().add(eannot);
}
((EEnum) eclassifier).getELiterals().add(literal);
}
} else {
// create EClass
eclassifier = EcoreFactory.eINSTANCE.createEClass();
}
// set name of EClassifier
eclassifier.setName(shortTypeName);
// add to package
ePackage.getEClassifiers().add(eclassifier);
// set description as EAnnotation
if (aType.getDescription() != null && aType.getDescription().length() > 0) {
EAnnotation eannot = EcoreFactory.eINSTANCE.createEAnnotation();
eannot.setSource("http://uima.apache.org");
eannot.getDetails().put("description", aType.getDescription());
eclassifier.getEAnnotations().add(eannot);
}
return eclassifier;
}Example 63
| Project: uima_prolog-master File: UimaTypeSystem2Ecore.java View source code |
private static EClassifier uimaType2EClassifier(TypeDescription aType, Map aOptions) {
// separate name into package name and class name
String fullTypeName = aType.getName();
String uimaNamespace, shortTypeName;
int lastDot = fullTypeName.lastIndexOf('.');
if (lastDot <= 0) {
uimaNamespace = null;
shortTypeName = fullTypeName;
} else {
uimaNamespace = fullTypeName.substring(0, lastDot);
shortTypeName = fullTypeName.substring(lastDot + 1);
}
// does EPackage already exist for this URI?
EPackage ePackage = uimaNamespace2EPackage(uimaNamespace);
EClassifier eclassifier;
// if aType is a "subtype" of uima.cas.String, create an EEnum for it
if (CAS.TYPE_NAME_STRING.equals(aType.getSupertypeName())) {
eclassifier = EcoreFactory.eINSTANCE.createEEnum();
AllowedValue[] vals = aType.getAllowedValues();
for (int i = 0; i < vals.length; i++) {
EEnumLiteral literal = EcoreFactory.eINSTANCE.createEEnumLiteral();
literal.setValue(i);
literal.setName(vals[i].getString());
if (vals[i].getDescription() != null && vals[i].getDescription().length() > 0) {
EAnnotation eannot = EcoreFactory.eINSTANCE.createEAnnotation();
eannot.setSource("http://uima.apache.org");
eannot.getDetails().put("description", vals[i].getDescription());
literal.getEAnnotations().add(eannot);
}
((EEnum) eclassifier).getELiterals().add(literal);
}
} else {
// create EClass
eclassifier = EcoreFactory.eINSTANCE.createEClass();
}
// set name of EClassifier
eclassifier.setName(shortTypeName);
// add to package
ePackage.getEClassifiers().add(eclassifier);
// set description as EAnnotation
if (aType.getDescription() != null && aType.getDescription().length() > 0) {
EAnnotation eannot = EcoreFactory.eINSTANCE.createEAnnotation();
eannot.setSource("http://uima.apache.org");
eannot.getDetails().put("description", aType.getDescription());
eclassifier.getEAnnotations().add(eannot);
}
return eclassifier;
}Example 64
| Project: EmfStore-Test-master File: IntegrationTestHelper.java View source code |
/**
* This changes the given attribute on given ME. If attribute isMany then a new entry of attribute type will be
* added to a random position of its list. Also if attribute is an Enum, then a new value from this enumeration will
* be set for it. Note that new values are all selected randomly (except for strings).
*
* @param me model element
* @param attribute attribute to change
*/
@SuppressWarnings("unchecked")
public void changeAttribute(EObject me, EAttribute attribute) {
if (attribute.getEType().getInstanceClass().equals(String.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<String> eList = (EList<String>) object;
int position = getRandomPosition(eList.size());
eList.add(position, "new entry for" + attribute.getName());
} else {
String oldValue = (String) me.eGet(attribute);
String newValue = "changed-" + oldValue;
me.eSet(attribute, newValue);
}
} else if (attribute.getEType().getInstanceClass().equals(boolean.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<Boolean> eList = (EList<Boolean>) object;
int position = getRandomPosition(eList.size());
eList.add(position, getRandom().nextBoolean());
} else {
me.eSet(attribute, !((Boolean) me.eGet(attribute)));
}
} else if (attribute.getEType().getInstanceClass().equals(int.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<Integer> eList = (EList<Integer>) object;
int position = getRandomPosition(eList.size());
eList.add(position, getRandom().nextInt());
} else {
me.eSet(attribute, getRandom().nextInt());
}
} else if (attribute.getEType().getInstanceClass().equals(Date.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<Date> eList = (EList<Date>) object;
int position = getRandomPosition(eList.size());
eList.add(position, getRandomDate());
} else {
me.eSet(attribute, getRandomDate());
}
}
if (attribute.getEType() instanceof EEnum) {
EEnum en = (EEnum) attribute.getEType();
int numOfLiterals = en.getELiterals().size();
int index = getRandomPosition(numOfLiterals);
EEnumLiteral value = en.getELiterals().get(index);
me.eSet(attribute, value.getInstance());
}
}Example 65
| Project: JaMoPP-master File: JavaCodeCompletionHelper.java View source code |
public void run() {
if (feature instanceof EReference) {
EReference reference = (EReference) feature;
if (featureType instanceof EClass) {
if (reference.isContainment()) {
// the FOLLOW set should contain only non-containment references
assert false;
} else {
proposals.addAll(handleNCReference(expectedTerminal, container, reference, expectedTerminal.getPrefix(), expectedFeature.getTokenName()));
}
}
} else if (feature instanceof EAttribute) {
EAttribute attribute = (EAttribute) feature;
if (featureType instanceof EEnum) {
EEnum enumType = (EEnum) featureType;
proposals.addAll(handleEnumAttribute(expectedTerminal, expectedFeature, enumType, expectedTerminal.getPrefix(), container));
} else {
// handle EAttributes (derive default value depending on the type of the
// attribute, figure out token resolver, and call deResolve())
proposals.addAll(handleAttribute(expectedTerminal, expectedFeature, container, attribute, expectedTerminal.getPrefix()));
}
} else {
// there should be no other subclass of EStructuralFeature
assert false;
}
}Example 66
| Project: spray-master File: PropertySection.java View source code |
public StringConcatenation mainFile(final EAttribute eAttribute, final String className) {
StringConcatenation _builder = new StringConcatenation();
String _name = this.diagram.getName();
final String diagramName = _name;
_builder.newLineIfNotEmpty();
EClass _eContainingClass = eAttribute.getEContainingClass();
final EClass eClass = _eContainingClass;
_builder.newLineIfNotEmpty();
String _name_1 = eAttribute.getName();
final String propertyName = _name_1;
_builder.append(" ");
_builder.newLineIfNotEmpty();
EDataType _eAttributeType = eAttribute.getEAttributeType();
final boolean isEnum = (_eAttributeType instanceof EEnum);
_builder.newLineIfNotEmpty();
EDataType _eAttributeType_1 = eAttribute.getEAttributeType();
String _name_2 = _eAttributeType_1.getName();
boolean _operator_equals = ObjectExtensions.operator_equals(_name_2, "EBoolean");
final boolean isBoolean = _operator_equals;
_builder.newLineIfNotEmpty();
StringConcatenation _header = this.header(this);
_builder.append(_header, "");
_builder.newLineIfNotEmpty();
_builder.append("package ");
String _property_package = GeneratorUtil.property_package();
_builder.append(_property_package, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import org.eclipse.emf.transaction.RecordingCommand;");
_builder.newLine();
_builder.append("import org.eclipse.emf.transaction.TransactionalEditingDomain;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.pictograms.PictogramElement;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.services.Graphiti;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.ui.platform.GFPropertySection;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;");
_builder.newLine();
_builder.append("import org.eclipse.jface.action.IStatusLineManager;");
_builder.newLine();
_builder.append("import org.eclipse.swt.SWT;");
_builder.newLine();
_builder.append("import org.eclipse.swt.custom.CLabel;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.FocusEvent;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.FocusListener;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.ModifyEvent;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.ModifyListener;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.SelectionAdapter;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.SelectionEvent;");
_builder.newLine();
_builder.append("import org.eclipse.swt.events.SelectionListener;");
_builder.newLine();
_builder.append("import org.eclipse.swt.layout.FormAttachment;");
_builder.newLine();
_builder.append("import org.eclipse.swt.layout.FormData;");
_builder.newLine();
_builder.append("import org.eclipse.swt.widgets.Composite;");
_builder.newLine();
_builder.append("import org.eclipse.swt.widgets.Text;");
_builder.newLine();
_builder.append("import org.eclipse.swt.custom.CCombo;");
_builder.newLine();
_builder.append("import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;");
_builder.newLine();
_builder.append("import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;");
_builder.newLine();
_builder.append("import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;");
_builder.newLine();
_builder.append("import java.util.List;");
_builder.newLine();
_builder.append("import ");
String _javaInterfaceName = this.naming.getJavaInterfaceName(eClass);
_builder.append(_javaInterfaceName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
{
if (isEnum) {
_builder.append("import ");
EDataType _eAttributeType_2 = eAttribute.getEAttributeType();
String _fullPackageName = MetaModel.fullPackageName(_eAttributeType_2);
_builder.append(_fullPackageName, "");
_builder.append(".");
EDataType _eAttributeType_3 = eAttribute.getEAttributeType();
String _name_3 = _eAttributeType_3.getName();
_builder.append(_name_3, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("// MARKER_IMPORT");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
_builder.append(className, "");
_builder.append(" extends GFPropertySection implements ITabbedPropertyConstants {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("protected ");
String _name_4 = eClass.getName();
_builder.append(_name_4, " ");
_builder.append(" bc = null;");
_builder.newLineIfNotEmpty();
{
boolean _operator_or = false;
if (isEnum) {
_operator_or = true;
} else {
_operator_or = BooleanExtensions.operator_or(isEnum, isBoolean);
}
if (_operator_or) {
_builder.append(" ");
_builder.append("protected CCombo ");
_builder.append(propertyName, " ");
_builder.append("Widget;");
_builder.newLineIfNotEmpty();
} else {
_builder.append(" ");
_builder.append("protected Text ");
_builder.append(propertyName, " ");
_builder.append("Widget;");
_builder.newLineIfNotEmpty();
}
}
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {");
_builder.newLine();
_builder.append(" ");
_builder.append("super.createControls(parent, tabbedPropertySheetPage);");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("TabbedPropertySheetWidgetFactory factory = getWidgetFactory();");
_builder.newLine();
_builder.append(" ");
_builder.append("Composite composite = factory.createFlatFormComposite(parent);");
_builder.newLine();
_builder.append(" ");
_builder.append("FormData data;");
_builder.newLine();
_builder.newLine();
{
boolean _operator_or_1 = false;
if (isEnum) {
_operator_or_1 = true;
} else {
_operator_or_1 = BooleanExtensions.operator_or(isEnum, isBoolean);
}
if (_operator_or_1) {
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget = factory.createCCombo(composite);");
_builder.newLineIfNotEmpty();
} else {
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget = factory.createText(composite, \"\");");
_builder.newLineIfNotEmpty();
}
}
_builder.append(" ");
_builder.append("data = new FormData();");
_builder.newLine();
_builder.append(" ");
_builder.append("data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);");
_builder.newLine();
_builder.append(" ");
_builder.append("data.right = new FormAttachment(100, 0);");
_builder.newLine();
_builder.append(" ");
_builder.append("data.top = new FormAttachment(0, VSPACE);");
_builder.newLine();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.setLayoutData(data);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("CLabel valueLabel = factory.createCLabel(composite, \"");
String _firstUpper = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper, " ");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("data = new FormData();");
_builder.newLine();
_builder.append(" ");
_builder.append("data.left = new FormAttachment(0, 0);");
_builder.newLine();
_builder.append(" ");
_builder.append("data.right = new FormAttachment(");
_builder.append(propertyName, " ");
_builder.append("Widget, -HSPACE);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("data.top = new FormAttachment(");
_builder.append(propertyName, " ");
_builder.append("Widget, 0, SWT.CENTER);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("valueLabel.setLayoutData(data);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
{
boolean _operator_or_2 = false;
if (isEnum) {
_operator_or_2 = true;
} else {
_operator_or_2 = BooleanExtensions.operator_or(isEnum, isBoolean);
}
boolean _operator_not = BooleanExtensions.operator_not(_operator_or_2);
if (_operator_not) {
_builder.append("@Override");
_builder.newLine();
_builder.append("public void refresh() {");
_builder.newLine();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.removeModifyListener(nameListener);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("PictogramElement pe = getSelectedPictogramElement();");
_builder.newLine();
_builder.append(" ");
_builder.append("if (pe != null) {");
_builder.newLine();
_builder.append(" ");
_builder.append("Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);");
_builder.newLine();
_builder.append(" ");
_builder.append("// the filter assured, that it is a ");
String _name_5 = eClass.getName();
_builder.append(_name_5, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("if (bo == null)");
_builder.newLine();
_builder.append(" ");
_builder.append("return;");
_builder.newLine();
_builder.append(" ");
_builder.append("bc = (");
String _name_6 = eClass.getName();
_builder.append(_name_6, " ");
_builder.append(")bo;");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("String value = \"\";");
_builder.newLine();
{
EDataType _eAttributeType_4 = eAttribute.getEAttributeType();
String _name_7 = _eAttributeType_4.getName();
boolean _operator_equals_1 = ObjectExtensions.operator_equals(_name_7, "EString");
if (_operator_equals_1) {
_builder.append("value = bc.get");
String _firstUpper_1 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_1, "");
_builder.append("();");
_builder.newLineIfNotEmpty();
} else {
EDataType _eAttributeType_5 = eAttribute.getEAttributeType();
String _name_8 = _eAttributeType_5.getName();
boolean _operator_equals_2 = ObjectExtensions.operator_equals(_name_8, "EInt");
if (_operator_equals_2) {
_builder.append("value = Integer.toString( bc.get");
String _firstUpper_2 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_2, "");
_builder.append("() );");
_builder.newLineIfNotEmpty();
} else {
_builder.append("value = \"unknown\";");
_builder.newLine();
}
}
}
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.setText(value == null ? \"\" : value);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.addModifyListener(nameListener);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("private ModifyListener nameListener = new ModifyListener() {");
_builder.newLine();
_builder.append(" ");
_builder.append("public void modifyText(ModifyEvent arg0) {");
_builder.newLine();
_builder.append(" ");
_builder.append("TransactionalEditingDomain editingDomain = getDiagramEditor().getEditingDomain();");
_builder.newLine();
_builder.append(" ");
_builder.append("editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {");
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("protected void doExecute() {");
_builder.newLine();
_builder.append(" ");
_builder.append("changePropertyValue();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("});");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("};");
_builder.newLine();
}
}
_builder.newLine();
{
boolean _operator_or_3 = false;
if (isEnum) {
_operator_or_3 = true;
} else {
_operator_or_3 = BooleanExtensions.operator_or(isEnum, isBoolean);
}
boolean _operator_not_1 = BooleanExtensions.operator_not(_operator_or_3);
if (_operator_not_1) {
_builder.append("protected void changePropertyValue(){");
_builder.newLine();
_builder.append(" ");
_builder.append("String newValue = ");
_builder.append(propertyName, " ");
_builder.append("Widget.getText();");
_builder.newLineIfNotEmpty();
{
boolean _operator_and = false;
boolean _isDerived = eAttribute.isDerived();
boolean _operator_not_2 = BooleanExtensions.operator_not(_isDerived);
if (!_operator_not_2) {
_operator_and = false;
} else {
boolean _isChangeable = eAttribute.isChangeable();
_operator_and = BooleanExtensions.operator_and(_operator_not_2, _isChangeable);
}
if (_operator_and) {
{
EDataType _eAttributeType_6 = eAttribute.getEAttributeType();
String _name_9 = _eAttributeType_6.getName();
boolean _operator_equals_3 = ObjectExtensions.operator_equals(_name_9, "EBoolean");
if (_operator_equals_3) {
_builder.append("String oldValue = ( bc.is");
String _firstUpper_3 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_3, "");
_builder.append("() ? \"true\" : \"false\" );");
_builder.newLineIfNotEmpty();
_builder.append("if( ! newValue.equals(oldValue) ) { ");
_builder.newLine();
_builder.append(" ");
_builder.append("bc.set");
String _firstUpper_4 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_4, " ");
_builder.append("(! bc.is");
String _firstUpper_5 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_5, " ");
_builder.append("() );");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
} else {
EDataType _eAttributeType_7 = eAttribute.getEAttributeType();
String _name_10 = _eAttributeType_7.getName();
boolean _operator_equals_4 = ObjectExtensions.operator_equals(_name_10, "EString");
if (_operator_equals_4) {
_builder.append("if( ! newValue.equals(bc.get");
String _firstUpper_6 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_6, "");
_builder.append("() ) ) { ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("bc.set");
String _firstUpper_7 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_7, " ");
_builder.append("(newValue);");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
} else {
EDataType _eAttributeType_8 = eAttribute.getEAttributeType();
String _name_11 = _eAttributeType_8.getName();
boolean _operator_equals_5 = ObjectExtensions.operator_equals(_name_11, "EInt");
if (_operator_equals_5) {
_builder.append("try {");
_builder.newLine();
_builder.append(" ");
_builder.append("int newIntValue = Integer.parseInt(newValue);");
_builder.newLine();
_builder.append(" ");
_builder.append("bc.set");
String _firstUpper_8 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_8, " ");
_builder.append("( newIntValue );");
_builder.newLineIfNotEmpty();
_builder.append("} catch(Exception e) {");
_builder.newLine();
_builder.append(" ");
_builder.append("IStatusLineManager mgr = GraphitiUiInternal.getWorkbenchService().getActiveStatusLineManager();");
_builder.newLine();
_builder.append(" ");
_builder.append("mgr.setErrorMessage(e.getMessage() + \" should be a number\");");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
}
}
}
}
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
{
boolean _operator_or_4 = false;
if (isEnum) {
_operator_or_4 = true;
} else {
_operator_or_4 = BooleanExtensions.operator_or(isEnum, isBoolean);
}
if (_operator_or_4) {
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("public void refresh() {");
_builder.newLine();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.removeSelectionListener(nameListener);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.setItems(getEnumerationFeatureValues());");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.setText(getFeatureAsText());");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(propertyName, " ");
_builder.append("Widget.addSelectionListener(nameListener);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.newLine();
_builder.append(" ");
_builder.append("* @return An Array of all the String representations of Multiplicity enumeration values");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append(" ");
_builder.append("protected String[] getEnumerationFeatureValues() {");
_builder.newLine();
{
if (isEnum) {
_builder.append(" ");
_builder.append("List<");
EDataType _eAttributeType_9 = eAttribute.getEAttributeType();
String _name_12 = _eAttributeType_9.getName();
_builder.append(_name_12, " ");
_builder.append("> values = ");
EDataType _eAttributeType_10 = eAttribute.getEAttributeType();
String _name_13 = _eAttributeType_10.getName();
_builder.append(_name_13, " ");
_builder.append(".VALUES;");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("String[] ret = new String[values.size()];");
_builder.newLine();
_builder.append(" ");
_builder.append("for (int i = 0; i < values.size(); i++) {");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
_builder.append("ret[i] = ((");
EDataType _eAttributeType_11 = eAttribute.getEAttributeType();
String _name_14 = _eAttributeType_11.getName();
_builder.append(_name_14, " ");
_builder.append(") values.get(i)).getName();");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
} else {
EDataType _eAttributeType_12 = eAttribute.getEAttributeType();
String _name_15 = _eAttributeType_12.getName();
boolean _operator_equals_6 = ObjectExtensions.operator_equals(_name_15, "EBoolean");
if (_operator_equals_6) {
_builder.append(" ");
_builder.append("String[] ret = new String[] {\"false\", \"true\"};");
_builder.newLine();
}
}
}
_builder.append(" ");
_builder.append("return ret;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("// value = ( bc.is");
String _firstUpper_9 = StringExtensions.toFirstUpper(propertyName);
_builder.append(_firstUpper_9, "");
_builder.append("() ? \"true\" : \"false\" );");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.newLine();
_builder.append(" ");
_builder.append("* @return The string representation of the current value of \'sourceMultiplicity\' of the selected Association");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append(" ");
_builder.append("protected String getFeatureAsText() {");
_builder.newLine();
_builder.append(" ");
_builder.append("PictogramElement pe = getSelectedPictogramElement();");
_builder.newLine();
_builder.append(" ");
_builder.append("if (pe != null) {");
_builder.newLine();
_builder.append(" ");
_builder.append("Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);");
_builder.newLine();
_builder.append(" ");
_builder.append("// the filter assured, that it is a ");
String _name_16 = eClass.getName();
_builder.append(_name_16, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("if (bo == null) {");
_builder.newLine();
_builder.append(" ");
_builder.append("return \"unknown \";");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("bc = (");
String _name_17 = eClass.getName();
_builder.append(_name_17, " ");
_builder.append(") bo;");
_builder.newLineIfNotEmpty();
{
if (isEnum) {
_builder.append(" ");
_builder.append("if( bc.get");
String _name_18 = eAttribute.getName();
String _firstUpper_10 = StringExtensions.toFirstUpper(_name_18);
_builder.append(_firstUpper_10, " ");
_builder.append("() == null ){");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("return \"Null value for ");
String _name_19 = eAttribute.getName();
_builder.append(_name_19, " ");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("return bc.get");
String _name_20 = eAttribute.getName();
String _firstUpper_11 = StringExtensions.toFirstUpper(_name_20);
_builder.append(_firstUpper_11, " ");
_builder.append("().getName();");
_builder.newLineIfNotEmpty();
} else {
if (isBoolean) {
_builder.append(" ");
_builder.append(" ");
String _xifexpression = null;
String _name_21 = eAttribute.getName();
boolean _startsWith = _name_21.startsWith("is");
if (_startsWith) {
String _name_22 = eAttribute.getName();
_xifexpression = _name_22;
} else {
String _name_23 = eAttribute.getName();
String _firstUpper_12 = StringExtensions.toFirstUpper(_name_23);
String _operator_plus = StringExtensions.operator_plus("is", _firstUpper_12);
_xifexpression = _operator_plus;
}
final String name = _xifexpression;
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("return ( bc.");
_builder.append(name, " ");
_builder.append("() ? \"true\" : \"false\" );");
_builder.newLineIfNotEmpty();
}
}
}
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("return \"unknown \";");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("private SelectionListener nameListener = new SelectionAdapter() {");
_builder.newLine();
_builder.append(" ");
_builder.append("public void widgetSelected(SelectionEvent event) {");
_builder.newLine();
_builder.append(" ");
_builder.append("TransactionalEditingDomain editingDomain = getDiagramEditor().getEditingDomain();");
_builder.newLine();
_builder.append(" ");
_builder.append("editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {");
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("protected void doExecute() {");
_builder.newLine();
_builder.append(" ");
_builder.append("changePropertyValue();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("});");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("};");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("protected void changePropertyValue(){");
_builder.newLine();
_builder.append(" ");
_builder.append("int index = ");
_builder.append(propertyName, " ");
_builder.append("Widget.getSelectionIndex();");
_builder.newLineIfNotEmpty();
{
boolean _operator_and_1 = false;
boolean _isDerived_1 = eAttribute.isDerived();
boolean _operator_not_3 = BooleanExtensions.operator_not(_isDerived_1);
if (!_operator_not_3) {
_operator_and_1 = false;
} else {
boolean _isChangeable_1 = eAttribute.isChangeable();
_operator_and_1 = BooleanExtensions.operator_and(_operator_not_3, _isChangeable_1);
}
if (_operator_and_1) {
{
if (isEnum) {
_builder.append(" ");
EDataType _eAttributeType_13 = eAttribute.getEAttributeType();
String _name_24 = _eAttributeType_13.getName();
_builder.append(_name_24, " ");
_builder.append(" value = ");
EDataType _eAttributeType_14 = eAttribute.getEAttributeType();
String _name_25 = _eAttributeType_14.getName();
_builder.append(_name_25, " ");
_builder.append(".VALUES.get(index);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("bc.set");
String _name_26 = eAttribute.getName();
String _firstUpper_13 = StringExtensions.toFirstUpper(_name_26);
_builder.append(_firstUpper_13, " ");
_builder.append("(value);");
_builder.newLineIfNotEmpty();
} else {
if (isBoolean) {
_builder.append(" ");
_builder.append(" ");
_builder.append("boolean newValue = (index == 0 ? false : true);");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
String _xifexpression_1 = null;
String _name_27 = eAttribute.getName();
boolean _startsWith_1 = _name_27.startsWith("is");
if (_startsWith_1) {
String _name_28 = eAttribute.getName();
_xifexpression_1 = _name_28;
} else {
String _name_29 = eAttribute.getName();
String _firstUpper_14 = StringExtensions.toFirstUpper(_name_29);
String _operator_plus_1 = StringExtensions.operator_plus("is", _firstUpper_14);
_xifexpression_1 = _operator_plus_1;
}
final String name_1 = _xifexpression_1;
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("if( newValue != bc.");
_builder.append(name_1, " ");
_builder.append("() ) { ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("bc.set");
String _name_30 = eAttribute.getName();
String _firstUpper_15 = StringExtensions.toFirstUpper(_name_30);
_builder.append(_firstUpper_15, " ");
_builder.append("(newValue );");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
}
}
}
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("} ");
return _builder;
}Example 67
| Project: EMF-Store-Extensible-Authorization-master File: IntegrationTestHelper.java View source code |
/**
* This changes the given attribute on given ME. If attribute isMany then a new entry of attribute type will be
* added to a random position of its list. Also if attribute is an Enum, then a new value from this enumeration will
* be set for it. Note that new values are all selected randomly (except for strings).
*
* @param me model element
* @param attribute attribute to change
*/
@SuppressWarnings("unchecked")
public void changeAttribute(EObject me, EAttribute attribute) {
if (attribute.getEType().getInstanceClass().equals(String.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<String> eList = (EList<String>) object;
int position = getRandomPosition(eList.size());
eList.add(position, "new entry for" + attribute.getName());
} else {
String oldValue = (String) me.eGet(attribute);
String newValue = "changed-" + oldValue;
me.eSet(attribute, newValue);
}
} else if (attribute.getEType().getInstanceClass().equals(boolean.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<Boolean> eList = (EList<Boolean>) object;
int position = getRandomPosition(eList.size());
eList.add(position, getRandom().nextBoolean());
} else {
me.eSet(attribute, !((Boolean) me.eGet(attribute)));
}
} else if (attribute.getEType().getInstanceClass().equals(int.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<Integer> eList = (EList<Integer>) object;
int position = getRandomPosition(eList.size());
eList.add(position, getRandom().nextInt());
} else {
me.eSet(attribute, getRandom().nextInt());
}
} else if (attribute.getEType().getInstanceClass().equals(Date.class)) {
if (attribute.isMany()) {
Object object = me.eGet(attribute);
EList<Date> eList = (EList<Date>) object;
int position = getRandomPosition(eList.size());
eList.add(position, getRandomDate());
} else {
me.eSet(attribute, getRandomDate());
}
}
if (attribute.getEType() instanceof EEnum) {
EEnum en = (EEnum) attribute.getEType();
int numOfLiterals = en.getELiterals().size();
int index = getRandomPosition(numOfLiterals);
EEnumLiteral value = en.getELiterals().get(index);
me.eSet(attribute, value.getInstance());
}
}Example 68
| Project: org.eclipselab.emf.ecore.protobuf-master File: EnumConverter.java View source code |
@Override
public boolean supports(FieldDescriptor sourceType, EDataType targetType) {
return sourceType.getType() == Type.ENUM && targetType instanceof EEnum;
}Example 69
| Project: emf4sw-master File: DatatypeConverter.java View source code |
public static String get(EDataType aType) {
return aType instanceof EEnum ? RDFS.Literal : xsdmap.containsKey(aType) ? xsdmap.get(aType) : RDFS.Literal;
}Example 70
| Project: monticore-master File: ASTENodePackageImpl.java View source code |
public EEnum getConstantsASTENode() {
return constantsASTENodeEEnum;
}Example 71
| Project: xrepl-master File: EcoreUtil3.java View source code |
public static boolean isEnum(EClassifier eType) {
return eType instanceof EEnum;
}Example 72
| Project: Android-DataLib-master File: ContentPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getParseType() {
return parseTypeEEnum;
}Example 73
| Project: edu.ufc.femtost.disc.sysml2modelica-master File: TypesPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getModelicaFlowFlagKind() {
return modelicaFlowFlagKindEEnum;
}Example 74
| Project: eef-master File: ValidationPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getSeverity() {
return severityEEnum;
}Example 75
| Project: EMF-IncQuery-Examples-master File: Bpmn20execPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getProcessState() {
return processStateEEnum;
}Example 76
| Project: ifml-editor-master File: DataTypesPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getDirection() {
return directionEEnum;
}Example 77
| Project: rmf-master File: MappingPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getDataType() {
return dataTypeEEnum;
}Example 78
| Project: starschema-talend-plugins-master File: ConstantsPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getDevelopmentStatus() {
return developmentStatusEEnum;
}Example 79
| Project: webtools.jsf-master File: QuickEditTabSectionsPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getSECTION_TYPE() {
return sectioN_TYPEEEnum;
}Example 80
| Project: ArchStudio5-master File: Domain_3_0PackageImpl.java View source code |
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public EEnum getDomainType() {
return domainTypeEEnum;
}Example 81
| Project: dltk.tcl-master File: MessagesPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getMessageCategory() {
return messageCategoryEEnum;
}Example 82
| Project: elexis-3-core-master File: TypesPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getContactType() {
return contactTypeEEnum;
}Example 83
| Project: fstoolkit-master File: ExperimentRuntimePackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getRuntimeElementStatus() {
return runtimeElementStatusEEnum;
}Example 84
| Project: Magic-Collection-Builder-master File: DatabasePackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getCardCSVFields() {
return cardCSVFieldsEEnum;
}Example 85
| Project: melange-master File: TestcopyPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getMyEnum() {
return myEnumEEnum;
}Example 86
| Project: openflexo-eclipse-master File: City1PackageImpl.java View source code |
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
public EEnum getHouseType() {
return houseTypeEEnum;
}Example 87
| Project: skysail-server-ext-master File: FormsPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getType() {
return typeEEnum;
}Example 88
| Project: tdq-studio-se-master File: SQLPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getSqlPredicate() {
return sqlPredicateEEnum;
}Example 89
| Project: viatra-example-master File: FowlerPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getState() {
return stateEEnum;
}Example 90
| Project: webtools.javaee-master File: ClientPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getResAuthApplicationType() {
return resAuthApplicationTypeEEnum;
}Example 91
| Project: webtools.sourceediting-master File: DTDAdapterFactory.java View source code |
public Object caseEEnum(EEnum object) {
return createEEnumAdapter();
}Example 92
| Project: emf.emfstore.core-master File: ModelPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
public EEnum getEMFStorePropertyType() {
return emfStorePropertyTypeEEnum;
}Example 93
| Project: emfdatabinding-tutorial-master File: AddressbookPackageImpl.java View source code |
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
public EEnum getAddressType() {
return addressTypeEEnum;
}Example 94
| Project: fr.obeo.performance-master File: PerformancePackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getDimension() {
return dimensionEEnum;
}Example 95
| Project: geotools-2.7.x-master File: XlinkPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getActuateType() {
return actuateTypeEEnum;
}Example 96
| Project: geotools-old-master File: XlinkPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getActuateType() {
return actuateTypeEEnum;
}Example 97
| Project: geotools-tike-master File: XlinkPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getActuateType() {
return actuateTypeEEnum;
}Example 98
| Project: geotools_trunk-master File: XlinkPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getActuateType() {
return actuateTypeEEnum;
}Example 99
| Project: mecha-master File: OpServiceModelPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getOpArgType() {
return opArgTypeEEnum;
}Example 100
| Project: mechanoid-master File: OpServiceModelPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getOpArgType() {
return opArgTypeEEnum;
}Example 101
| Project: Permet-master File: ChessPackageImpl.java View source code |
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EEnum getRanks() {
return ranksEEnum;
}