//
 // For convenience, trusts that the node passed to it is a NodeSequence.
 // (of course, will throw an exception if it isn't).
 //
 public void visit(Node n1, String sep) {
   NodeSequence n = (NodeSequence) n1;
   for (Enumeration e = n.elements(); e.hasMoreElements(); ) {
     ((Node) e.nextElement()).accept(this);
     if (e.hasMoreElements()) out.print(sep);
   }
 }
 //
 // f0 -> "switch"
 // f1 -> "("
 // f2 -> Expression()
 // f3 -> ")"
 // f4 -> "{"
 // f5 -> ( SwitchLabel() ( BlockStatement() )* )*
 // f6 -> "}"
 //
 public void visit(SwitchStatement n) {
   out.print(n.f0 + " " + n.f1);
   n.f2.accept(this);
   out.println(n.f3);
   out.println(spc.spc + n.f4);
   spc.updateSpc(+1);
   for (Enumeration e = n.f5.elements(); e.hasMoreElements(); ) {
     NodeSequence seq = (NodeSequence) e.nextElement();
     out.print(spc.spc);
     seq.elementAt(0).accept(this);
     spc.updateSpc(+1);
     if (((NodeListOptional) seq.elementAt(1)).present()) {
       if (((NodeListOptional) seq.elementAt(1)).size() == 1) out.print(" ");
       else {
         out.println();
         out.print(spc.spc);
       }
       visit((NodeListOptional) seq.elementAt(1), "\n" + spc.spc);
     }
     out.println();
     spc.updateSpc(-1);
   }
   spc.updateSpc(-1);
   out.println(spc.spc + n.f6);
 }
  //
  // f0 -> "try"
  // f1 -> Block()
  // f2 -> ( "catch" "(" FormalParameter() ")" Block() )*
  // f3 -> [ "finally" Block() ]
  //
  public void visit(TryStatement n) {
    out.println(n.f0);
    out.print(spc.spc);
    n.f1.accept(this);
    for (Enumeration e = n.f2.elements(); e.hasMoreElements(); ) {
      NodeSequence seq = (NodeSequence) e.nextElement();
      out.println();
      out.print(spc.spc);
      seq.elementAt(0).accept(this);
      out.print(" ");
      seq.elementAt(1).accept(this);
      seq.elementAt(2).accept(this);
      seq.elementAt(3).accept(this);
      out.println();
      out.print(spc.spc);
      seq.elementAt(4).accept(this);
    }

    if (n.f3.present()) {
      NodeSequence seq = (NodeSequence) n.f3.node;
      out.println();
      seq.elementAt(0).accept(this);
      out.println();
      out.print(spc.spc);
      seq.elementAt(1).accept(this);
    }
  }
 //
 // f0 -> "this" Arguments() ";"
 //       | [ PrimaryExpression() "." ] "super" Arguments() ";"
 //
 public void visit(ExplicitConstructorInvocation n) {
   //
   // This code may not be appropriate if "which" is removed from NodeChoice
   //
   if (n.f0.which == 0) {
     n.f0.accept(this);
   } else {
     NodeSequence seq = (NodeSequence) n.f0.choice;
     seq.elementAt(0).accept(this);
     out.print(" ");
     seq.elementAt(1).accept(this);
     seq.elementAt(2).accept(this);
     seq.elementAt(3).accept(this);
   }
 }
Exemple #5
0
 public void visit(NodeSequence n, A argu) {
   int _count = 0;
   for (Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
     e.nextElement().accept(this, argu);
     _count++;
   }
 }
 public R visit(NodeSequence n) {
   R _ret = null;
   int _count = 0;
   for (Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
     e.nextElement().accept(this);
     _count++;
   }
   return _ret;
 }
  //
  // f0 -> "new" PrimitiveType() ArrayDimensions() [ ArrayInitializer() ]
  //       | "new" Name() ( ArrayDimensions() [ ArrayInitializer() ]| Arguments() [ ClassBody() ]  )
  //
  public void visit(AllocationExpression n) {
    NodeSequence seq = (NodeSequence) n.f0.choice;

    if (n.f0.which == 0) {
      seq.elementAt(0).accept(this);
      out.print(" ");
      seq.elementAt(1).accept(this);
      seq.elementAt(2).accept(this);
      if (((NodeOptional) seq.elementAt(3)).present()) {
        out.print(" ");
        seq.elementAt(3).accept(this);
      }
    } else { // needs a little tweaking
      seq.elementAt(0).accept(this);
      out.print(" ");
      seq.elementAt(1).accept(this);
      seq.elementAt(2).accept(this);
    }
  }
 public void visit(final NodeSequence n, final A argu) {
   for (final Iterator<INode> e = n.elements(); e.hasNext(); ) {
     e.next().accept(this, argu);
   }
   return;
 }
 public void visit(NodeSequence n) {
   for (Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) e.nextElement().accept(this);
 }