package ca.uwaterloo.joos.ast.name;

import java.util.LinkedList;
import java.util.List;

import ca.uwaterloo.joos.ast.ASTNode;
import ca.uwaterloo.joos.ast.descriptor.SimpleListDescriptor;
import ca.uwaterloo.joos.parser.ParseTree.LeafNode;
import ca.uwaterloo.joos.parser.ParseTree.Node;
import ch.lambdaj.Lambda;

public class QualifiedName extends Name {

	public static final SimpleListDescriptor COMPONENTS = new SimpleListDescriptor(String.class);

	public QualifiedName(Node qualifiedName, ASTNode parent) throws Exception {
		super(qualifiedName, parent);
	}

	public String getQualifiedName() throws ChildTypeUnmatchException {
		return Lambda.join(this.getComponents(), ".");
	}

	@SuppressWarnings("unchecked")
	public List<String> getComponents() throws ChildTypeUnmatchException {
		return (List<String>) this.getChildByDescriptor(COMPONENTS);
	}

	@Override
	public String getName() throws Exception {
		return this.getQualifiedName();
	}

	@Override
	public void processLeafNode(LeafNode leafNode) throws Exception {
		if (leafNode.token.getKind().equals("ID")) {
			List<String> components = this.getComponents();
			if (components == null) {
				components = new LinkedList<String>();
				this.addChild(QualifiedName.COMPONENTS, components);
			}

			components.add(0, leafNode.token.getLexeme());
		}
	}

}

@@ -47,22 +47,21 @@
 va.util.
-Linked
+Array
 List;%0Aim
@@ -1177,14 +1177,13 @@
 new 
-Linked
+Array
 List
@@ -1279,11 +1279,8 @@
 add(
-0, 
 leaf

Reverse the qualified name list order