+private void initializeOuterMember( MethodDescriptor md, String fieldName, String formalParameter ) {
+ BlockNode obn = state.getMethodBody(md);
+ NameNode nn=new NameNode( new NameDescriptor( fieldName ) );
+ NameNode fn = new NameNode ( new NameDescriptor( formalParameter ) );
+ //nn.setNumLine(en.getNumLine())
+ AssignmentNode an=new AssignmentNode(nn,fn,new AssignOperation(1));
+ //an.setNumLine(pn.getLine());
+ obn.addFirstBlockStatement(new BlockExpressionNode(an));
+ // System.out.print( "The code inserted is : " + obn.printNode( 0 ) + "\n" );
+ state.addTreeCode(md, obn);
+}
+
+private void addOuterClassParam( ClassDescriptor cn, ClassDescriptor ocn, int depth )
+{
+ Iterator nullCheckItr = cn.getInnerClasses();
+ if( false == nullCheckItr.hasNext() )
+ return;
+
+ //create a typedescriptor of type cn
+ TypeDescriptor theTypeDesc = new TypeDescriptor( ocn );
+
+ for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
+ ClassDescriptor icd=(ClassDescriptor)it.next();
+ if(icd.isStatic()||icd.getInStaticContext()) {
+ continue;
+ }
+
+ //iterate over all ctors of I.Cs and add a new param
+ for(Iterator method_it=icd.getMethods(); method_it.hasNext(); ) {
+ MethodDescriptor md=(MethodDescriptor)method_it.next();
+ if( md.isConstructor() ){
+ md.addParameter( theTypeDesc, "surrounding___DOLLAR___" + String.valueOf(depth) );
+ initializeOuterMember( md, "this___DOLLAR___" + String.valueOf( depth ), "surrounding___DOLLAR___" + String.valueOf(depth) );
+ //System.out.println( "The added param is " + md.toString() + "\n" );
+ }
+ }
+ addOuterClassParam( icd, ocn, depth + 1 );
+
+ }
+
+}
+private void addOuterClassReferences( ClassDescriptor cn, ClassDescriptor ocn, int depth )
+{
+ //SYMBOLTABLE does not have a length or empty method, hence could not define a hasInnerClasses method in classDescriptor
+ Iterator nullCheckItr = cn.getInnerClasses();
+ if( false == nullCheckItr.hasNext() )
+ return;
+
+ String tempCopy = ocn.getClassName();
+ //MESSY HACK FOLLOWS
+ int i = 0;
+
+ ParseNode theNode = new ParseNode( "field_declaration" );
+ theNode.addChild("modifier").addChild( new ParseNode( "modifier_list" ) ).addChild("final");
+ ParseNode theTypeNode = new ParseNode("type");
+ ParseNode tempChildNode = theTypeNode.addChild("class").addChild( "name" );
+ //tempChildNode.addChild("base").addChild( new ParseNode("empty") );
+ tempChildNode.addChild("identifier").addChild ( tempCopy );
+ theNode.addChild("type").addChild( theTypeNode );
+ ParseNode variableDeclaratorID = new ParseNode("single");
+ String theStr = "this___DOLLAR___" + String.valueOf( depth );
+ variableDeclaratorID.addChild( theStr );
+ ParseNode variableDeclarator = new ParseNode( "variable_declarator" );
+ variableDeclarator.addChild( variableDeclaratorID );
+ ParseNode variableDeclaratorList = new ParseNode("variable_declarators_list");
+ variableDeclaratorList.addChild( variableDeclarator );
+ theNode.addChild("variables").addChild( variableDeclaratorList );
+
+ for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
+ ClassDescriptor icd=(ClassDescriptor)it.next();
+ if(icd.isStatic() || icd.getInStaticContext()) {
+ continue;
+ }
+ parseFieldDecl( icd, theNode );
+ /*if( true ) {
+ SymbolTable fieldTable = icd.getFieldTable();
+ //System.out.println( fieldTable.toString() );
+ }*/
+ icd.setInnerDepth( depth + 1 );
+ addOuterClassReferences( icd, ocn, depth + 1 );
+ }
+}
+