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

org.eclipse.ocl.expressions.operations.LoopExpOperations 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: LoopExpOperations.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.LoopExp;
import org.eclipse.ocl.expressions.OCLExpression;
import org.eclipse.ocl.expressions.Variable;

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;

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

* The following operations are supported: *

    *
  • {@link org.eclipse.ocl.expressions.LoopExp#checkSourceCollection(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Source Collection}
  • *
  • {@link org.eclipse.ocl.expressions.LoopExp#checkLoopVariableInit(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Loop Variable Init}
  • *
  • {@link org.eclipse.ocl.expressions.LoopExp#checkLoopVariableType(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) Check Loop Variable Type}
  • *
*

* * @generated */ public class LoopExpOperations extends OCLExpressionOperations { /** * * * @generated */ protected LoopExpOperations() { super(); } /** * * * * source.type.oclIsKindOf(CollectionType) * @param loopExp The receiving 'Loop 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 checkSourceCollection(LoopExp loopExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; OCLExpression source = loopExp.getSource(); if (source != null) { C sourceType = source.getType(); if (!(sourceType instanceof CollectionType)) { result = false; message = OCLMessages.bind(OCLMessages.IteratorSource_ERROR_, loopExp.toString()); } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.LOOP_EXP__SOURCE_COLLECTION, message, new Object[]{loopExp})); } } return result; } /** * * * * self.iterator->forAll(initExpression->isEmpty()) * @param loopExp The receiving 'Loop 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 checkLoopVariableInit(LoopExp loopExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; for (Variable loopiter : loopExp.getIterator()) { if (loopiter.getInitExpression() != null) { result = false; message = OCLMessages.bind( OCLMessages.IterateExpLoopVarInit_ERROR_, loopExp .toString()); break; } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.LOOP_EXP__LOOP_VARIABLE_INIT, message, new Object[]{loopExp})); } } return result; } /** * * * * self.iterator->forAll(type = source.type.oclAsType(CollectionType).elementType) * @param loopExp The receiving 'Loop 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 checkLoopVariableType(LoopExp loopExp, DiagnosticChain diagnostics, Map context) { boolean result = true; String message = null; Environment env = OCLUtil .getValidationEnvironment(loopExp, context); if ((env != null) && (loopExp.getSource() != null) && (loopExp.getSource().getType() instanceof CollectionType)) { @SuppressWarnings("unchecked") CollectionType ct = (CollectionType) loopExp .getSource().getType(); C elementType = ct.getElementType(); if (elementType != null) { for (Variable loopiter : loopExp.getIterator()) { if ((loopiter.getType() != null) && !TypeUtil.exactTypeMatch(env, loopiter.getType(), elementType)) { result = false; message = OCLMessages .bind( OCLMessages.TypeConformanceIteratorExpLoopVar_ERROR_, loopExp.toString()); break; } } } } if (!result) { if (diagnostics != null) { diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, ExpressionsValidator.DIAGNOSTIC_SOURCE, ExpressionsValidator.LOOP_EXP__LOOP_VARIABLE_TYPE, message, new Object[]{loopExp})); } } return result; } } // LoopExpOperations




© 2015 - 2024 Weber Informatics LLC | Privacy Policy