/* Generated By:JJTree: Do not edit this line. ASTCompositeReference.java */

package org.dojo.jsl.parser;

import org.dojo.jsl.parser.ASTPropertyIdentifierReference;
import org.dojo.jsl.parser.EcmaScript;
import org.dojo.jsl.parser.EcmaScriptVisitor;

public class ASTCompositeReference extends SimpleNode {
	public ASTCompositeReference(int id) {
		super(id);
	}

	public ASTCompositeReference(EcmaScript p, int id) {
		super(p, id);
	}

	/** Accept the visitor. * */
	@Override
	public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
		return visitor.visit(this, data);
	}

	public String getCompositeName() {
		int n = jjtGetNumChildren();

		return this.getCompositeName(n);
	}

	public String getPropertyIdentifierCompositeName() {
		StringBuffer compositeNameBuffer = new StringBuffer();
		SimpleNode cNode = (SimpleNode) jjtGetChild(0);

		int n = jjtGetNumChildren();

		if (cNode instanceof ASTIdentifier) {
			compositeNameBuffer.append(((ASTIdentifier) cNode).getName());
		} else {
			return null;
		}

		for (int i = 1; i < n; i++) {
			cNode = (SimpleNode) jjtGetChild(i);

			if (cNode instanceof ASTPropertyIdentifierReference) {
				ASTIdentifier nameNode = (ASTIdentifier) cNode.jjtGetChild(0);

				compositeNameBuffer.append('.');
				compositeNameBuffer.append(nameNode.getName());
			} else {
				break;
			}
		}

		return compositeNameBuffer.toString();
	}

	public String getCompositeName(int n) {
		StringBuffer compositeNameBuffer = new StringBuffer();
		SimpleNode cNode = (SimpleNode) jjtGetChild(0);

		if (cNode instanceof ASTIdentifier) {
			compositeNameBuffer.append(((ASTIdentifier) cNode).getName());
		} else {
			return null;
		}

		for (int i = 1; i < n; i++) {
			cNode = (SimpleNode) jjtGetChild(i);

			if (cNode instanceof ASTPropertyIdentifierReference) {
				ASTIdentifier nameNode = (ASTIdentifier) cNode.jjtGetChild(0);

				compositeNameBuffer.append('.');
				compositeNameBuffer.append(nameNode.getName());
			} else {
				return null;
			}
		}

		return compositeNameBuffer.toString();
	}

	public String getName(int index) {
		SimpleNode cNode = (SimpleNode) jjtGetChild(index);
		String result = null;

		if (cNode instanceof ASTPropertyIdentifierReference) {
			ASTIdentifier nameNode = (ASTIdentifier) cNode.jjtGetChild(0);

			result = nameNode.getName();
		} else if (cNode instanceof ASTIdentifier) {
			result = ((ASTIdentifier) cNode).getName();
		}

		return result;
	}

}
