/** * Get a set of possibilities to complete the passed word. * * @param word The word you want to complete * @param types The types of completions you want. * @return A set of possibilities to complete the code. */ public Collection<CodePossibility> getPossiblilities(String word, Type[] types) { ZDebug.print(4, "getPossiblilities( ", word, " )"); // Optimisation if (word.length() > 0 && !Character.isLetter(word.charAt(0))) { return new ArrayList<CodePossibility>(0); } // Get what types of possibility the caller wants boolean listGroups = false, listFunctions = false, listKeywords = false; for (Type type : types) { switch (type) { case FUNCTION: listFunctions = true; break; case GROUP: listGroups = true; break; case KEYWORD: listKeywords = true; break; } } // Split up into parts (for functions and groups) String[] parts = word.split("\\.", -1); if (parts.length < 1) return new HashSet<CodePossibility>(0); String groupName = ""; String funcName = null; for (int i = 0; i < parts.length - 1; i++) { if (i != 0) groupName += "."; groupName += parts[i]; } ZDebug.print(5, "Word Before: '", word, "'"); FunctionGroup currentGroup = this.getGroup(groupName); if (parts.length > 0) { funcName = parts[parts.length - 1]; } TreeSet<CodePossibility> list = new TreeSet<CodePossibility>(); // Suggest some keywords if (listKeywords) { for (String keyword : getKeywordsStartingWith(word)) { list.add(new CodePossibility(keyword, word)); } } // Suggest some groups if (listGroups) { ZDebug.print(5, "Getting groups that start with: ", word); for (FunctionGroup group : getGroupsStartingWith(word)) { list.add(new CodePossibility(group, word)); } } // Suggest some functions if (listFunctions) { if (currentGroup != null) { ZDebug.print(5, "Getting functions in '", currentGroup, "' that start with: ", funcName); for (Function function : currentGroup.getFunctionsStartingWith(funcName)) { list.add(new CodePossibility(function, funcName)); } } } return list; }