/** Complete will all stuff except directives for now */ protected void buildTrie() { this.trie = new AbstractTrie<>(); for (TemplateDotProvider provider : templating.getTemplateDotProviders()) { if ("DIRECTIVE".equals(provider.getType())) { continue; } trie.put(provider.getName(), provider); } }
@Override public void computeCompletionProposals( TextEditor textEditor, int offset, CodeAssistCallback codeAssistCallback) { IContext context = contextFactory.create(); String prefix = computePrefix(textEditor.getDocument(), offset); context.setPrefix(prefix); List<CompletionProposal> prop = new ArrayList<>(); String templatePrefix = computeTemplatePrefix(textEditor.getDocument(), offset); int dot = 0; int lastDot = Integer.MAX_VALUE; if (templatePrefix.length() > 0) { dot = templatePrefix.indexOf('.'); lastDot = templatePrefix.lastIndexOf('.'); } if (dot != -1 && dot == lastDot) { // get the current template provider String prefixVal = templatePrefix.substring(0, dot).trim(); String suffixVal = templatePrefix.substring(dot + 1, templatePrefix.length()); AbstractTrie<String> subTrie = new AbstractTrie<>(); for (TemplateDotProvider provider : templating.getTemplateDotProviders()) { if (prefixVal.equals(provider.getName())) { // add all methods List<Method> methods = provider.getMethods(); if (methods != null) { for (Method m : methods) { String fullName = m.getName(); if (m.getParams() != null && m.getParams().size() > 0) { fullName = fullName.concat("("); int i = 1; for (Param param : m.getParams()) { fullName = fullName.concat(param.getName()); if (i < m.getParams().size()) { fullName = fullName.concat(","); } i++; } fullName = fullName.concat(")"); } else { fullName = fullName.concat("()"); } subTrie.put(m.getName(), fullName); } } } } List<String> result = subTrie.search(suffixVal); Collections.sort(result, String.CASE_INSENSITIVE_ORDER); for (String st : result) { TemplateProposal templateProposal = new TemplateProposal( templatePrefix, st, prefixVal.concat(".").concat(st), offset, javaScriptResources); templateProposal.setMethod(); prop.add(templateProposal); } } else if (dot == -1) { // Perform completion only if there is no dot List<TemplateDotProvider> result = trie.search(prefix); Collections.sort( result, new Comparator<TemplateDotProvider>() { @Override public int compare(TemplateDotProvider o1, TemplateDotProvider o2) { return o1.getName().compareTo(o2.getName()); } }); for (TemplateDotProvider provider : result) { prop.add( new TemplateProposal( templatePrefix, provider.getName(), provider.getName(), offset, javaScriptResources)); } } try { JsArray<JsProposal> jsProposals = provider.computeProposals(textEditor.getDocument().getContents(), offset, context); if (jsProposals != null && jsProposals.length() != 0) { for (int i = 0; i < jsProposals.length(); i++) { JsProposal jsProposal = jsProposals.get(i); CompletionProposal proposal = new JavaScriptProposal(prefix, jsProposal, offset, javaScriptResources); prop.add(proposal); } } } catch (Exception ignore) { ignore.printStackTrace(); } List<CompletionProposal> proposals = new ArrayList<>(); for (int i = 0; i < prop.size(); i++) { proposals.add(prop.get(i)); } codeAssistCallback.proposalComputed(proposals); }