Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
research:software:reflex:documentation:structural_model [2007/08/13 16:20] – created adminresearch:software:reflex:documentation:structural_model [2007/08/20 14:42] (current) admin
Line 1: Line 1:
 +====== Structural Model ======
  
 +The Reflex structural model is a set of classes that reifies the different structures of an application: RClass objects gives access to their members as [[http://reflex.dcc.uchile.cl/svn/base/trunk/src/reflex/api/model/RMember.java|RMember]] objects (either [[http://reflex.dcc.uchile.cl/svn/base/trunk/src/reflex/api/model/RField.java|RField]], [[http://reflex.dcc.uchile.cl/svn/base/trunk/src/reflex/api/model/RMethod.java|RMethod|]], or [[http://reflex.dcc.uchile.cl/svn/base/trunk/src/reflex/api/model/RConstructor.java|RConstructor]]), which in turn give access to their bodies as RExpr objects (with a specific type foreach kind of expression). 
 +
 +In the following figure we can see this structure:
 +
 +{{ research:software:reflex:documentation:structural-model.png }}
 +
 +We will review the most important part of the API of each class. Notice that this objects are passed as paramenters to Selectors, and then, they can reason over any property the //R*// classes give access to.
 +
 +=====  RClass =====
 +
 +We have divided the methods of RClass in four categories related to: structure, fields, contructors and methods. Let us review them in detail.
 +
 +====  Structure ====
 +
 +<code java>
 +public RClass getSuperclass()
 +</code>
 +This method gives access to the class superclass. If the current class is ''java.lang.Object'', this method returns null. If it represents an interface, it always returns ''java.lang.Object''.
 +<code java>
 +public void setSuperclass(RClass aClass)
 +</code>
 +This method changes the superclass of the current class. This class must be compatible (for example, if the superclass defines abtract methods, the current class has to implement them before calling this method). If the current class represents an interface, this method is equivalent to call ''addInterface''.
 +<code java>
 +public RClass[] getInterfaces()
 +</code>
 +This method returns the interfaces implemented by the current class. A empty array is returned if this class does not implement any interface. If the current class represents an interface, the super interfaces are returned.
 +<code java>
 +public void addInterface(RClass aInterface)
 +</code>
 +This method adds a interface to the current class. All methods defined by the interface must be already implemented in the class.
 +
 +====  Fields ====
 +
 +<code java>
 +public RField getDeclaredField(String name)
 +</code>
 +This method returns the field with the given name.
 +<code java>
 +public RFieldIterator getFieldIterator()
 +</code>
 +This method returns an iterator over all fields declared in the current class.
 +<code java>
 +public void addField(RField aField)
 +</code>
 +This method adds a new field to the current class.
 +<code java>
 +public void addField(RField aField, String aInit)
 +</code>
 +This method adds a field to the current class. The second parameter is the initialization code of the field.
 +
 +====  Constructor ====
 +
 +<code java>
 +public RConstructorIterator getConstructorIterator()
 +</code>
 +This method returns an iterator over the constructors of the current class.
 +<code java>
 +public void addConstructor(RConstructor aConstructor)
 +</code>
 +This method adds a contructor to the current class.
 +
 +====  Method ====
 +
 +<code java>
 +public RMethod getDeclaredMethod(String aName)
 +</code>
 +This method returns the method with the given name and does not take any parameters.
 +<code java>
 +public RMethod getDeclaredMethod(String aName, RClass[] aParams)
 +</code>
 +This method returns the method with the given name and that takes parameters of the given types.
 +<code java>
 +public void addMethod(RMethod aMethod)
 +</code>
 +This method adds a method to the current class.
 +
 +=====  RField =====
 +
 +<code java>
 +public RClass getType()
 +</code>
 +This method returns the type of the current field.
 +
 +=====  RConstructor =====
 +
 +<code java>
 +public boolean isDefaultConstructor();
 +</code>
 +This method returns true if the current contructor is the default one, ie, the one that does not take any parameters.
 +<code java>
 +public boolean isClassInitializer();
 +</code>
 +This class returns true if this constructor represents a static class initializer. This method is present because constructor and static initializers are both reified using RConstructor objects.
 +<code java>
 +public void insertBeforeBody(String aCode);
 +</code>
 +This method adds the given source code to the begining of the current constructor.
 +
 +=====  RMethod =====
 +
 +<code java>
 +public RClass getReturnType()
 +</code>
 +This method returns the return type of the current method.
 +<code java>
 +public void setName(String aName)
 +</code>
 +This method changes the name of the current method.
 +<code java>
 +public void setModifiers(int aModifiers)
 +</code>
 +This method changes the modifiers of the current method. The specified modifiers are enconded as an ''int'' as in ''java.lang.reflect.Modifier''.