// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static String formatPath(List<String> path, 
//         char separator) {
//     StringBuilder sb = new StringBuilder();
//     for (int i=0; i<path.size(); i++) {
//         String pathPart = path.get(i);
//         if (! pathPart.isEmpty()) {
//             sb.append(pathPart);
//             if (i<path.size()-1) sb.append(separator);
//         }
//     }
//     return sb.toString();
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static boolean isNameMatching(
//         String startingWith, Declaration d) {
//     return isNameMatching(startingWith, d.getName());
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static boolean isOverloadedVersion(Declaration decl) {
//     return decl!=null && 
//             (decl.isOverloaded() && 
//             !decl.isAbstraction());
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static boolean isResolvable(Declaration declaration) {
//     return declaration.getName()!=null &&
//         !declaration.isSetter() && //return getters, not setters
//         !declaration.isAnonymous(); //don't return the type associated with an object dec 
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static Declaration lookupMember(
//         List<Declaration> members, String name,
//         List<Type> signature, boolean ellipsis) {
//     return lookupMember(members, name, signature, ellipsis, false);
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static Declaration lookupMemberForBackend(
//         List<Declaration> members, String name, Backends backends) {
//     for (Declaration dec: members) {
//         if (isResolvable(dec) && isNamed(name, dec)) {
//             Backends bs = dec.getNativeBackends();
//             if (bs.none()) {
//                 return dec;
//             }
//             else if (backends.supports(bs)) {
//                 return dec;
//             }
//         }
//     }
//     return null;
// }


import static com.redhat.ceylon.model.typechecker.model.ModelUtil.formatPath;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isNameMatching;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isOverloadedVersion;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isResolvable;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.lookupMember;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.lookupMemberForBackend;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.redhat.ceylon.common.Backends;
    public Declaration getDirectMemberForBackend(String name, 
            Backends backends) {
        return lookupMemberForBackend(getMembers(), 
                name, backends);
    }

    @Override
    public Type getDeclaringType(Declaration d) {
        if (d.isClassMember()) {
            Class containingAnonClass =
                    (Class) d.getContainer();
            if (containingAnonClass.isAnonymous()) {
                return containingAnonClass.getType();
            }
        }
        return null;
    }

    /**
     * Search in the package, taking into account
     * imports
     */
    @Override
    public Declaration getMemberOrParameter(Unit unit, 
            String name, List<Type> signature, 
            boolean ellipsis) {
        //this implements the rule that imports hide 
        //toplevel members of a package
        //TODO: would it be better to look in the given unit 
        //      first, before checking imports?
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static String formatPath(List<String> path, 
//         char separator) {
//     StringBuilder sb = new StringBuilder();
//     for (int i=0; i<path.size(); i++) {
//         String pathPart = path.get(i);
//         if (! pathPart.isEmpty()) {
//             sb.append(pathPart);
//             if (i<path.size()-1) sb.append(separator);
//         }
//     }
//     return sb.toString();
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static boolean isNameMatching(
//         String startingWith, Declaration d) {
//     return isNameMatching(startingWith, d.getName());
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static boolean isOverloadedVersion(Declaration decl) {
//     return decl!=null && 
//             (decl.isOverloaded() && 
//             !decl.isAbstraction());
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static boolean isResolvable(Declaration declaration) {
//     return declaration.getName()!=null &&
//         !declaration.isSetter() && //return getters, not setters
//         !declaration.isAnonymous(); //don't return the type associated with an object dec 
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static Declaration lookupMember(
//         List<Declaration> members, String name,
//         List<Type> signature, boolean ellipsis) {
//     return lookupMember(members, name, signature, ellipsis, false);
// }
// 
// Path: src/com/redhat/ceylon/model/typechecker/model/ModelUtil.java
// public static Declaration lookupMemberForBackend(
//         List<Declaration> members, String name, Backends backends) {
//     for (Declaration dec: members) {
//         if (isResolvable(dec) && isNamed(name, dec)) {
//             Backends bs = dec.getNativeBackends();
//             if (bs.none()) {
//                 return dec;
//             }
//             else if (backends.supports(bs)) {
//                 return dec;
//             }
//         }
//     }
//     return null;
// }


// Path: src/com/redhat/ceylon/model/typechecker/model/Package.java
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.formatPath;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isNameMatching;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isOverloadedVersion;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isResolvable;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.lookupMember;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.lookupMemberForBackend;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.redhat.ceylon.common.Backends;

    public Declaration getDirectMemberForBackend(String name, 
            Backends backends) {
        return lookupMemberForBackend(getMembers(), 
                name, backends);
    }

    @Override
    public Type getDeclaringType(Declaration d) {
        if (d.isClassMember()) {
            Class containingAnonClass =
                    (Class) d.getContainer();
            if (containingAnonClass.isAnonymous()) {
                return containingAnonClass.getType();
            }
        }
        return null;
    }

    /**
     * Search in the package, taking into account
     * imports
     */
    @Override
    public Declaration getMemberOrParameter(Unit unit, 
            String name, List<Type> signature, 
            boolean ellipsis) {
        //this implements the rule that imports hide 
        //toplevel members of a package
        //TODO: would it be better to look in the given unit 
        //      first, before checking imports?
        Declaration d = 