Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / code / ast / ClassInstanceCreation.java
package code.ast;

import java.util.List;

public class ClassInstanceCreation extends Expression {
	private Type type;
	
	private List<Expression> arguments;
	
	public ClassInstanceCreation(Type type) {
		this(type, List.of());
	}
	
	public ClassInstanceCreation(Type type, List<Expression> arguments) {
		this.type = type;
		this.arguments = arguments;
	}
	
	public Type getType() {
		return type;
	}
	
	public void setType(Type type) {
		this.type = type;
	}
	
	public List<Expression> getArguments() {
		return arguments;
	}
	
	public void setArguments(List<Expression> arguments) {
		this.arguments = arguments;
	}
	
	public void addArgument(Expression expression) {
		arguments.add(expression);
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		
		builder.append("new ");
		builder.append(type.toString());
		builder.append("(");
		for (int i = 0; i < arguments.size(); i++) {
			Expression argument = arguments.get(i);
			
			builder.append(argument.toString());
			
			if (i < arguments.size() - 1) {
				builder.append(", ");
			}
		}
		builder.append(")");
		
		return builder.toString();
	}
}