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

org.eclipse.ocl.expressions.operations.IteratorExpOperations 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: IteratorExpOperations.java,v 1.4 2009/06/25 19:23:52 ewillink Exp $
 */
package org.eclipse.ocl.expressions.operations;

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.IteratorExp;
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.BagType;
import org.eclipse.ocl.types.OrderedSetType;
import org.eclipse.ocl.types.PrimitiveType;
import org.eclipse.ocl.types.SequenceType;
import org.eclipse.ocl.util.OCLStandardLibraryUtil;
import org.eclipse.ocl.util.OCLUtil;
import org.eclipse.ocl.util.TypeUtil;
import org.eclipse.ocl.utilities.PredefinedType;

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

* The following operations are supported: *

    *
  • {@link org.eclipse.ocl.expressions.IteratorExp#checkBooleanType(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Boolean Type}
  • *
  • {@link org.eclipse.ocl.expressions.IteratorExp#checkCollectType(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Collect Type}
  • *
  • {@link org.eclipse.ocl.expressions.IteratorExp#checkSelectRejectType(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Select Reject Type}
  • *
  • {@link org.eclipse.ocl.expressions.IteratorExp#checkBooleanBodyType(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Boolean Body Type}
  • *
*

* * @generated */ public class IteratorExpOperations extends LoopExpOperations { /** * * * @generated */ protected IteratorExpOperations() { super(); } /** * * * * name = 'exists' or name = 'forAll' or name = 'isUnique' * implies type.oclIsKindOf(PrimitiveType) and type.name = 'Boolean' * @param iteratorExp The receiving 'Iterator 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 checkBooleanType( IteratorExp iteratorExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(iteratorExp, context); C type = iteratorExp.getType(); if (env != null) { String name = iteratorExp.getName(); int opcode = OCLStandardLibraryUtil.getOperationCode(name); switch (opcode) { case PredefinedType.FOR_ALL : case PredefinedType.EXISTS : case PredefinedType.IS_UNIQUE : if (!(type instanceof PrimitiveType) || !"Boolean".equals(env.getUMLReflection() //$NON-NLS-1$ .getName(type))) { result = false; message = OCLMessages.bind( OCLMessages.TypeConformanceIteratorResult_ERROR_, iteratorExp.toString()); } } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.ITERATOR_EXP__BOOLEAN_TYPE, message, new Object[]{iteratorExp})); } } return result; } /** * * * * name = 'collect' implies * if source.type.oclIsKindOf(SequenceType) then * type = expression.type.collectionType->select(oclIsTypeOf(SequenceType))->first() * else * type = expression.type.collectionType->select(oclIsTypeOf(BagType))->first() * endif * @param iteratorExp The receiving 'Iterator 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 checkCollectType( IteratorExp iteratorExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(iteratorExp, context); C type = iteratorExp.getType(); OCLExpression source = iteratorExp.getSource(); if ((env != null) && (source != null) && (source.getType() != null)) { String name = iteratorExp.getName(); int opcode = OCLStandardLibraryUtil.getOperationCode(name); switch (opcode) { case PredefinedType.COLLECT : if ((source.getType() instanceof SequenceType) || (source.getType() instanceof OrderedSetType)) { if (!(type instanceof SequenceType)) { result = false; message = OCLMessages .bind( OCLMessages.TypeConformanceCollectSequence_ERROR_, iteratorExp.toString()); } } else if (!(type instanceof BagType)) { result = false; message = OCLMessages.bind( OCLMessages.TypeConformanceCollectBag_ERROR_, iteratorExp.toString()); } break; } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.ITERATOR_EXP__COLLECT_TYPE, message, new Object[]{iteratorExp})); } } return result; } /** * * * * name = 'select' or name = 'reject' implies type = source.type * @param iteratorExp The receiving 'Iterator 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 checkSelectRejectType( IteratorExp iteratorExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(iteratorExp, context); C type = iteratorExp.getType(); OCLExpression source = iteratorExp.getSource(); if ((env != null) && (source != null) && (source.getType() != null)) { String name = iteratorExp.getName(); int opcode = OCLStandardLibraryUtil.getOperationCode(name); switch (opcode) { case PredefinedType.SELECT : case PredefinedType.REJECT : if (!TypeUtil.exactTypeMatch(env, type, source.getType())) { result = false; message = OCLMessages.bind( OCLMessages.TypeConformanceSelectReject_ERROR_, iteratorExp.toString()); } break; } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.ITERATOR_EXP__SELECT_REJECT_TYPE, message, new Object[]{iteratorExp})); } } return result; } /** * * * * name = 'exists' or name = 'forAll' or name = 'select' or name = 'reject' * implies body.type.name = 'Boolean' * @param iteratorExp The receiving 'Iterator 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 checkBooleanBodyType( IteratorExp iteratorExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(iteratorExp, context); OCLExpression body = iteratorExp.getBody(); if ((env != null) && (body != null)) { C type = body.getType(); String name = iteratorExp.getName(); int opcode = OCLStandardLibraryUtil.getOperationCode(name); switch (opcode) { case PredefinedType.SELECT : case PredefinedType.REJECT : case PredefinedType.FOR_ALL : case PredefinedType.ANY : case PredefinedType.EXISTS : case PredefinedType.ONE : if (!(type instanceof PrimitiveType) || !"Boolean".equals(env.getUMLReflection() //$NON-NLS-1$ .getName(type))) { result = false; message = OCLMessages .bind( OCLMessages.TypeConformanceIteratorBodyBoolean_ERROR_, iteratorExp.toString()); } break; } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.ITERATOR_EXP__BOOLEAN_BODY_TYPE, message, new Object[]{iteratorExp})); } } return result; } } // IteratorExpOperations




© 2015 - 2024 Weber Informatics LLC | Privacy Policy