UmpleModelFilter

Timothy Lethbridge edited this page Jun 14, 2016 · 2 revisions
Clone this wiki locally

Introduction

This page is to present proposed syntax for the filter(diagram) to an Umple model. A feature for this was implemented, so this page is for the historical reference and may be deleted.

In addition, if any of these filters are applied, it restricts any generated code to just involve the classes considered.

Details

Using this filter feature it should be possible to generate gv class diagrams for

a) Just a particular set of classes/interfaces, and the associations/generalizations/ among them

b) Just a set of classes and neighbouring or tree of classes (by association/generalization/etc).

c) Just the classes in the selected namespaces/packages

Gv state diagrams would just have state machines from those classes.

And code generated would be just from a particular subsystem

Proposed Syntax Examples

Example 1 Default When No Filter Provided:

// include everything of an umple model
filter
{
 include *;
}

which is equivalent to

filter
{
}

Which is also equivalent to having absolutely no filter in effect, i.e. the status quo.

Example 2 Include Parts of the Model:


// include every class, interface, or trait starting with A, entire superclass hierarchy of these classes, and any relationships between them (if any)

filter name_a
{
  include A*;
}

//super is set to * and sub is set to 0 by default

filter name_a
{
  hops{
    super *;
    sub 0;
  }

  include A*;
}

//how far in the superclass hierarchy included in the filter can be set separately; the following example include the parent and children that is 1 hop from A*

filter name_a
{
  hops{
    super 1;
    sub 1;
  }
 include A*
}

//include every class, interface, or trait starting with A, entire superclass hierarchy and any direct associations with these classes

filter name_a
{
  hops{
    association 1;
  }
  include A*;
}

// the following one include every class starts with A and classes that are two elements apart

filter name_a
{
  hops{
    association 2;
  }
  include A*;
}

// the following include class AAA and BBB, entire superclass hierarchy of them and associations between them.

filter name_ab
{
  include AAA, BBB;
}

// include every class that does not start with A and their entire superclass hierarchy

filter name_na
{
  include !A*;
}

Example 3 Combining Filters

filter name_a
{
  hops{
    super *;
    sub 1;
    association 1;
  }
  include AAA;
}

filter name_b
{
  hops{
    super 1;
    sub 0;
  }

  include BBB;
}

//combining filter name_a and name_b with their parent, children and association setting

filter name_c
{
  filter name_a, name_b;
}

//overwrite the parents, children and association setting in the runtime
filter name_c
{
  hops{
    super *;
    sub 0;
    association 1;
  }
  filter name_a, name_b;
}

Example 5 Namespace

//include everything in the provided namespaces

filter namespace
{
 namespace n_a, n_b;
}

Proposed Syntax


filter : filter ( [filterName] )? { ([[filterStatement]])* }

filterStatement- : [[filterCombinedValue]] | [[filterNamespace]] | [[filterValue]] | [[hops]]

filterValue : include ([classname])? ( , [classname] )*;

hops- : hops {([[super]] | [[sub]] | [[association]])*}

super : super [superNum];

sub : sub [subNum];

association : association [associationNum];

filterCombinedValue : filter ([filterName])? (, [filterName])*;

filterNamespace : namespace [Namespace] (, [Namespace])*;

Invoking Filters

Umple Filter Syntax

Examples:

//umple file: example.ump

class School{
  name;
}

class Student{
}

class Mentor{
  1 -- * Student;  
}

//this filter includes Student, Mentor, and the association between them
filter Roles
{
  include Student, Mentor;
}

//the following would be equivalent using mixins
filter People
{
  include Student;
}

filter People
{
  include Mentor;
}

filter Organizations
{
  include School;
}

Umple Apply Syntax

Much like for generating code, there will be an apply keyword that is used to active filter(s).

// Activate the Roles filters
apply Roles;

// Activate the Roles and Organizations filters
apply Roles, Organizations;

Umple CLI Example

The command line will support -a / --apply option to apply a particular filter. The code below would result in the same two filter applications as shown above

// Activate the Roles filters (from command line)
java -jar umple.jar --apply Roles example.ump

// Activate the Roles and Organizations filters
java -jar umple.jar --apply Roles,Organizations example.ump

Note that un-named filters would always be applied. And filters support mixins, so duplicately named filters would be combined and compile time.