All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jrubyparser.rewriter.ClassBodyWriter Maven / Gradle / Ivy

Go to download

A library to expose exact char-for-char position information of Ruby syntax.

There is a newer version: 0.5.3
Show newest version
package org.jrubyparser.rewriter;

import java.util.Iterator;

import org.jrubyparser.ast.BlockNode;
import org.jrubyparser.ast.NewlineNode;
import org.jrubyparser.ast.Node;
import org.jrubyparser.rewriter.utils.ReWriterContext;


public class ClassBodyWriter {
	private ReWriteVisitor visitor;
	private Node bodyNode;
	private ReWriterContext context;

	public ClassBodyWriter(ReWriteVisitor visitor, Node bodyNode) {
		this.visitor = visitor;
		this.bodyNode = bodyNode;
		this.context = visitor.getConfig();
	}
	
	public void write(){
		if (bodyNode instanceof BlockNode) {
			context.getIndentor().indent();
			writeContent((BlockNode) bodyNode);
			context.getIndentor().outdent();
		} else if (bodyNode instanceof NewlineNode) {
			visitor.visitNodeInIndentation(bodyNode);
		} else {
			visitor.visitNode(bodyNode);
		}
	}
	
	private void writeContent(BlockNode node) {
		for (Iterator it = node.childNodes().iterator(); it.hasNext(); ) {
			visitor.visitNode(it.next());
            
			if (it.hasNext()) {
				context.getOutput().print(context.getFormatHelper().classBodyElementsSeparator());
            }
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy