This is an old revision of the document!
Table of Contents
PADL
PADL stands for Pattern and Abstract-level Description Language. It is a meta-model to describe programs at different levels of abstractions.
Levels of Models
There are four different levels of abstractions to model programs, collectively called abstract-level models:
- A
ICodeLevelModelrepresents the “raw” model of a program, including only data directly extractable from the program source representation (Java bytecodes, Java source code, C/C++ source code…);
- A
IIdiomLevelModelrepresents a model of a program where some idioms have been reified, typically binary-class relationships computed using some analyses;
- A
IDesignLevelModelrepresents a model of a program where design information is available. Typical design information is obtained from the idiom-level model, for example occurrences of design motifs or of code and design smells;
- A
IDesignMotifrepresents a design motif, i.e., the solution to a design pattern model inPADL Design Motifs.
The following diagram shows the hierarchy of the interface describing models. (This hierarchy has been built using the project Ptidej UI Viewer Standalone Swing.) The root of the models is the interface IAbstractModel, which describes any model that could be handled by most of Ptidej analyses and tools. This interface abstracts IAbstractLevelModel, which represents models of programs, and IDesignMotif, which represents models of design motifs.
The PADL project also provides the interfaces:
ICodeLevelModelCreator, along withpadl.kernel.ICodeLevelModel.create(ICodeLevelModelCreator), is an implementation of the Builder design pattern, to provide a unified interface to create PADL models. Creators exist for Java bytecodes as well as other representations, such as AOL files, AspectJlstfiles, C/C++ and Java source code…
Binary Class Relationships
The PADL meta-model includes an extensive hierarchy of interfaces to describes binary class relationships. The following figure highlights these relationships. (This hierarchy has been built using the project Ptidej UI Viewer Standalone Swing.) Of particular interest are the following relationships, presented in order from the most constraining to the least constraining. Whenever a relationship is identified between two entities, the following least constraining relationships are not included. For example, if an aggregation relationships exists between two classes A and B, no corresponding use relationship would exist:
IContainerCompositiondescribes a relationship between two classesAandBsuch as A holds the unique reference(s) to (an) instance(s) ofBand plays the role of container, providing method to add/remove instances ofB;
ICompositiondescribes a relationship between two classesAandBsuch asAholds the unique reference(s) to (an) instance(s) ofB;
IContainerAggregationdescribes a relationship between two classesAandBsuch asAholds (possibly shared) reference(s) to (an) instance(s) ofBand plays the role of container, providing method to add/remove instances ofB;
IAggregationdescribes a relationship between two classesAandBsuch asAholds (possibly shared) reference(s) to (an) instance(s) ofB;
IAssociationa relationship between two classesAandBsuch as A calls some methods ofBusing (an) instance(s) ofB;
ICreationa relationship between two classesAandBsuch asAcreate (an) instance(s) ofB;
IUseRelationshipa relationship between two classesAandBsuch asAuses in some way, for example by declaring a method with a parameter of typeB, (an) instance(s) of classB.
The existence of binary class relationships is inferred from an ICodeLevelModel based on the presence of certain fields and methods and method invocations in classes by the padl.analysis.repository.AACRelationshipsAnalysis.
Generators and Walkers
The PADL meta-model provides you with two distinct but related visitors: padl.visitor.IGenerator and padl.visitor.IWalker. Both visitors inherit from padl.visitor.IVisitor but provide different methods to retrieve the results of the visit: getCode() and getResult(), respectively. A typical example of using one of these visitors is:
final IWalker walker = new InheritanceImplementationCounter();
final ICodeLevelModel codeLevelModel =
Primitive.getFactory().createCodeLevelModel("");
codeLevelModel.create(
new CompleteClassFileCreator(
DefaultFileRepository.getInstance(),
new String[] { path },
true));
final IIdiomLevelModel idiomLevelModel =
(IIdiomLevelModel) new AACRelationshipsAnalysis().invoke(codeLevelModel);
walker.reset();
idiomLevelModel.walk(walker);
System.out.println(walker.getResult());
Obviously, the class padl.creator.classfile.test.creator.InheritanceImplementationCounter implements padl.visitor.IWalker.
Method Invocations
As part of an effort to improve code representation in PADL. The concept of method invocation has been added since 2004-2005. An interface padl.kernel.IMethodInvocation represents method invocations. This concept is as-of-today not quite clean and is used to describes both method invocations and field accesses. Therefore, the interface padl.kernel.IMethodInvocation (and its reference implementation) includes:
- a
padl.kernel.IMethodcontainer that is the calling method (in which the method invocation can be found.) (Dirty Hack.)
- a
int cardinalityvalue that describes the cardinality of the call- 1 = unique call;
- 2 = repetitions of the call;
- a
int typevalue that characterises the type of method invocation:CLASS_CLASS: method invocation from a class method to another class method;CLASS_CLASS_FROM_FIELD: method invocation from a class method to another class method through a class variable;CLASS_INSTANCE: method invocation from a class method to an instance method;CLASS_INSTANCE_FROM_FIELD: method invocation from a class method to an instance method through a class variable;INSTANCE_CLASS: method invocation from an instance method to a class method;INSTANCE_CLASS_FROM_FIELD: method invocation from an instance method to a class method through an instance variable;INSTANCE_CREATION: creation of a new instance;INSTANCE_INSTANCE: method invocation from an instance method to another instance method;INSTANCE_INSTANCE_FROM_FIELD: method invocation from an instance method to another instance method through an instance variable;OTHER: other things… such as field accesses! (Dirty Hack.)
- an
IEntity targetEntitythat references the entity declaring the called method. (Dirty Hack.)
- an
int visibilityvalues that is the visibility of the called method. (Dirty Hack.)
- an
IAbstractMethod calledMethodthat is a reference to the called method.
- a
List callingFieldsthat is a list of the fields (if any) through which the called method is invoked. (Fragile Code.)
- an
IEntity fieldDeclaringEntityreferencing theIEntitydeclaring the (last) field through which the called method is invoked. (Dirty Hack.)
Names and Paths
The getName() always returns the simple name of a constituent. For binary-class relationships and method invocations, the name returned by getName() is less important, it could simply be Method Invocation, for example. For a first-class entity, though, it is important, for example getName() returns Constituent for padl.kernel.IConstituent. Here are other examples of getName() values:
padlfor a package;
getName()for a method;
setName(char[])for a method;
namefor an attribute;
NaturalOrderComparatorfor a member class.
The paths are used to name and address each constituent uniquely within a model but consistently across models. The paths start with a '/' and the name of the model. Then, it includes the name, as in getName(), of each constituent to go through until the name of the current constituent is reached. Here are some examples of getPath() values:
/PADL|padlfor a package;
/PADL|padl|kernel|padl.kernel.IConstituent|getName()for a method;
/PADL|padl|kernel|padl.kernel.IConstituent|setName(char[])for a method;
/PADL|padl|kernel|impl|padl.kernel.impl.Constituent|namefor an attribute;
/PADL|padl|kernel|impl|padl.kernel.impl.GenericContainerOfNaturallyOrderedConstituents$NaturalOrderComparatorfor a member class.
The class padl.path.Finder in the PADL project can be used to walk the paths.


