system/src/sc/parser/FormatContext.java
private void insertPendingParents(ParentParseNode curParseNode, ISemanticNode parNode, ISemanticNode findNode) {
      ArrayList<Entry> pathToNode = null;
      int maxLevelCount = 3; // TODO: this might need to be higher?
      int ct = 0;
      do {
         if (parNode != null) {
            Object parParseNodeObj = parNode.getParseNode();
            if (parParseNodeObj instanceof ParentParseNode) {
               ParentParseNode parParseNode = (ParentParseNode) parParseNodeObj;
               boolean found;
               do {
                  found = false;
                  List parChildren = parParseNode.children;
                  int parChildIndex = -1;
                  if (parChildren != null) {
                     if ((parChildIndex = parChildren.indexOf(curParseNode)) != -1) {
                        Entry ent = new Entry();
                        ent.currentIndex = parChildIndex;
                        ent.parent = parParseNode;
                        pendingParents.add(0, ent);
                        if (pathToNode != null) {
                           pendingParents.addAll(0, pathToNode);
                           curParseNode = pathToNode.get(0).parent;
                           pathToNode = null;
                        }
                        else
                           curParseNode = parParseNode;
                     } else {
                        for (int i = 0; i < parChildren.size(); i++) {
                           Object parChild = parChildren.get(i);
                           if (parChild instanceof ParentParseNode) {
                              ParentParseNode parChildPNode = (ParentParseNode) parChild;
                              // Is this child the path to find the parent?  If so, add this to the chain, then advance to the next one.
                              if (parChildPNode.refersToSemanticValue(findNode)) {
                                 Entry pathEnt = new Entry();
                                 pathEnt.currentIndex = i;
                                 pathEnt.parent = parParseNode;

                                 if (pathToNode == null)
                                    pathToNode = new ArrayList<Entry>();
                                 pathToNode.add(pathEnt);
                                 found = true;
                                 parParseNode = parChildPNode;
                                 break;
                              }
                           }
                        }
                     }
                  }
               } while (found);
            }
         }
         ct++;
         if (ct == maxLevelCount)
            parNode = null;
         else if (parNode != null)
            parNode = parNode.getParentNode();
      } while (parNode != null);
   }
/**
    * This handles the case where we are trying to reformat a node inside of a larger document and need
    * the context of where this node resides in order to find the adjacent text for determining proper
    * spacing.  For example, the ClassType semantic node ends in a spacing parse node.  There are a couple
    * of levels of ParentParseNode between it and the parent FieldDefinition - so we need to determine the
    * path back from the FieldDefinition to the correct ParentParseNode of the ClassType in order to add
    * the trailing space to teh ClassType when it's name changes.
    *
    * If we don't find the nextChar() for the SpacingParseNode in ClassType, we'll treat it like the end of
    * file which is not correct.  But when ClassType ends up at the end of a newline or something we do not
    * want to insert that extra space.
    *
    * TODO: Currently we only go up the parent hierarchy three levels - to handle the case where you are changing
    * an expression inside of a binary expression.  There's a list -> identifierExpr -> BinaryOperand -> BinaryExpression
    * It's possible we need to do this more levels... or maybe we should lazily find the next level in "nextChar"
    * when we hit the end of the top-most level?
    */
This handles the case where we are trying to reformat a node inside of a larger document and need
the context of where this node resides in order to find the adjacent text for determining proper
spacing.  For example, the ClassType semantic node ends in a spacing parse node.  There are a couple
of levels of ParentParseNode between it and the parent FieldDefinition - so we need to determine the
path back from the FieldDefinition to the correct ParentParseNode of the ClassType in order to add
the trailing space to teh ClassType when it's name changes.

If we don't find the nextChar() for the SpacingParseNode in ClassType, we'll treat it like the end of
file which is not correct.  But when ClassType ends up at the end of a newline or something we do not
want to insert that extra space.

