Coverage Report - org.argouml.uml.cognitive.critics.CrNavFromInterface
 
Classes in this File Line Coverage Branch Coverage Complexity
CrNavFromInterface
33%
9/27
0%
0/14
4.333
 
 1  
 /* $Id: CrNavFromInterface.java 17849 2010-01-12 19:50:34Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    maurelio1234
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2007 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.cognitive.critics;
 40  
 
 41  
 import java.util.HashSet;
 42  
 import java.util.Iterator;
 43  
 import java.util.Set;
 44  
 
 45  
 import org.argouml.cognitive.Critic;
 46  
 import org.argouml.cognitive.Designer;
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.uml.cognitive.UMLDecision;
 49  
 
 50  
 /**
 51  
  * A critic to detect navigation from an Interface to a Class in an
 52  
  * Association.  This is not permitted in UML, since it would require
 53  
  * the Interface to hold state to represent the association
 54  
  * reference.<p>
 55  
  *
 56  
  * The critic will trigger whenever an association between an
 57  
  * interface and a class is navigable <em>from</em> the interface.<p>
 58  
  *
 59  
  * See the ArgoUML User Manual: Remove Navigation From Interface
 60  
  *
 61  
  * @author jrobbins@ics.uci.edu
 62  
  */
 63  
 public class CrNavFromInterface extends CrUML {
 64  
 
 65  
     /**
 66  
      * Constructor for the critic.
 67  
      * <p>
 68  
      * Sets up the resource name, which will allow headline and description to
 69  
      * found for the current locale. Provides a design issue category
 70  
      * (RELATIONSHIPS) and knowledge type (SYNTAX). Adds trigger
 71  
      * "end_navigable".
 72  
      */
 73  900
     public CrNavFromInterface() {
 74  900
         setupHeadAndDesc();
 75  
 
 76  
         // Specify design issue category and knowledge type
 77  
 
 78  900
         addSupportedDecision(UMLDecision.RELATIONSHIPS);
 79  900
         setKnowledgeTypes(Critic.KT_SYNTAX);
 80  
 
 81  
         // This may not actually make any difference at present (the code
 82  
         // behind addTrigger needs more work).
 83  
 
 84  900
         addTrigger("end_navigable");
 85  900
     }
 86  
 
 87  
     /**
 88  
      * The trigger for the critic.<p>
 89  
      *
 90  
      * Applies to Associations only, not AssociationRoles. The reason is
 91  
      * that an AssociationRole cannot have greater navigability than the
 92  
      * Association it specializes, so if the critic has addressed the
 93  
      * Association, the AssociationRole will effectively be addressed. There
 94  
      * may of course be a need for a critic to check that Association Roles do
 95  
      * match their parents in this respect!<p>
 96  
      *
 97  
      * As a consequence, we also don't need to check for associations with
 98  
      * ClassifierRoles.<p>
 99  
      *
 100  
      * Iterate over all the AssociationEnds. We only have a problem if:<p>
 101  
      * <ol>
 102  
      *   <li>There is an end connected to an Interface; and
 103  
      *   <li>An end other than that end is navigable.
 104  
      * </ol>
 105  
      *
 106  
      * @param  dm    the object to be checked against the critic
 107  
      * @param  dsgr  the designer creating the model. Not used, this is for
 108  
      *               future development of ArgoUML
 109  
      * @return       {@link #PROBLEM_FOUND PROBLEM_FOUND} if the critic is
 110  
      *               triggered, otherwise {@link #NO_PROBLEM NO_PROBLEM}.
 111  
      */
 112  
     public boolean predicate2(Object dm, Designer dsgr) {
 113  
 
 114  
         // Only look at Associations
 115  
 
 116  0
         if (!(Model.getFacade().isAAssociation(dm))) {
 117  0
             return NO_PROBLEM;
 118  
         }
 119  
 
 120  0
         if (Model.getFacade().isAAssociationRole(dm)) {
 121  0
             return NO_PROBLEM;
 122  
         }
 123  
 
 124  
         // Iterate over all the AssociationEnds. We only have a problem if 1)
 125  
         // there is an end connected to an Interface and 2) an end other than
 126  
         // that end is navigable.
 127  
 
 128  0
         Iterator assocEnds = Model.getFacade().getConnections(dm).iterator();
 129  
 
 130  0
         boolean haveInterfaceEnd  = false;  // End at an Interface?
 131  0
         boolean otherEndNavigable = false;  // Navigable other end?
 132  
 
 133  0
         while (assocEnds.hasNext()) {
 134  
 
 135  
             // The next AssociationEnd
 136  
 
 137  0
             Object ae = assocEnds.next();
 138  
 
 139  
             // If its an interface we have an interface end, otherwise its
 140  
             // something else and we should see if it is navigable. We don't
 141  
             // check that the end is a Classifier, rather than its child
 142  
             // ClassifierRole, since we have effectively eliminated that
 143  
             // possiblity in rejecting AssociationRoles above.
 144  
 
 145  0
             Object type = Model.getFacade().getType(ae);
 146  
 
 147  0
             if (Model.getFacade().isAInterface(type)) {
 148  0
                 haveInterfaceEnd = true;
 149  0
             } else if (Model.getFacade().isNavigable(ae)) {
 150  0
                 otherEndNavigable = true;
 151  
             }
 152  
 
 153  
             // We can give up looking if we've hit both criteria
 154  
 
 155  0
             if (haveInterfaceEnd && otherEndNavigable) {
 156  0
                 return PROBLEM_FOUND;
 157  
             }
 158  0
         }
 159  
 
 160  
         // If we drop out we didn't meet both criteria, and all is well.
 161  
 
 162  0
         return NO_PROBLEM;
 163  
     }
 164  
 
 165  
     /*
 166  
      * @see org.argouml.uml.cognitive.critics.CrUML#getCriticizedDesignMaterials()
 167  
      */
 168  
     public Set<Object> getCriticizedDesignMaterials() {
 169  900
         Set<Object> ret = new HashSet<Object>();
 170  900
         ret.add(Model.getMetaTypes().getAssociationClass());
 171  900
         return ret;
 172  
     }
 173  
 
 174  
     /**
 175  
      * The UID.
 176  
      */
 177  
     private static final long serialVersionUID = 2660051106458704056L;
 178  
 } /* end class CrNavFromInterface */
 179