public List<String> getTopProposalsAsString() { List<String> strList = new ArrayList<>(); for (Proposal p : topProposals) strList.add(p.getValue()); return strList; }
@Override public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) { AutoCompleteResult result = new AutoCompleteResult(); FunctionDescriptor functionDesc = null; if (desc instanceof FunctionDescriptor) { functionDesc = (FunctionDescriptor) desc; } else { return result; // empty result } String nameToFind = functionDesc.getFunctionName(); // handle proposals int count = 0; // insertionPos is not yet provided for formula // TODO: improve parser String originalContent = desc.getOriginalContent(); int insertionPos = originalContent.lastIndexOf(nameToFind); if (!functionDesc.hasOpenBracket()) { Proposal topProposal = null; String closestMatchingFunction = null; for (String functionName : functions.keySet()) { if (functionName.startsWith(nameToFind)) { Proposal proposal = new Proposal(functionName + "(", false); String description = functions.get(functionName).get(0).getDescription() + "\n\n"; for (FormulaFunction ff : functions.get(functionName)) description += generateSignature(ff); proposal.setDescription(description); for (FormulaFunction ff : functions.get(functionName)) proposal.addTooltipData(generateTooltipData(ff, 0)); proposal.addStyle(ProposalStyle.getDefault(0, nameToFind.length() - 1)); proposal.setInsertionPos(insertionPos); proposal.setFunction(true); // display function icon result.addProposal(proposal); count++; if (closestMatchingFunction == null || closestMatchingFunction.compareTo(functionName) > 0) { closestMatchingFunction = functionName; topProposal = proposal; } } } // handle top proposals if (closestMatchingFunction != null) result.addTopProposal(topProposal); } result.setCount(count); // handle tooltip if (functionDesc.hasOpenBracket() && !functionDesc.isComplete()) { for (String setName : FormulaRegistry.getDefault().listFunctionSets()) { FormulaFunctionSet set = FormulaRegistry.getDefault().findFunctionSet(setName); for (FormulaFunction function : set.findFunctions(nameToFind)) { if (function.getName().equals(nameToFind)) if (function.getArgumentNames().size() >= functionDesc.getArgs().size() || function.isVarArgs()) result.addTooltipData( generateTooltipData(function, functionDesc.getCurrentArgIndex())); } } } return result; }