PremChaRM
Class PremChaRM

java.lang.Object
  |
  +--openjava.mop.OJClass
        |
        +--PremChaRM.PremChaRM

public class PremChaRM
extends OJClass

This class represents the OpenJava Preprocessor for a class containing the mChaRM mechanism. Its role is to translate the OpenJava class who instantiates it (which is a class written in an extended syntax of java) into three pure-java classes. The whole class contains methods and objects representing the mChaRM objects Core Channel, Sender and Receiver. The classes created by PremChaRM represent these objects and they are obtained sharing out methods and fields according the use they did. A method or a field is put into a class only if it is really used by respective mChaRM object.

Author:
Valentina Cordì (1996s081@educ.disi.unige.it), Maurizio Mazza (1996s065@educ.disi.unige.it), Roberto Montagna (1996s063@educ.disi.unige.it)

Field Summary
private static int CLASSNAME
          This constant represent name class. it is an index of memory structure that contains information about index classes
private static int CORE
          This constant represent the core.
private  OJMethod[] coreMethods
          This array contains all methods of create Core class.
private static int ENRICHNAME
          This constant represent the enriches clause.
private  ObjectList ExtendedSyntax
          This variable contains the parse tree reapresentanting the extedend syntax.
private  boolean firstTime
          During a process that translate class that contains main, is possible that in several situation the programm need information contained in OJMI, this flag used in combination of function HandleFirstTime( String ) permitt to access to information only one time.
private  boolean[] isDefined
          Every cell of array meaning that relative output Class is defined.
private static int KIND
          This constant represent the kind.
private static java.lang.String[] NAME_BASE_CLASSES
          This array of constant contains the names of base classes.
private static java.lang.String[] NAME_START_METHODS
          This array of constant contains the names of the base methods.
private  OJField[] ojFields
          This variable contains all fields of starting class.
private  PreGraph ojGraph
          Instance of Graph, is used to check the consistence of an access to fields.
private  java.util.Vector ojMethods
          This Vector contains all the method declared in base class
private  java.util.Vector ojMethodsCore
          This Vector contains the method of hierarchy of the Core.
private  java.util.Vector ojMethodsReceiver
          This Vector contains the method of hierarchy of the Receiver.
private  java.util.Vector ojMethodsSender
          This Vector contains the method of hierarchy of the Sender.
private  java.lang.String[] OJMIclassNames
          This array contains name of output class create during a translating process.
private  OJSubClass ojsCore
          This OJSubClass contains, if present, the new class CORE
private  OJSubClass ojsReceiver
          This OJSubClass contains, if present, the new class RECEIVER
private  OJSubClass ojsSender
          This OJSubClass contains, if present, the new class SENDER
private static int PROVIDESNAME
          This constant represent the provides clause.
private static int RECEIVER
          This constant represent the receiver.
private static int SENDER
          This constant represent the sender.
 
Fields inherited from class openjava.mop.OJClass
substance
 
Constructor Summary
PremChaRM(java.lang.Class oj_param0, MetaInfo oj_param1)
           
PremChaRM(Environment oj_param0, OJClass oj_param1, ClassDeclaration oj_param2)
           
 
Method Summary
private  java.util.Vector cascadeMethods(OJClass ojClass)
          This method return all method declared in a class hierarchy.
private  void changeReferenceExpr(Expression call, Environment env)
          This method do a recursive parsing to find typeName to change.
 Expression expandAllocation(Environment env, AllocationExpression expr)
          This method is invoked on every AllocationExpression instance of start class.
 Expression expandMethodCall(Environment env, MethodCall call)
          This method is invoked on every MethodCall instance of start class not tested yet.
 TypeName expandTypeName(Environment env, TypeName type)
          This method is invoked on every TypeName instance of start class.
 Statement expandVariableDeclaration(Environment env, VariableDeclaration var)
          This method is invoked on every VariableDeclaration instance of start class.
static SyntaxRule getDeclSuffixRule(java.lang.String keyword)
          Function predefined in OJClass, is used to get a parse tree of added syntax.
 void HandleFirstTime(java.lang.String expr)
          This method takes the info in OJMI file of sterting class.
private  void insertConstructorMethods(int className)
          This method finds particulary methods representing constructors.
