...create a new critique?
Currently the only way to add a new critique is to write a class that
implements it so that is described here.
There have however been ideas on a possibility to build critics in
some other way in the future, as a set of rules instead of java code.
Create a new critic class, of the form
CrXxxxYyyyZzzz,
extending CrUML.
Typically your new class will go in the package
org.argouml.uml.cognitive.critics,
but it could go in one of the other
cognitive.critics packages.
Write a constructor, which takes no arguments and calls the following
methods of CrUML:
setHeadline("");
to set up the locale specific text for
the critic headline (the one liner that appears in the to-do pane)
and
the critic description (the detailed explanation that appears in
the to-do tab of the details pane).
The String parameter is ignored.
addSupportedDecision(UMLDecision.decAAAA);
where AAAA is the design issue category
this critic falls into
(examples include STORAGE, PATTERNS, METHODS).
setPriority(ToDoItem.BBB_PRIORITY);
where BBB is one of
LOW, MEDIUM or
HIGH, to set the priority for the critic
in the to-do pane.
addTrigger("UML Meta-Class");
where UML Meta-Class is a UML Meta-Class,
with initial lower capital, e.g. "associationEnd".
The intention is that critics should only trigger for elements (or
children) of particular UML meta-classes.
I (Jeremy Bennett February 2002) believe this code is not yet working
so you can probably leave it out.
You can have multiple calls to this method for different meta-classes.
After this add a method
public boolean predicate2(Object dm, Designer dsgr);.
This is the decision routine for the critic.
The parameter
dm
(short for Design Material)
is the UML entity (a Model subsystem object)
that is being checked.
The second argument, dsgr
(short for Designer)
is for future
development and can be ignored.
The Critic class conveniently defines
two boolean constants
NO_PROBLEM and
PROBLEM_FOUND to be returned
according to whether the object is OK, or triggers the critic.
The parameter
dm may be any UML object,
so the first action is to see if it is an
artifact of interest and if not return
NO_PROBLEM.
The remaining code should examine dm and
return NO_PROBLEM or
PROBLEM_FOUND as appropriate.
Having written the code you need to add the text for the headline and
description to the cognitive resource bundles.
These are in the package
org.argouml.i18n,
in the file
critics.properties.
You need to add two keys for the head and description,
which will be named respectively
critics.CrXxxxxYyyyZzzz-head
and
critics.CrXxxxxYyyyZzzz-desc.
There are plenty of examples to look at there.
Headlines shall be unique, see issue 618.
The other files
for
British English,
Spanish, ...
respectively)
are the responsibility of the corresponding language team.
Notify the language teams that there is work to be done.
In method Init
of the class org.argouml.uml.cognitive.critics.Init,
add two statements:
private static Critic crXxxxxYyyyZzzz = new CrXxxxxYyyyZzzz();
...
Agency.register(crXxxxxYyyyZzzz, DesignMaterialCls);
If you want to add a critic to a design material
which is not already declared (for example the Extend class),
you will have to add a third statement to the
Init method as well, which is:
java.lang.Class XxxYyyyZzCls = MXxxYyyyZzImpl.class;
where MXxxYyyyZzImpl.class should be part of the NovoSoft UML package.
Finally you should get a new section added to the user manual reference
section on critics.
The purpose of this is to collect all the details and rationale around
this critic to complement the short text in the description.
It should go in the ref_critics.xml file and have an id tag
named critics.CrXxxYyyyZzzz.
...write the test in a critique?
The critiques tests are essentially a combination of conditions
that are to be fulfilled.
The conditions are often simple tests on simple model elements.
The class
org.argouml.cognitive.critics.CriticUtils
contains static routines that are commonly needed when writing
predicate2
(for example to test if a class has a constructor).
If you find you are writing code that may be of wider use than just
your critic, you should add it to
CriticUtils
rather than putting it in your critic.
For commented examples to copy, look at
org.argouml.pattern.cognitive.critics.CrConsiderSingleton,
org.argouml.pattern.cognitive.critics.CrSingletonViolated and
org.argouml.uml.cognitive.critics.CrConstructorNeeded.