package com.redhat.ceylon.compiler.typechecker.ui;

import java.util.HashSet;
import java.util.Set;

import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.tree.Node;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.compiler.typechecker.tree.Visitor;

public class FindReferenceVisitor extends Visitor {
	
	private final Declaration declaration;
	private final Set<Node> nodes = new HashSet<Node>();
	
	public FindReferenceVisitor(Declaration declaration) {
		this.declaration = declaration;
	}
	
	public Set<Node> getNodes() {
		return nodes;
	}
	
	@Override
	public void visit(Tree.MemberOrTypeExpression that) {
		//TODO: handle refinement!
		if (that.getDeclaration()==declaration) {
			nodes.add(that);
		}
		super.visit(that);
	}
		
	@Override
	public void visit(Tree.NamedArgument that) {
		if (that.getParameter()==declaration) {
			nodes.add(that);
		}
		super.visit(that);
	}
		
	@Override
	public void visit(Tree.Type that) {
		if (that.getTypeModel().getDeclaration()==declaration) {
			nodes.add(that);
		}
		super.visit(that);
	}
		
	@Override
	public void visit(Tree.ImportMemberOrType that) {
		if (that.getDeclarationModel()==declaration) {
			nodes.add(that);
		}
		super.visit(that);
	}
		
}

@@ -631,16 +631,97 @@
 s;%0A%09%7D%0A%09%0A
+%09protected boolean equals(Declaration x, Declaration y) %7B%0A%09    return x==y;%0A%09%7D%0A%09%0A
 %09@Overri
@@ -808,24 +808,31 @@
 ement!%0A%09%09if 
+(equals
 (that.getDec
@@ -833,34 +833,34 @@
 getDeclaration()
-==
+, 
 declaration) %7B%0A%09
@@ -847,32 +847,33 @@
 (), declaration)
+)
  %7B%0A%09%09%09nodes.add(
@@ -964,32 +964,39 @@
 nt that) %7B%0A%09%09if 
+(equals
 (that.getParamet
@@ -999,18 +999,18 @@
 ameter()
-==
+, 
 declarat
@@ -1005,32 +1005,33 @@
 (), declaration)
+)
  %7B%0A%09%09%09nodes.add(
@@ -1113,32 +1113,39 @@
 pe that) %7B%0A%09%09if 
+(equals
 (that.getTypeMod
@@ -1165,18 +1165,18 @@
 ration()
-==
+, 
 declarat
@@ -1171,32 +1171,33 @@
 (), declaration)
+)
  %7B%0A%09%09%09nodes.add(
@@ -1224,33 +1224,99 @@
 isit(that);%0A%09%7D%0A%09
-%09
+%0A%09/*@Override%0A%09public void visit(Tree.SyntheticVariable that) %7B%7D*/%0A
 %0A%09@Override%0A%09pub
@@ -1367,16 +1367,23 @@
  %7B%0A%09%09if 
+(equals
 (that.ge
@@ -1401,18 +1401,18 @@
 nModel()
-==
+, 
 declarat
@@ -1411,24 +1411,25 @@
 declaration)
+)
  %7B%0A%09%09%09nodes.

abstract the equality test