Currently we only go up the parent hierarchy three levels - to handle the case where you are changing
an expression inside of a binary expression.  There's a list -> identifierExpr -> BinaryOperand -> BinaryExpression
It's possible we need to do this more levels...
This handles the case where we are trying to reformat a node inside of a larger document and need the context of where this node resides in order to find the adjacent text for determining proper spacing . For example the ClassType semantic node ends in a spacing parse node . There are a couple of levels of ParentParseNode between it and the parent FieldDefinition - so we need to determine the path back from the FieldDefinition to the correct ParentParseNode of the ClassType in order to add the trailing space to teh ClassType when it ' s name changes . If we don ' t find the nextChar () for the SpacingParseNode in ClassType we ' ll treat it like the end of file which is not correct . But when ClassType ends up at the end of a newline or something we do not want to insert that extra space . Currently we only go up the parent hierarchy three levels - to handle the case where you are changing an expression inside of a binary expression . There ' s a list - > identifierExpr - > BinaryOperand - > BinaryExpression It ' s possible we need to do this more levels ...
private void insertPendingParents(ParentParseNode curParseNode, ISemanticNode parNode, ISemanticNode findNode) {
      ArrayList<Entry> pathToNode = null;
      int maxLevelCount = 3; 
      int ct = 0;
      do {
         if (parNode != null) {
            Object parParseNodeObj = parNode.getParseNode();
            if (parParseNodeObj instanceof ParentParseNode) {
               ParentParseNode parParseNode = (ParentParseNode) parParseNodeObj;
               boolean found;
               do {
                  found = false;
                  List parChildren = parParseNode.children;
                  int parChildIndex = -1;
                  if (parChildren != null) {
                     if ((parChildIndex = parChildren.indexOf(curParseNode)) != -1) {
                        Entry ent = new Entry();
                        ent.currentIndex = parChildIndex;
                        ent.parent = parParseNode;
                        pendingParents.add(0, ent);
                        if (pathToNode != null) {
                           pendingParents.addAll(0, pathToNode);
                           curParseNode = pathToNode.get(0).parent;
                           pathToNode = null;
                        }
                        else
                           curParseNode = parParseNode;
                     } else {
                        for (int i = 0; i < parChildren.size(); i++) {
                           Object parChild = parChildren.get(i);
                           if (parChild instanceof ParentParseNode) {
                              ParentParseNode parChildPNode = (ParentParseNode) parChild;
                              if (parChildPNode.refersToSemanticValue(findNode)) {
                                 Entry pathEnt = new Entry();
                                 pathEnt.currentIndex = i;
                                 pathEnt.parent = parParseNode;
                                 if (pathToNode == null)
                                    pathToNode = new ArrayList<Entry>();
                                 pathToNode.add(pathEnt);
                                 found = true;
                                 parParseNode = parChildPNode;
                                 break;
                              }
                           }
                        }
                     }
                  }
               } while (found);
            }
         }
         ct++;
         if (ct == maxLevelCount)
            parNode = null;
         else if (parNode != null)
            parNode = parNode.getParentNode();
      } while (parNode != null);
   }
private void insertPendingParents ( ParentParseNode curParseNode , ISemanticNode parNode , ISemanticNode findNode ) { ArrayList < Entry > pathToNode = null ; int maxLevelCount = 3 ; int ct = 0 ; do { if ( parNode != null ) { Object parParseNodeObj = parNode . getParseNode ( ) ; if ( parParseNodeObj instanceof ParentParseNode ) { ParentParseNode parParseNode = ( ParentParseNode ) parParseNodeObj ; boolean found ; do { found = false ; List parChildren = parParseNode . children ; int parChildIndex = - 1 ; if ( parChildren != null ) { if ( ( parChildIndex = parChildren . indexOf ( curParseNode ) ) != - 1 ) { Entry ent = new Entry ( ) ; ent . currentIndex = parChildIndex ; ent . parent = parParseNode ; pendingParents . add ( 0 , ent ) ; if ( pathToNode != null ) { pendingParents . addAll ( 0 , pathToNode ) ; curParseNode = pathToNode . get ( 0 ) . parent ; pathToNode = null ; } else curParseNode = parParseNode ; } else { for ( int i = 0 ; i < parChildren . size ( ) ; i ++ ) { Object parChild = parChildren . get ( i ) ; if ( parChild instanceof ParentParseNode ) { ParentParseNode parChildPNode = ( ParentParseNode ) parChild ; if ( parChildPNode . refersToSemanticValue ( findNode ) ) { Entry pathEnt = new Entry ( ) ; pathEnt . currentIndex = i ; pathEnt . parent = parParseNode ; if ( pathToNode == null ) pathToNode = new ArrayList < Entry > ( ) ; pathToNode . add ( pathEnt ) ; found = true ; parParseNode = parChildPNode ; break ; } } } } } } while ( found ) ; } } ct ++ ; if ( ct == maxLevelCount ) parNode = null ; else if ( parNode != null ) parNode = parNode . getParentNode ( ) ; } while ( parNode != null ) ; }
This handles the case where we are trying to reformat a node inside of a larger document and need
 the context of where this node resides in order to find the adjacent text for determining proper
 spacing.
This handles the case where we are trying to reformat a node inside of a larger document and need the context of where this node resides in order to find the adjacent text for determining proper spacing .
// TODO: this might need to be higher? // Is this child the path to find the parent?  If so, add this to the chain, then advance to the next one.