Patternity Source Code Examples

 

Autoimplemente

MyBean.java

/**
* A simple bean class
*
* @pattern autoimplemente
*/
public class MyBean implements Startable{
...


Startable.java

/**
* A simple interface with start() methods.
*/
public interface Startable{

/** Computes the result with TVA */
public void start(float a,String s);

/** Computes the result with TVA */
public void start(float a);
...

run Patternity...

/**
* A simple bean class
*
* @pattern autoimplemente
*/
public class MyBean implements Startable{

/** Computes the result with TVA **/
public void start(float a,java.lang.String s) {
  ;
}

/** Computes the result with TVA **/
public void start(float a) {
  ;
}
...

Visitor

MyBean.java

/**
* A simple Visitor class
*
* @pattern Visitor node=Visitable
*/
public class MyVisitor {
...


Node.java

public class Node implements Visitable{ ...


OtherNode.java

public class OtherNode implements Visitable{ ...


run Patternity...

MyBean.java

/**
* A simple Visitor class
*
* @pattern Visitor node=Visitable
*/
public class MyVisitor {
...
/** The visitor method to handle the OtherNode object. **/
public void visit(OtherNode o) {
   ;
}

/** The visitor method to handle the Node object. **/
public void visit(Node o) {
   ;
}
...

Getter and Setter


/**
* @get
* @set
*/
protected String name= "";

/**
* @get
* @set
*/
protected String secondName= "";

public String getName(){return name;} //already exists!
...

run Patternity...

/** Sets the name. **/
public void setName(String name) {
   this.name = name;
}

/** Gets the secondName. **/
public String getSecondName() {
   return this.secondName;
}

/** Sets the secondName. **/
public void setSecondName(String secondName) {
   this.secondName = secondName;
}
...

IfProxy

MyBean.java

...
/**
* @set
* @pattern IfProxy
*/
protected Node deleguee = null;
...


Node.java

/**
* A simple node class
*/
public class Node{

/** Computes the result with TVA */
public void dump(float a,String s){;}
}

run Patternity...

MyBean.java

...
/** Computes the result with TVA **/
public void dump(float a,java.lang.String s) {
   if(true){
     this.deleguee.dump(a,s);
  }
}
...
/** Sets the deleguee. **/
public void setDeleguee(Node deleguee) {
  this.deleguee = deleguee;
}
...

Composite

MyBean.java

...
/**
* @get
* @pattern Composite
*/
protected Rendable[] children = null;
...

Rendable.java

/**
* A simple interface with render() methods.
*/
public interface Rendable{

/** Computes the result with TVA */
public void render(Node n,Node n2);

/** Computes the result with TVA */
public void render(Node n);

}

run Patternity...

MyBean.java

...
/** Computes the result with TVA **/
public void render(examples.Node n,examples.Node n2) {
  for(int i=0;i<this.children.length;i++){
    Rendable o = this.children[i];
    o.render(n,n2);
  }
}

/** Computes the result with TVA **/
public void render(examples.Node n) {
  for(int i=0;i<this.children.length;i++){
    Rendable o = this.children[i];
    o.render(n);
  }
}
...
/** Gets the children. **/
public Rendable getChildren() {
  return this.children;
}
...