package com.redhat.ceylon.eclipse.util;

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

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

public class FindRefinementsVisitor extends Visitor implements NaturalVisitor {
    
    private final Declaration declaration;
    private Set<Tree.Declaration> declarationNodes = new HashSet<Tree.Declaration>();
    
    public FindRefinementsVisitor(Declaration declaration) {
        this.declaration = declaration;
    }
    
    public Set<Tree.Declaration> getDeclarationNodes() {
        return declarationNodes;
    }
    
    protected boolean isRefinement(Declaration dec) {
        return dec!=null && dec.refines(declaration) ||
                dec instanceof Setter && ((Setter)dec).getGetter()
                        .refines(declaration);
    }
    
    @Override
    public void visit(Tree.Declaration that) {
        if (isRefinement(that.getDeclarationModel())) {
            declarationNodes.add(that);
        }
        super.visit(that);
    }
        
}

@@ -542,27 +542,35 @@
 et%3CTree.
-Declaration
+StatementOrArgument
 %3E declar
@@ -582,16 +582,29 @@
 Nodes = 
+%0A            
 new Hash
@@ -612,27 +612,35 @@
 et%3CTree.
-Declaration
+StatementOrArgument
 %3E();%0A   
@@ -773,27 +773,35 @@
 et%3CTree.
-Declaration
+StatementOrArgument
 %3E getDec
@@ -1039,16 +1039,16 @@
 etter()%0A
-
         
@@ -1111,16 +1111,263 @@
 verride%0A
+    public void visit(Tree.SpecifierStatement that) %7B%0A        if (that.getRefinement() &&%0A                isRefinement(that.getDeclaration())) %7B%0A            declarationNodes.add(that);%0A        %7D%0A        super.visit(that);%0A    %7D%0A    %0A    @Override%0A
     publ

enable Find Refinements on toplevels and locals