PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/ooc/frontend/model/CommaSequence.java

http://github.com/nddrylliog/ooc
Java | 58 lines | 45 code | 13 blank | 0 comment | 4 complexity | 10b27eaa3969ab36ffe34e06265c16be MD5 | raw file
 1package org.ooc.frontend.model;
 2
 3import java.io.IOException;
 4
 5import org.ooc.frontend.Visitor;
 6import org.ooc.frontend.model.tokens.Token;
 7
 8public class CommaSequence extends Expression {
 9
10	NodeList<Statement> body;
11	
12	public Type getType() {
13		return body.isEmpty() ? null : ((Expression) body.getLast()).getType();
14	}
15	
16	public CommaSequence(Token startToken) {
17		super(startToken);
18		body = new NodeList<Statement>();
19	}
20	
21	public NodeList<Statement> getBody() {
22		return body;
23	}
24
25	@Override
26	public boolean replace(Node oldie, Node kiddo) {
27		return body.replace(oldie, kiddo);
28	}
29
30	public void accept(Visitor visitor) throws IOException {
31		visitor.visit(this);
32	}
33
34	public void acceptChildren(Visitor visitor) throws IOException {
35		for (Statement stmt : body) {
36			stmt.accept(visitor);
37		}
38	}
39
40	public boolean hasChildren() {
41		return !body.isEmpty();
42	}
43	
44	@Override
45	public String toString() {
46		StringBuilder sb = new StringBuilder();
47		sb.append('(');
48		boolean isFirst = true;
49		for(Statement stmt : body) {
50			if(isFirst) isFirst = false;
51			else        sb.append(", ");
52			sb.append(stmt.toString());
53		}
54		sb.append(')');
55		return sb.toString();
56	}
57
58}