Coverage Report - com.sdmetrics.model.XMITransformation - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
XMITransformation
100%
26/26
100%
4/4
1,273
 
 1  
 /*
 2  
  * SDMetrics Open Core for UML design measurement
 3  
  * Copyright (c) Juergen Wuest
 4  
  * To contact the author, see <http://www.sdmetrics.com/Contact.html>.
 5  
  * 
 6  
  * This file is part of the SDMetrics Open Core.
 7  
  * 
 8  
  * SDMetrics Open Core is free software: you can redistribute it and/or modify
 9  
  * it under the terms of the GNU Affero General Public License as
 10  
  * published by the Free Software Foundation, either version 3 of the
 11  
  * License, or (at your option) any later version.
 12  
     
 13  
  * SDMetrics Open Core is distributed in the hope that it will be useful,
 14  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  
  * GNU Affero General Public License for more details.
 17  
  *
 18  
  * You should have received a copy of the GNU Affero General Public License
 19  
  * along with SDMetrics Open Core.  If not, see <http://www.gnu.org/licenses/>.
 20  
  *
 21  
  */
 22  
 package com.sdmetrics.model;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 import com.sdmetrics.math.ExpressionNode;
 28  
 
 29  
 /**
 30  
  * Stores the XMI pattern and triggers for one XMI transformation.
 31  
  */
 32  
 class XMITransformation {
 33  
         /** Name of the XMI element that this XMI transformation handles. */
 34  
         private final String xmiPattern;
 35  
         /** Metamodel element type that this XMI transformation produces. */
 36  
         private final MetaModelElement type;
 37  
         /** List of triggers stored with this XMI transformation. */
 38  1637
         private final ArrayList<XMITrigger> triggers = new ArrayList<XMITrigger>();
 39  
         /**
 40  
          * Indicates if the model element produces by this transformation can own
 41  
          * sub-elements.
 42  
          */
 43  1637
         private boolean xmiRecurse = false;
 44  
         /**
 45  
          * Indicate if the XMI element must have an explicit XMI id for this
 46  
          * transformation to fire.
 47  
          */
 48  1637
         private boolean requireXMIID = true;
 49  
         /** Conditional expression for this XMI transformation. */
 50  1637
         private ExpressionNode condition = null;
 51  
         /** Line number of the XMI transformation in the definition file. */
 52  
         private int lineNumber;
 53  
 
 54  
         /**
 55  
          * Creates a new XMI transformation with an empty list of triggers.
 56  
          * 
 57  
          * @param type The metamodel element type that this transformations
 58  
          *        produces.
 59  
          * @param xmiPattern The name of the XMI element that corresponds to the
 60  
          *        metamodel element type.
 61  
          * @param recurse Flag indicating if model elements produced by this
 62  
          *        transformation can own sub-elements.
 63  
          * @param requireXMIID Flag indicating if this transformation requires XMI
 64  
          *        IDs to be present in the XMI file for the transformation to fire
 65  
          * @param condition The condition operator tree for conditional
 66  
          *        transformations. <code>null</code> for unconditional
 67  
          *        transformations.
 68  
          */
 69  1637
         XMITransformation(MetaModelElement type, String xmiPattern,
 70  
                         boolean recurse, boolean requireXMIID, ExpressionNode condition) {
 71  1637
                 this.type = type;
 72  1637
                 this.xmiPattern = xmiPattern;
 73  1637
                 this.xmiRecurse = recurse;
 74  1637
                 this.requireXMIID = requireXMIID;
 75  1637
                 this.condition = condition;
 76  1637
         }
 77  
 
 78  
         /**
 79  
          * Adds a trigger to the XMI transformation.
 80  
          * 
 81  
          * @param t Trigger to add.
 82  
          */
 83  
         void addTrigger(XMITrigger t) {
 84  11352
                 triggers.add(t);
 85  11352
         }
 86  
 
 87  
         /**
 88  
          * Retrieves the list of triggers of this XMI transformation.
 89  
          * 
 90  
          * @return Random access list of triggers
 91  
          */
 92  
         List<XMITrigger> getTriggerList() {
 93  37310
                 return triggers;
 94  
         }
 95  
 
 96  
         /**
 97  
          * Returns the name of the XMI element this XMI transformation handles.
 98  
          * 
 99  
          * @return Name of the XMI element associated with this XMI transformation.
 100  
          */
 101  
         String getXMIPattern() {
 102  3253
                 return xmiPattern;
 103  
         }
 104  
 
 105  
         /**
 106  
          * Checks if model elements produced by this transformation can own
 107  
          * sub-elements.
 108  
          * 
 109  
          * @return <code>true</code> if the model element can have sub-elements.
 110  
          */
 111  
         boolean getXMIRecurse() {
 112  36784
                 return xmiRecurse;
 113  
         }
 114  
 
 115  
         /**
 116  
          * Checks if the XMI element for this transformation requires an XMI id to
 117  
          * be recognized as design element.
 118  
          * 
 119  
          * @return <code>true</code> if XMI ID is required for recognition as model
 120  
          *         element
 121  
          */
 122  
         boolean requiresXMIID() {
 123  16320
                 return requireXMIID;
 124  
         }
 125  
 
 126  
         /**
 127  
          * Returns the operator tree for the condition expression.
 128  
          * 
 129  
          * @return root node of the operator tree, or <code>null</code> if this is
 130  
          *         an unconditional transformation
 131  
          */
 132  
         ExpressionNode getConditionExpression() {
 133  17967
                 return condition;
 134  
         }
 135  
 
 136  
         /**
 137  
          * Return the type of elements produced by this XMI transformation.
 138  
          * 
 139  
          * @return metamodel element type of this XMI transformation
 140  
          */
 141  
         MetaModelElement getType() {
 142  47872
                 return type;
 143  
         }
 144  
 
 145  
         /**
 146  
          * Sets the line number of this XMI transformation's definition in the XMI
 147  
          * transformation file. Used to pinpoint the user to the error location when
 148  
          * there is a problem during the evaluation of condition expressions.
 149  
          * 
 150  
          * @param line Line number of the transformation
 151  
          */
 152  
         void setLineNumber(int line) {
 153  1637
                 lineNumber = line;
 154  1637
         }
 155  
 
 156  
         /**
 157  
          * Gets the line number of the XMI transformation's definition in the XMI
 158  
          * transformation file.
 159  
          * 
 160  
          * @return Line number of the transformation
 161  
          */
 162  
         int getLineNumber() {
 163  1
                 return lineNumber;
 164  
         }
 165  
 
 166  
         /**
 167  
          * Checks if this XMI transformation has a trigger of a certain name.
 168  
          * 
 169  
          * @param triggerName The name of the trigger to search
 170  
          * @return <code>true</code> if the transformation has a trigger with that
 171  
          *         name
 172  
          */
 173  
         boolean hasTrigger(String triggerName) {
 174  30349
                 for (XMITrigger trigger : triggers) {
 175  13379
                         if (trigger.name.equals(triggerName))
 176  752
                                 return true;
 177  
                 }
 178  8109
                 return false;
 179  
         }
 180  
 }