package com.redhat.ceylon.eclipse.util;

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 FindDeclarationVisitor extends Visitor {
	
	private final Declaration declaration;
	private Tree.Declaration declarationNode;
	
	public FindDeclarationVisitor(Declaration declaration) {
		this.declaration = declaration;
	}
	
	public Tree.Declaration getDeclarationNode() {
		return declarationNode;
	}
	
    private boolean isDeclaration(Declaration dec) {
        return dec!=null && dec.equals(declaration);
    }
    
	@Override
	public void visit(Tree.Declaration that) {
		if (isDeclaration(that.getDeclarationModel())) {
			declarationNode = that;
		}
		super.visit(that);
	}
	
	public void visitAny(Node node) {
		if (declarationNode==null) {
			super.visitAny(node);
		}
	}
	
}

@@ -867,24 +867,252 @@
 that);%0A%09%7D%0A%09%0A
+    @Override%0A    public void visit(Tree.ObjectDefinition that) %7B%0A        if (isDeclaration(that.getDeclarationModel().getTypeDeclaration())) %7B%0A            declarationNode = that;%0A        %7D%0A        super.visit(that);%0A    %7D%0A    %0A
 %09public void

make FindDeclarationVisitor work for "object" classes