package com.redhat.ceylon.eclipse.util;

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

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

public class FindSubtypesVisitor extends Visitor {
	
	private final TypeDeclaration declaration;
	private Set<Tree.Declaration> declarationNodes = new HashSet<Tree.Declaration>();
	
	public FindSubtypesVisitor(TypeDeclaration declaration) {
		this.declaration = declaration;
	}
	
	public Set<Tree.Declaration> getDeclarationNodes() {
		return declarationNodes;
	}
	
    protected boolean isRefinement(TypeDeclaration dec) {
        return dec!=null && dec.inherits(declaration);
    }
    
	@Override
	public void visit(Tree.TypeDeclaration that) {
		if (isRefinement(that.getDeclarationModel())) {
			declarationNodes.add(that);
		}
		super.visit(that);
	}
		
}

@@ -931,10 +931,245 @@
 ;%0A%09%7D%0A%09%09%0A
+    @Override%0A    public void visit(Tree.ObjectDefinition that) %7B%0A        if (isRefinement(that.getDeclarationModel().getTypeDeclaration())) %7B%0A            declarationNodes.add(that);%0A        %7D%0A        super.visit(that);%0A    %7D%0A        %0A
 %7D%0A

find subtypes should return object declarations