private  void insertLateBindingMethods(int className)
          This method find methods, in start class, that override someone else in hierarchy class specified by className.
private  void insertMethodsFrom(OJMethod ojMethod, int className)
          This method insert in graph the starting method and all method called in.
static boolean isRegisteredKeyword(java.lang.String keyword)
          Function predefined in OJClass, is used to check if the keyword present in added syntax regard current OJClass
 OJMethod methodCall2OJMethod(MethodCall mcMethod, Environment environment)
          This method perform the translation of MethodCall into OJMethod.
 void openClasses()
          This method create the output class.
 java.lang.String[] parseConstr(java.lang.String constr)
           
 java.lang.String parseConstr(java.util.StringTokenizer strToken, char stop)
           
private  void prepareClasses()
          This method makes two different works: first, it initializes the three output classes inserting import clauses and the relative constructor; then it creates graphs for methods and fields, finally inserts right fields and methods in relative class.
private  void prepareMainClass()
          This method delete main class and add three instance of the generated classes.
private  void printClasses()
          This method write on file the code of the three classes if they are defining.
 void translateDefinition()
          This is the starting point of pre-compiling.
 
Methods inherited from class openjava.mop.OJClass
addClass, addConstructor, addField, addInterface, addMethod, arrayForClasses, expandArrayAccess, expandArrayAllocation, expandAssignmentExpression, expandCastedExpression, expandCastExpression, expandExpression, expandFieldRead, expandFieldWrite, forClass, forName, forObject, forParseTree, getAcceptableConstructor, getAcceptableMethod, getAllClasses, getAllField, getAllFields, getAllMethod, getAllMethods, getAllMethods, getByteCode, getClasses, getClasses, getClassLoader, getCompatibleJavaClass, getComponentType, getConstructor, getConstructor, getConstructors, getConstructors, getDeclaredClasses, getDeclaredConstructor, getDeclaredConstructors, getDeclaredField, getDeclaredFields, getDeclaredMethod, getDeclaredMethods, getDeclaringClass, getEnvironment, getField, getField, getFields, getFields, getInheritableClasses, getInheritableClasses, getInheritableConstructors, getInheritableFields, getInheritableFields, getInheritableMethods, getInheritableMethods, getInheritedClasses, getInheritedFields, getInheritedMethods, getInterfaces, getMetaInfo, getMetaInfoElements, getMetaInfoKeys, getMethod, getMethod, getMethods, getMethods, getModifiers, getName, getPackage, getResource, getResourceAsStream, getSigners, getSimpleName, getSourceCode, getSuffix, getSuperclass, getTypeSuffixRule, isAlterable, isArray, isArrayName, isAssignableFrom, isExecutable, isInSamePackage, isInstance, isInterface, isPrimitive, isPrimitiveWrapper, isRegisteredModifier, lookupFromByteCode, lookupFromMetaInfo, makeCopy, makeExpression, makeExpression, makeStatement, makeStatement, makeStatementList, makeStatementList, nameForJavaClassName, nameToJavaClassName, newInstance, overridesOn, overridesOn, overridesOn, pickupAcceptableConstructor, pickupAcceptableMethod, pickupConstructor, pickupField, pickupMethod, pickupMethodsByName, primitiveTypeWidth, primitiveWrapper, putMetaInfo, removeClass, removeConstructor, removeField, removeMethod, removeTheDefaults, removeTheDefaults, removeTheDefaults, removeTheDefaults, removeTheNonPublics, removeTheNonPublics, removeTheNonPublics, removeTheNonPublics, removeThePrivates, removeThePrivates, removeThePrivates, removeThePrivates, replaceDotWithDoller, resolveException, resolveException, setDeclaringClass, setInterfaces, setName, setSuperclass, signature, stripBrackets, toClasses, toString, translateDefinition, unwrappedPrimitive, waitTranslation, writeMetaInfo
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

KIND

private static final int KIND
This constant represent the kind.

CORE

private static final int CORE
This constant represent the core.

SENDER

private static final int SENDER
This constant represent the sender.

RECEIVER

private static final int RECEIVER
This constant represent the receiver.

CLASSNAME

