KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > ast > visitor > rewriter > ClassBodyWriter


1 package org.jruby.ast.visitor.rewriter;
2
3 import java.util.Iterator JavaDoc;
4
5 import org.jruby.ast.BlockNode;
6 import org.jruby.ast.NewlineNode;
7 import org.jruby.ast.Node;
8 import org.jruby.ast.visitor.rewriter.utils.ReWriterContext;
9
10
11 public class ClassBodyWriter {
12     private ReWriteVisitor visitor;
13     private Node bodyNode;
14     private ReWriterContext context;
15
16     public ClassBodyWriter(ReWriteVisitor visitor, Node bodyNode) {
17         this.visitor = visitor;
18         this.bodyNode = bodyNode;
19         this.context = visitor.getConfig();
20     }
21     
22     public void write(){
23         if (bodyNode instanceof BlockNode) {
24             context.getIndentor().indent();
25             writeContent((BlockNode) bodyNode);
26             context.getIndentor().outdent();
27         } else if (bodyNode instanceof NewlineNode) {
28             visitor.visitNodeInIndentation(bodyNode);
29         } else {
30             visitor.visitNode(bodyNode);
31         }
32     }
33     
34     private void writeContent(BlockNode node) {
35         for (Iterator JavaDoc it = node.childNodes().iterator(); it.hasNext(); ) {
36             visitor.visitNode((Node) it.next());
37             
38             if (it.hasNext()) {
39                 context.getOutput().print(context.getFormatHelper().classBodyElementsSeparator());
40             }
41         }
42     }
43 }
44
Popular Tags