Table of Contents

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 RMember objects (either RField, RMethod|, or 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:

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

public RClass getSuperclass()

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.

public void setSuperclass(RClass aClass)

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.

public RClass[] getInterfaces()

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.

public void addInterface(RClass aInterface)

This method adds a interface to the current class. All methods defined by the interface must be already implemented in the class.

Fields

public RField getDeclaredField(String name)

This method returns the field with the given name.

public RFieldIterator getFieldIterator()

This method returns an iterator over all fields declared in the current class.

public void addField(RField aField)

This method adds a new field to the current class.

public void addField(RField aField, String aInit)

This method adds a field to the current class. The second parameter is the initialization code of the field.

Constructor

public RConstructorIterator getConstructorIterator()

This method returns an iterator over the constructors of the current class.

public void addConstructor(RConstructor aConstructor)

This method adds a contructor to the current class.

Method

public RMethod getDeclaredMethod(String aName)

This method returns the method with the given name and does not take any parameters.

public RMethod getDeclaredMethod(String aName, RClass[] aParams)

This method returns the method with the given name and that takes parameters of the given types.

public void addMethod(RMethod aMethod)

This method adds a method to the current class.

RField

public RClass getType()

This method returns the type of the current field.

RConstructor

public boolean isDefaultConstructor();

This method returns true if the current contructor is the default one, ie, the one that does not take any parameters.

public boolean isClassInitializer();

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.

public void insertBeforeBody(String aCode);

This method adds the given source code to the begining of the current constructor.

RMethod

public RClass getReturnType()

This method returns the return type of the current method.

public void setName(String aName)

This method changes the name of the current method.

public void setModifiers(int aModifiers)

This method changes the modifiers of the current method. The specified modifiers are enconded as an int as in java.lang.reflect.Modifier.