private static final int CLASSNAME
This constant represent name class. it is an index of memory structure that contains information about index classes

ENRICHNAME

private static final int ENRICHNAME
This constant represent the enriches clause. It used during the parsing of added syntax.

PROVIDESNAME

private static final int PROVIDESNAME
This constant represent the provides clause. It used during the parsing of added syntax.

NAME_START_METHODS

private static final java.lang.String[] NAME_START_METHODS
This array of constant contains the names of the base methods. This array is indexed over the constants:

NAME_BASE_CLASSES

private static final java.lang.String[] NAME_BASE_CLASSES
This array of constant contains the names of base classes. This class is used to default enrich. This array is indexed over the constants:

ojsCore

private OJSubClass ojsCore
This OJSubClass contains, if present, the new class CORE

ojsSender

private OJSubClass ojsSender
This OJSubClass contains, if present, the new class SENDER

ojsReceiver

private OJSubClass ojsReceiver
This OJSubClass contains, if present, the new class RECEIVER

ojMethods

private java.util.Vector ojMethods
This Vector contains all the method declared in base class

ojMethodsCore

private java.util.Vector ojMethodsCore
This Vector contains the method of hierarchy of the Core. It contains all methods of all class, beginnig to enriches CORE ending with NAME_BASE_CLASSES relative

ojMethodsSender

private java.util.Vector ojMethodsSender
This Vector contains the method of hierarchy of the Sender. It contains all methods of all class, beginnig to enriches SENDER ending with NAME_BASE_CLASSES relative

ojMethodsReceiver

private java.util.Vector ojMethodsReceiver
This Vector contains the method of hierarchy of the Receiver. It contains all methods of all class, beginnig to enriches RECEIVER ending with NAME_BASE_CLASSES relative

coreMethods

private OJMethod[] coreMethods
This array contains all methods of create Core class. It use during a translating main class, to check if the methods invoke over an instance of Start class are present in Core class generated.

OJMIclassNames

private java.lang.String[] OJMIclassNames
This array contains name of output class create during a translating process. It use during a translating of main class, to find a name of new class and change the allocatition and invocation of static methods inside the main class.

ojGraph

private PreGraph ojGraph
Instance of Graph, is used to check the consistence of an access to fields. The prepocessor insert the information into the graph using some utils and check the consistence of an access to fields using member function of PreGraph.

ExtendedSyntax

private ObjectList ExtendedSyntax
This variable contains the parse tree reapresentanting the extedend syntax. It contains all information about name of output class and name of enriches class.

ojFields

private OJField[] ojFields
This variable contains all fields of starting class.

isDefined

private boolean[] isDefined
Every cell of array meaning that relative output Class is defined.

firstTime

private boolean firstTime
During a process that translate class that contains main, is possible that in several situation the programm need information contained in OJMI, this flag used in combination of function HandleFirstTime( String ) permitt to access to information only one time.
Constructor Detail

PremChaRM

public PremChaRM(Environment oj_param0,
                 OJClass oj_param1,
                 ClassDeclaration oj_param2)

PremChaRM

public PremChaRM(java.lang.Class oj_param0,
                 MetaInfo oj_param1)
Method Detail

isRegisteredKeyword

public static boolean isRegisteredKeyword(java.lang.String keyword)
Function predefined in OJClass, is used to check if the keyword present in added syntax regard current OJClass
Parameters:
keyword - String that must be check
Returns:
true if the keyword is correct

getDeclSuffixRule

public static SyntaxRule getDeclSuffixRule(java.lang.String keyword)
Function predefined in OJClass, is used to get a parse tree of added syntax.
Parameters:
keyword - start String of added syntax
Returns:
the parse tree contains all added syntax

openClasses

public void openClasses()
This method create the output class. It starting after that the added syntax is parsing, it create and initialize the output class.
The new class is insert ipn instance of OJSubClass
See Also:
OJSubClass

prepareClasses

private void prepareClasses()
This method makes two different works: first, it initializes the three output classes inserting import clauses and the relative constructor; then it creates graphs for methods and fields, finally inserts right fields and methods in relative class. In the first phase it finds all method belong to the superclass o the three output class calling cascadeMethods, finally it create the three constructor. In the last phase it divides all member of start class, to do that first find late Binding methods and then for each method founded search all method called in. At this time for each method founded search all fields used in. If there are multi-referred fields it indicate a Fatal Error and terminate the esecution otherwise it splits the whole classe in three classes.

