All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ocl.expressions.operations.TupleLiteralExpOperations Maven / Gradle / Ivy

/**
 * 
 * 
 * Copyright (c) 2008 IBM Corporation, Zeligsoft Inc., and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   IBM - Initial API and implementation
 *   Zeligsoft - Bug 207365
 * 
 * 
 *
 * $Id: TupleLiteralExpOperations.java,v 1.4 2009/06/25 19:23:52 ewillink Exp $
 */
package org.eclipse.ocl.expressions.operations;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;

import org.eclipse.ocl.Environment;
import org.eclipse.ocl.expressions.TupleLiteralExp;
import org.eclipse.ocl.expressions.TupleLiteralPart;

import org.eclipse.ocl.expressions.util.ExpressionsValidator;
import org.eclipse.ocl.internal.l10n.OCLMessages;
import org.eclipse.ocl.types.TupleType;
import org.eclipse.ocl.util.OCLUtil;
import org.eclipse.ocl.utilities.UMLReflection;

/**
 * 
 * A static utility class that provides operations related to 'Tuple Literal Exp' model objects.
 * 
 *
 * 

* The following operations are supported: *

    *
  • {@link org.eclipse.ocl.expressions.TupleLiteralExp#checkTupleType(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Tuple Type}
  • *
  • {@link org.eclipse.ocl.expressions.TupleLiteralExp#checkPartsUnique(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Parts Unique}
  • *
*

* * @generated */ public class TupleLiteralExpOperations extends OCLExpressionOperations { /** * * * @generated */ protected TupleLiteralExpOperations() { super(); } /** * * * * type.oclIsKindOf (TupleType) * and * part->forAll (tlep | * type.oclAsType (TupleType).allProperties()->exists (tp | tlep.attribute = tp)) * and * part->size() = type.oclAsType (TupleType).allProperties()->size() * @param tupleLiteralExp The receiving 'Tuple Literal Exp' model object. * @param diagnostics The chain of diagnostics to which problems are to be appended. * @param context The cache of context-specific information. * * @generated NOT */ public static boolean checkTupleType( TupleLiteralExp tupleLiteralExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(tupleLiteralExp, context); if (env != null) { UMLReflection uml = env .getUMLReflection(); C type = tupleLiteralExp.getType(); if (!(type instanceof TupleType)) { result = false; message = OCLMessages.bind( OCLMessages.TypeConformanceTupleLiteralExp_ERROR_, tupleLiteralExp.toString()); } else { // The fields of the tuple are the properties of the EClass. List> tp = tupleLiteralExp.getPart(); List

attributes = uml.getAttributes(type); if (tp.size() != attributes.size()) { result = false; message = OCLMessages.bind( OCLMessages.TypeConformanceTupleLiteralExpParts_ERROR_, tupleLiteralExp.toString()); } else { // Match each property with a tuple part for (TupleLiteralPart part : tp) { if ((part.getAttribute() == null) || (uml.getOwningClassifier(part.getAttribute()) != type)) { result = false; message = OCLMessages.bind( OCLMessages.TupleLiteralExpressionPart_ERROR_, part.getName(), tupleLiteralExp.toString()); break; } } } } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.TUPLE_LITERAL_EXP__TUPLE_TYPE, message, new Object[]{tupleLiteralExp})); } } return result; } /** * * * * part->isUnique (attribute.name) * @param tupleLiteralExp The receiving 'Tuple Literal Exp' model object. * @param diagnostics The chain of diagnostics to which problems are to be appended. * @param context The cache of context-specific information. * * @generated NOT */ public static boolean checkPartsUnique( TupleLiteralExp tupleLiteralExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Set names = new java.util.HashSet(); // Match each property with a tuple part for (TupleLiteralPart part : tupleLiteralExp.getPart()) { String name = part.getName(); if (!names.add(name)) { result = false; message = OCLMessages.bind( OCLMessages.TupleDuplicateName_ERROR_, name, tupleLiteralExp.toString()); } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.TUPLE_LITERAL_EXP__PARTS_UNIQUE, message, new Object[]{tupleLiteralExp})); } } return result; } } // TupleLiteralExpOperations





© 2015 - 2024 Weber Informatics LLC | Privacy Policy