コード例 #1
0
 public FormulaFunctionProvider() {
   functions = new TreeMap<String, List<FormulaFunction>>();
   for (String setName : FormulaRegistry.getDefault().listFunctionSets()) {
     FormulaFunctionSet set = FormulaRegistry.getDefault().findFunctionSet(setName);
     for (FormulaFunction function : set.getFunctions()) {
       List<FormulaFunction> functionList = functions.get(function.getName());
       if (functionList == null) {
         functionList = new ArrayList<FormulaFunction>();
         functions.put(function.getName(), functionList);
       }
       functionList.add(function);
     }
   }
 }
コード例 #2
0
  @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;
  }
コード例 #3
0
 public void registerFormulaFunctionSet(FormulaFunctionSet formulaFunctionSet) {
   logger.info("register FormulaFunctionSet:" + formulaFunctionSet.getName());
   FormulaRegistry.getDefault().registerFormulaFunctionSet(formulaFunctionSet);
 }