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

org.eclipse.ocl.expressions.operations.MessageExpOperations 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: MessageExpOperations.java,v 1.5 2010/01/14 12:44:33 ewillink Exp $
 */
package org.eclipse.ocl.expressions.operations;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

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.MessageExp;
import org.eclipse.ocl.expressions.OCLExpression;

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

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

* The following operations are supported: *

    *
  • {@link org.eclipse.ocl.expressions.MessageExp#checkOperationArguments(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Operation Arguments}
  • *
  • {@link org.eclipse.ocl.expressions.MessageExp#checkSignalArguments(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Signal Arguments}
  • *
  • {@link org.eclipse.ocl.expressions.MessageExp#checkTargetDefinesOperation(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Target Defines Operation}
  • *
  • {@link org.eclipse.ocl.expressions.MessageExp#checkHasOperationOrSignal(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Has Operation Or Signal}
  • *
  • {@link org.eclipse.ocl.expressions.MessageExp#checkTargetNotCollection(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Target Not Collection}
  • *
*

* * @generated */ public class MessageExpOperations extends OCLExpressionOperations { /** * * * @generated */ protected MessageExpOperations() { super(); } /** * * * * calledOperation->notEmpty() implies * argument->forall (a | a.type.conformsTo * (self.calledOperation.operation.ownedParameter-> * select( kind = ParameterDirectionKind::in ) * ->at (argument->indexOf (a)).type)) * @param messageExp The receiving 'Message 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 checkOperationArguments( MessageExp messageExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(messageExp, context); if (env != null) { UMLReflection uml = env .getUMLReflection(); if (messageExp.getCalledOperation() == null) { return true; } Object operation = uml .getOperation(messageExp.getCalledOperation()); if (operation == null) { return true; } List parameters = uml.getParameters(operation); List> arguments = messageExp.getArgument(); if (arguments.size() != parameters.size()) { result = false; message = OCLMessages.bind( OCLMessages.MessageArgumentCount_ERROR_, uml .getName(messageExp.getType())); } else { // check type conformance against parameters Iterator paramsIter = parameters.iterator(); Iterator> argsIter = arguments.iterator(); while (paramsIter.hasNext()) { Object param = paramsIter.next(); OCLExpression arg = argsIter.next(); if (!TypeUtil.compatibleTypeMatch(env, arg.getType(), uml .getOCLType(param))) { result = false; message = OCLMessages.bind( OCLMessages.MessageArgConformance_ERROR_, uml .getName(param), arg.toString()); break; } } } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.MESSAGE_EXP__OPERATION_ARGUMENTS, message, new Object[]{messageExp})); } } return result; } /** * * * * sentSignal->notEmpty() implies * argument->forall (a | a.type.conformsTo * (self.sentSignal.signal.ownedAttribute * ->at (argument->indexOf (a)).type)) * @param messageExp The receiving 'Message 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 checkSignalArguments( MessageExp messageExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(messageExp, context); if (env != null) { UMLReflection uml = env .getUMLReflection(); if (messageExp.getSentSignal() == null) { return true; } C signal = uml.getSignal(messageExp.getSentSignal()); if (signal == null) { return true; } List attributes = uml.getAttributes(signal); List> arguments = messageExp.getArgument(); if (arguments.size() != attributes.size()) { result = false; message = OCLMessages.bind( OCLMessages.MessageArgumentCount_ERROR_, uml .getName(messageExp.getType())); } else { // check type conformance against attributes Iterator attrsIter = attributes.iterator(); Iterator> argsIter = arguments.iterator(); while (attrsIter.hasNext()) { Object attr = attrsIter.next(); OCLExpression arg = argsIter.next(); if (!TypeUtil.compatibleTypeMatch(env, arg.getType(), uml .getOCLType(attr))) { result = false; message = OCLMessages.bind( OCLMessages.MessageArgConformance_ERROR_, uml .getName(attr), arg.toString()); break; } } } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.MESSAGE_EXP__SIGNAL_ARGUMENTS, message, new Object[]{messageExp})); } } return result; } /** * * * * calledOperation->notEmpty() implies * target.type.allOperations()->includes(calledOperation.operation) * @param messageExp The receiving 'Message 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 checkTargetDefinesOperation( MessageExp messageExp, DiagnosticChain diagnostics, Map context) { boolean result = true; Environment env = OCLUtil .getValidationEnvironment(messageExp, context); if (env != null) { UMLReflection uml = env .getUMLReflection(); if (messageExp.getTarget() == null) { return true; } if (messageExp.getTarget().getType() == null) { return true; } if (messageExp.getCalledOperation() == null) { return true; } Object operation = uml .getOperation(messageExp.getCalledOperation()); if (operation == null) { return true; } String name = uml.getName(operation); List> arguments = messageExp.getArgument(); Object operation1 = env.lookupOperation(messageExp.getTarget() .getType(), name, arguments); if (operation1 != operation) { result = false; } } if (!result) { if (diagnostics != null) { // TODO: Specific message diagnostics .add(new BasicDiagnostic( Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.MESSAGE_EXP__TARGET_DEFINES_OPERATION, org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE .getString( "_UI_GenericInvariant_diagnostic", new Object[]{"checkTargetDefinesOperation", org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(messageExp, context)}), //$NON-NLS-1$ //$NON-NLS-2$ new Object[]{messageExp})); } } return result; } /** * * * * calledOperation->size() + sentSignal->size() = 1 * @param messageExp The receiving 'Message 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 checkHasOperationOrSignal( MessageExp messageExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; if (messageExp.getCalledOperation() == null && messageExp.getSentSignal() == null) { result = false; message = OCLMessages.UnrecognizedMessageType_ERROR_; } if (messageExp.getCalledOperation() != null && messageExp.getSentSignal() != null) { result = false; message = OCLMessages.AmbiguousMessageType_ERROR_; } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.MESSAGE_EXP__HAS_OPERATION_OR_SIGNAL, message, new Object[]{messageExp})); } } return result; } /** * * * * not target.type.oclIsKindOf(CollectionType) * @param messageExp The receiving 'Message 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 checkTargetNotCollection( MessageExp messageExp, DiagnosticChain diagnostics, Map context) { boolean result = true; OCLExpression target = messageExp.getTarget(); if ((target != null) && (target.getType() instanceof CollectionType)) { result = false; } if (!result) { if (diagnostics != null) { // TODO: Specific message diagnostics .add(new BasicDiagnostic( Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.MESSAGE_EXP__TARGET_NOT_COLLECTION, org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE .getString( "_UI_GenericInvariant_diagnostic", new Object[]{"checkTargetNotCollection", org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(messageExp, context)}), //$NON-NLS-1$ //$NON-NLS-2$ new Object[]{messageExp})); } } return result; } } // MessageExpOperations




© 2015 - 2024 Weber Informatics LLC | Privacy Policy