org.argouml.uml.cognitive.critics
Class CrOperNameConflict

java.lang.Object
  extended byorg.argouml.cognitive.critics.Critic
      extended byorg.argouml.uml.cognitive.critics.CrUML
          extended byorg.argouml.uml.cognitive.critics.CrOperNameConflict
All Implemented Interfaces:
Poster, Serializable

public class CrOperNameConflict
extends CrUML

A critic to detect when a class has operations with two matching signatures.

Takes each operation in turn and compares its signature with all earlier operations. This version corrects and earlier bug, which checked for matching names as well as types in the parameter list.

Warning. The algorithm in is quadratic in the number of operations. It could be computationally demanding on a design where classes have a lot of operations. See the predicate2(java.lang.Object, org.argouml.cognitive.Designer) method for possible solutions.

See Also:
ArgoUML User Manual: Change Names or Signatures in <artifact> , Serialized Form

Field Summary
 
Fields inherited from class org.argouml.uml.cognitive.critics.CrUML
DEC_BEHAVIOR, DEC_CLASS_SELECTION, DEC_CODE_GEN, DEC_CONTAINMENT, DEC_EXPECTED_USAGE, DEC_INHERITANCE, DEC_INSTANCIATION, DEC_METHODS, DEC_MODULARITY, DEC_NAMING, DEC_PATTERNS, DEC_PLANNED_EXTENSIONS, DEC_RELATIONSHIPS, DEC_STATE_MACHINES, DEC_STEREOTYPES, DEC_STORAGE
 
Fields inherited from class org.argouml.cognitive.critics.Critic
DEFAULT_CLARIFIER, KT_COMPLETENESS, KT_CONSISTENCY, KT_CORRECTNESS, KT_DESIGNERS, KT_EXPERIENCIAL, KT_OPTIMIZATION, KT_ORGANIZATIONAL, KT_PRESENTATION, KT_SEMANTICS, KT_SYNTAX, KT_TOOL, NO_PROBLEM, PROBLEM_FOUND
 
Constructor Summary
CrOperNameConflict()
          Constructor for the critic.
 
Method Summary
 Icon getClarifier()
          Return the icon to be used for the clarifier for this critic.
 boolean predicate2(Object dm, Designer dsgr)
          The trigger for the critic.
private  boolean signaturesMatch(Object op1, Object op2)
          Sees if the signatures of two Operations are the same.
 
Methods inherited from class org.argouml.uml.cognitive.critics.CrUML
expand, predicate, setHeadline, setResource, toDoItem
 
Methods inherited from class org.argouml.cognitive.critics.Critic
addControlRec, addKnowledgeType, addSupportedDecision, addSupportedGoal, addTrigger, beActive, beInactive, canFixIt, containsKnowledgeType, critique, defaultMoreInfoURL, fixIt, getArg, getArgs, getControlRec, getCriticCategory, getCriticKey, getCriticName, getCriticType, getDecisionCategory, getDescription, getDescriptionTemplate, getExpertEmail, getHeadline, getHeadline, getHeadline, getKnowledgeTypes, getMoreInfoURL, getMoreInfoURL, getPriority, getPriority, getSupportedDecisions, getSupportedGoals, getTriggerMask, getWizardClass, initWizard, isActive, isEnabled, isRelevantToDecisions, isRelevantToGoals, makeWizard, matchReason, postItem, reasonCodeFor, setArg, setArgs, setDecisionCategory, setDescription, setEnabled, setExpertEmail, setKnowledgeTypes, setKnowledgeTypes, setKnowledgeTypes, setKnowledgeTypes, setMoreInfoURL, setPriority, snooze, snoozeOrder, stillValid, supports, supports, toString, unsnooze
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CrOperNameConflict

public CrOperNameConflict()
Constructor for the critic.

Sets up the resource name, which will allow headline and description to found for the current locale. Provides design issue categories (METHODS, NAMING), sets a knowledge type (SYNTAX) and adds triggers for metaclasses "behaviouralFeature" and feature_name".

Method Detail

predicate2

public boolean predicate2(Object dm,
                          Designer dsgr)
The trigger for the critic.

Finds all the operations for the given classifier. Takes each operation in turn and compares its signature with all earlier operations. This version corrects an earlier bug, which checked for matching names as well as types in the parameter list.

Note. The signature ignores any return parameters in looking for a match. This is in line with Java/C++.

We do not need to worry about signature clashes that are inherited (overloading). This is something encouraged in many OO environments to facilitate polymorphism.

This algorithm is quadratic in the number of operations. If this became a problem, we would have to consider sorting the operations vector and comparing only adjacent pairs (potentially O(n log n) performance).

Overrides:
predicate2 in class CrUML
Parameters:
dm - the Object to be checked against the critic.
dsgr - the Designer creating the model. Not used, this is for future development of ArgoUML.
Returns:
PROBLEM_FOUND if the critic is triggered, otherwise NO_PROBLEM.

getClarifier

public Icon getClarifier()
Return the icon to be used for the clarifier for this critic.

A clarifier is the graphical highlight used to show the presence of a critique. For example wavy colored underlines beneath operations.

In this case it will be a wavy line under the second of the clashing operations.

Specified by:
getClarifier in interface Poster
Overrides:
getClarifier in class Critic
Returns:
The Icon to use.
See Also:
Poster.getClarifier()

signaturesMatch

private boolean signaturesMatch(Object op1,
                                Object op2)
Sees if the signatures of two Operations are the same.

Checks for matching operation name, and list of parameter types. The order of the parameters is significant. This version also checks for the parameter kind, since otherwise, "op(int a)" and "op():int" appear to have the same signature. Purists would probably suggest that the kind should match exactly. However we only differentiate the return parameter(s). It is unlikely that any practical OO language would be able to distinguish instantiation of in from out from inout parameters.

We ignore return parameters completely. This is in line with Java/C++ which regard int x(int, int) and double x(int, int) as having the same signature.

If you need to modify this method, take care, since there are numerous "telegraph pole" problems involved in working through pairs of mixed lists.

Parameters:
op1 - the first operation whose signature is being compared.
op2 - the second operation whose signature is being compared.
Returns:
true if the signatures match, false otherwise.


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook