package com.redhat.ceylon.eclipse.util;

import org.eclipse.core.resources.IProject;

import com.redhat.ceylon.cmr.api.ModuleQuery;
import com.redhat.ceylon.cmr.api.ModuleSearchResult;
import com.redhat.ceylon.common.Versions;
import com.redhat.ceylon.compiler.typechecker.TypeChecker;
import com.redhat.ceylon.eclipse.core.builder.CeylonBuilder;

public class ModuleQueries {

    public static ModuleQuery.Type getModuleQueryType(IProject project) {
        if (project!=null) {
            boolean compileToJava = CeylonBuilder.compileToJava(project);
            boolean compileToJs = CeylonBuilder.compileToJs(project);
            if (compileToJava&&!compileToJs) {
                return ModuleQuery.Type.JVM;
            }
            if (compileToJs&&!compileToJava) {
                return ModuleQuery.Type.JS;
            }
            if (compileToJs&&compileToJava) {
                return ModuleQuery.Type.CEYLON_CODE;
            }
        }
        return ModuleQuery.Type.CODE;
    }

    public static ModuleSearchResult getModuleSearchResults(String prefix,
            TypeChecker tc, IProject project) {
        ModuleQuery query = new ModuleQuery(prefix, getModuleQueryType(project));
        query.setBinaryMajor(Versions.JVM_BINARY_MAJOR_VERSION);
        return tc.getContext().getRepositoryManager().completeModules(query);
    }

}

@@ -372,29 +372,30 @@
 ies %7B%0A%0A    p
-ublic
+rivate
  static Modu
@@ -401,21 +401,16 @@
 uleQuery
-.Type
  getModu
@@ -416,21 +416,32 @@
 uleQuery
-Type(
+(String prefix, 
 IProject
@@ -686,32 +686,56 @@
           return
+ new ModuleQuery(prefix,
  ModuleQuery.Typ
@@ -739,16 +739,17 @@
 Type.JVM
+)
 ;%0A      
@@ -817,32 +817,56 @@
           return
+ new ModuleQuery(prefix,
  ModuleQuery.Typ
@@ -869,16 +869,17 @@
 .Type.JS
+)
 ;%0A      
@@ -946,32 +946,56 @@
           return
+ new ModuleQuery(prefix,
  ModuleQuery.Typ
@@ -1003,24 +1003,52 @@
 .CEYLON_CODE
+, ModuleQuery.Retrieval.ALL)
 ;%0A          
@@ -1075,16 +1075,40 @@
   return
+ new ModuleQuery(prefix,
  ModuleQ
@@ -1121,16 +1121,17 @@
 ype.CODE
+)
 ;%0A    %7D%0A
@@ -1282,20 +1282,19 @@
 query = 
-new 
+get
 ModuleQu
@@ -1309,35 +1309,16 @@
 ix, 
-getModuleQueryType(
 project)
 );%0A 
@@ -1313,17 +1313,16 @@
 project)
-)
 ;%0A      

Set retrieval mode to `ALL` when using query type `CEYLON_CODE` (#671)