package jadx.core.dex.instructions;

import org.jetbrains.annotations.NotNull;

import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.InsnNode;

public class NewArrayNode extends InsnNode {

	private final ArgType arrType;

	public NewArrayNode(@NotNull ArgType arrType, RegisterArg res, InsnArg size) {
		this(arrType);
		setResult(res);
		addArg(size);
	}

	private NewArrayNode(ArgType arrType) {
		super(InsnType.NEW_ARRAY, 1);
		this.arrType = arrType;
	}

	public ArgType getArrayType() {
		return arrType;
	}

	@Override
	public boolean isSame(InsnNode obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof NewArrayNode) || !super.isSame(obj)) {
			return false;
		}
		NewArrayNode other = (NewArrayNode) obj;
		return arrType == other.arrType;
	}

	@Override
	public InsnNode copy() {
		return copyCommonParams(new NewArrayNode(arrType));
	}

	@Override
	public String toString() {
		return super.toString() + " type: " + arrType;
	}
}