cascadeMethods

private java.util.Vector cascadeMethods(OJClass ojClass)
This method return all method declared in a class hierarchy. To do that it call itself recursively, stops when find a Base class.
Parameters:
ojClass - Class whom find methods
Returns:
Vector contains all methods declared
See Also:
array that contains base class

insertConstructorMethods

private void insertConstructorMethods(int className)
This method finds particulary methods representing constructors.
Parameters:
className - name of class where it search the overridden methods

parseConstr

public java.lang.String[] parseConstr(java.lang.String constr)

parseConstr

public java.lang.String parseConstr(java.util.StringTokenizer strToken,
                                    char stop)

insertLateBindingMethods

private void insertLateBindingMethods(int className)
This method find methods, in start class, that override someone else in hierarchy class specified by className. In particulary for each method, in hierarchy class specified by className, it searchs once in start class that is equals to him ( same parameters, same name ).
Parameters:
className - name of class where it search the overridden methods

insertMethodsFrom

private void insertMethodsFrom(OJMethod ojMethod,
                               int className)
This method insert in graph the starting method and all method called in. It does the transitive closure of ojMethod.
Parameters:
ojMethod - starting method to find all methods invoked in.
className - name of class that contains starting method

methodCall2OJMethod

public OJMethod methodCall2OJMethod(MethodCall mcMethod,
                                    Environment environment)
This method perform the translation of MethodCall into OJMethod. This translation is done only if the MethodCall deals a method belong to start class, otherwise it return null. To do the translation it searchs a OJMethod with same name and same parameters type.
Parameters:
mcMethod - MethodCall to translate in OJMethod
environment - current Environment
Returns:
OJMethod invoked by specified MethodCall.

prepareMainClass

private void prepareMainClass()
This method delete main class and add three instance of the generated classes. It does that to force the classes compiling

printClasses

private void printClasses()
This method write on file the code of the three classes if they are defining.

translateDefinition

public void translateDefinition()
This is the starting point of pre-compiling. Initially it checks th syntax, then creates and initializes the output classes, finally it prints\ all three classes and prepare main class. All this things are doing using several methods.
Overrides:
translateDefinition in class OJClass

expandVariableDeclaration

public Statement expandVariableDeclaration(Environment env,
                                           VariableDeclaration var)
This method is invoked on every VariableDeclaration instance of start class. It change type of Declaration into Core Type.
Parameters:
env - current Environment
var - current VariableDeclaration
Overrides:
expandVariableDeclaration in class OJClass

expandTypeName

public TypeName expandTypeName(Environment env,
                               TypeName type)
This method is invoked on every TypeName instance of start class. It change type name into Core Type.
Parameters:
env - current Environment
type - current TypeName
Overrides:
expandTypeName in class OJClass

expandAllocation

public Expression expandAllocation(Environment env,
                                   AllocationExpression expr)
This method is invoked on every AllocationExpression instance of start class. It earch the constructor and change it into a new constructor of Core class. To do that change name of current constructor and add it three parameters, KIND of Channel name of SENDER and RECEIVER.
Parameters:
env - current Environment
expr - current AllocationExpression
Overrides:
expandAllocation in class OJClass

expandMethodCall

public Expression expandMethodCall(Environment env,
                                   MethodCall call)
This method is invoked on every MethodCall instance of start class not tested yet. It check if a method is static, if so it translate it, otherwise don't make anything. To translate calling changeReferenceExpr
Parameters:
env - current Environment
call - current MethodCall
Overrides:
expandMethodCall in class OJClass

HandleFirstTime

public void HandleFirstTime(java.lang.String expr)
This method takes the info in OJMI file of sterting class. This method is performs only once.
Parameters:
expr - string representig the Core name

changeReferenceExpr

private void changeReferenceExpr(Expression call,
                                 Environment env)
This method do a recursive parsing to find typeName to change. When find it delete it, because an instance of class can access to static member.
Parameters:
call - Expression
env - current Environment