Coverage Report - com.sdmetrics.model.XMITransformation - www.sdmetrics.com
 
Classes in this File Line Coverage Branch Coverage Complexity
XMITransformation
100%
29/29
100%
4/4
1,25
 
 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  1657
         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  1657
         private boolean xmiRecurse = false;
 44  
         /**
 45  
          * Indicates if the XMI element must have an explicit XMI id for this
 46  
          * transformation to fire.
 47  
          */
 48  1657
         private boolean requireXMIID = true;
 49  
 
 50  
         /**
 51  
          * Indicates if this transformation fires if an XMI element without 
 52  
          * explicit XMI id has an XMI idref attribute. 
 53  
          */
 54  1657
         private boolean allowXMIIDRef = false;
 55  
 
 56  
         /** Conditional expression for this XMI transformation. */
 57  1657
         private ExpressionNode condition = null;
 58  
         /** Line number of the XMI transformation in the definition file. */
 59  
         private int lineNumber;
 60  
 
 61  
         /**
 62  
          * Creates a new XMI transformation with an empty list of triggers.
 63  
          * 
 64  
          * @param type The metamodel element type that this transformations
 65  
          *        produces.
 66  
          * @param xmiPattern The name of the XMI element that corresponds to the
 67  
          *        metamodel element type.
 68  
          * @param recurse Flag indicating if model elements produced by this
 69  
          *        transformation can own sub-elements.
 70  
          * @param requireXMIID Flag indicating if this transformation requires XMI
 71  
          *        IDs to be present in the XMI file for the transformation to fire
 72  
          * @param allowXMIIDRef Flag indicating if this transformation fires even
 73  
          *        if the XMI element contains an XMI idref attribute
 74  
          * @param condition The condition operator tree for conditional
 75  
          *        transformations. <code>null</code> for unconditional
 76  
          *        transformations.
 77  
          */
 78  1657
         XMITransformation(MetaModelElement type, String xmiPattern,
 79  
                         boolean recurse, boolean requireXMIID, boolean allowXMIIDRef, 
 80  
                         ExpressionNode condition) {
 81  1657
                 this.type = type;
 82  1657
                 this.xmiPattern = xmiPattern;
 83  1657
                 this.xmiRecurse = recurse;
 84  1657
                 this.requireXMIID = requireXMIID;
 85  1657
                 this.allowXMIIDRef = allowXMIIDRef;
 86  1657
                 this.condition = condition;
 87  1657
         }
 88  
 
 89  
         /**
 90  
          * Adds a trigger to the XMI transformation.
 91  
          * 
 92  
          * @param t Trigger to add.
 93  
          */
 94  
         void addTrigger(XMITrigger t) {
 95  11469
                 triggers.add(t);
 96  11469
         }
 97  
 
 98  
         /**
 99  
          * Retrieves the list of triggers of this XMI transformation.
 100  
          * 
 101  
          * @return Random access list of triggers
 102  
          */
 103  
         List<XMITrigger> getTriggerList() {
 104  37417
                 return triggers;
 105  
         }
 106  
 
 107  
         /**
 108  
          * Returns the name of the XMI element this XMI transformation handles.
 109  
          * 
 110  
          * @return Name of the XMI element associated with this XMI transformation.
 111  
          */
 112  
         String getXMIPattern() {
 113  3293
                 return xmiPattern;
 114  
         }
 115  
 
 116  
         /**
 117  
          * Checks if model elements produced by this transformation can own
 118  
          * sub-elements.
 119  
          * 
 120  
          * @return <code>true</code> if the model element can have sub-elements.
 121  
          */
 122  
         boolean getXMIRecurse() {
 123  36871
                 return xmiRecurse;
 124  
         }
 125  
 
 126  
         /**
 127  
          * Checks if the XMI element for this transformation requires an XMI id to
 128  
          * be recognized as design element.
 129  
          * 
 130  
          * @return <code>true</code> if XMI ID is required for recognition as model
 131  
          *         element
 132  
          */
 133  
         boolean requiresXMIID() {
 134  16346
                 return requireXMIID;
 135  
         }
 136  
 
 137  
 
 138  
         /**
 139  
          * Checks if the XMI element for this transformation must not have an XMI idref to
 140  
          * be recognized as design element.
 141  
          * 
 142  
          * @return <code>true</code> if the presence of an XMI idref does not prevent
 143  
          *         recognition as model element
 144  
          */
 145  
         boolean allowsXMIIDRef() {
 146  492
                 return allowXMIIDRef;
 147  
         }
 148  
 
 149  
         /**
 150  
          * Returns the operator tree for the condition expression.
 151  
          * 
 152  
          * @return root node of the operator tree, or <code>null</code> if this is
 153  
          *         an unconditional transformation
 154  
          */
 155  
         ExpressionNode getConditionExpression() {
 156  18015
                 return condition;
 157  
         }
 158  
 
 159  
         /**
 160  
          * Return the type of elements produced by this XMI transformation.
 161  
          * 
 162  
          * @return metamodel element type of this XMI transformation
 163  
          */
 164  
         MetaModelElement getType() {
 165  48106
                 return type;
 166  
         }
 167  
 
 168  
         /**
 169  
          * Sets the line number of this XMI transformation's definition in the XMI
 170  
          * transformation file. Used to pinpoint the user to the error location when
 171  
          * there is a problem during the evaluation of condition expressions.
 172  
          * 
 173  
          * @param line Line number of the transformation
 174  
          */
 175  
         void setLineNumber(int line) {
 176  1657
                 lineNumber = line;
 177  1657
         }
 178  
 
 179  
         /**
 180  
          * Gets the line number of the XMI transformation's definition in the XMI
 181  
          * transformation file.
 182  
          * 
 183  
          * @return Line number of the transformation
 184  
          */
 185  
         int getLineNumber() {
 186  1
                 return lineNumber;
 187  
         }
 188  
 
 189  
         /**
 190  
          * Checks if this XMI transformation has a trigger of a certain name.
 191  
          * 
 192  
          * @param triggerName The name of the trigger to search
 193  
          * @return <code>true</code> if the transformation has a trigger with that
 194  
          *         name
 195  
          */
 196  
         boolean hasTrigger(String triggerName) {
 197  30674
                 for (XMITrigger trigger : triggers) {
 198  13549
                         if (trigger.name.equals(triggerName)) {
 199  765
                                 return true;
 200  
                         }
 201  
                 }
 202  8180
                 return false;
 203  
         }
 204  
 }