Java 类org.eclipse.jface.text.contentassist.ICompletionProposal 实例源码

项目:n4js    文件:JSDocCompletionProposalComputer.java   
private void createLineTagProposal(String prefix, N4JSDocletParser docletParser,
        ArrayList<ICompletionProposal> proposals) {
    int replacementOffset = offset - prefix.length();
    // create line tag proposals
    for (ITagDefinition td : docletParser.getLineTagDictionary().getTagDefinitions()) {
        String tagString = '@' + td.getTitle() + ' ';
        if (tagString.startsWith(prefix)) {

            int replacementLength = prefix.length();
            int cursorPosition = tagString.length();
            ICompletionProposal proposal = new CompletionProposal(tagString, replacementOffset,
                    replacementLength, cursorPosition);
            proposals.add(proposal);
        }
    }
}
项目:n4js    文件:ImportsAwareReferenceProposalCreator.java   
/**
 * Creates initial proposal adjusted for the N4JS imports. Then passes that proposal to the provided delegate
 * proposal factory. Obtained ICompletionProposal is configured with a FQNImporter as custom text. applier.
 *
 * @param candidate
 *            for which proposal is created
 * @param delegateProposalFactory
 *            delegate proposal factory
 * @return code completion proposal
 */
private ICompletionProposal getProposal(IEObjectDescription candidate, EObject model,
        IScope scope,
        EReference reference,
        ContentAssistContext context,
        Predicate<IEObjectDescription> filter,
        Function<IEObjectDescription, ICompletionProposal> delegateProposalFactory) {

    final IEObjectDescription inputToUse = getAliasedDescription(candidate, reference, context);
    final ICompletionProposal result = delegateProposalFactory.apply(inputToUse);

    if (result instanceof ConfigurableCompletionProposal) {
        final FQNImporter importer = fqnImporterFactory.create(
                model.eResource(),
                scope,
                valueConverter,
                filter,
                context.getViewer());

        ((ConfigurableCompletionProposal) result).setTextApplier(importer);
    }
    return result;
}
项目:ContentAssist    文件:JavaCompletionProposalComputer1.java   
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> propList = new ArrayList<ICompletionProposal>();
    List<ICompletionProposal> newpropList = new ArrayList<ICompletionProposal>();
    List<IContextInformation> propList2 = new ArrayList<IContextInformation>();

    ICompletionProposal first;
    DataManager datamanger = new DataManager(context,monitor);
    Activator.applyoperationlist.add(new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList));
    List<String> list = new ArrayList();
    CompletionProposal proposal;
    propList = datamanger.JavaDefaultProposal();
    propList2 = datamanger.ContextInformation();
    ApplyOperation ao = new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList);
    System.out.println(ao.toString());
    return newpropList;
}
项目:eclipse-batch-editor    文件:BatchEditorSimpleWordContentAssistProcessor.java   
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    IDocument document = viewer.getDocument();
    if (document == null) {
        return null;
    }
    String source = document.get();

    Set<String> words = simpleWordCompletion.calculate(source, offset);

    ICompletionProposal[] result = new ICompletionProposal[words.size()];
    int i = 0;
    for (String word : words) {
        result[i++] = new SimpleWordProposal(document, offset, word);
    }

    return result;
}
项目:eclipse-bash-editor    文件:BashEditorSimpleWordContentAssistProcessor.java   
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    IDocument document = viewer.getDocument();
    if (document == null) {
        return null;
    }
    String source = document.get();

    Set<String> words = simpleWordCompletion.calculate(source, offset);

    ICompletionProposal[] result = new ICompletionProposal[words.size()];
    int i = 0;
    for (String word : words) {
        result[i++] = new SimpleWordProposal(document, offset, word);
    }

    return result;
}
项目:Hydrograph    文件:HydrographCompletionProposalComputer.java   
private void filterProposalsOnPrefix(String prefix, List<ICompletionProposal> props) {
    if (prefix != null && prefix.trim().length() > 0) {
        Iterator<ICompletionProposal> iterator = props.iterator();
        String prefixLc = prefix.toLowerCase();

        {
            while (iterator.hasNext()) {
                ICompletionProposal item = (ICompletionProposal) iterator.next();
                String content = item.getDisplayString().toLowerCase(Locale.ENGLISH);
                if (!content.toLowerCase(Locale.ENGLISH).startsWith(prefixLc)) {
                    iterator.remove();
                }
            }
        }
    }
}
项目:vertigo-chroma-kspplugin    文件:BaseContentAssistProcessor.java   
/**
 * Constuit les propositions d'aucomplétion.
 * 
 * @param suggestions Suggestionsà proposer.
 * @param currentWordSelection Mot courant à remplacer dans le document.
 * @return Propositions d'autocomplétion.
 */
private ICompletionProposal[] buildProposals(List<CompletionCandidate> suggestions, ITextSelection currentWordSelection) {
    /* Calcul l'offset et la longueur du mot à remplacer dans le document. */
    int replacementLength = currentWordSelection.getLength();
    int replacementOffset = currentWordSelection.getOffset();

    /* Construit les propositions en parcourant les suggestions. */
    List<ICompletionProposal> proposals = new ArrayList<>();
    for (CompletionCandidate suggestion : suggestions) {
        /* String qui remplacera le mot courant. */
        String replacementString = suggestion.getDisplayString();

        /* String affiché comme libellé de la proposition. */
        String displayString = replacementString;

        /* String affiché comme description de la proposition (dans la boîte jaune). */
        String additionalProposalInfo = suggestion.getAdditionalProposalInfo();
        CompletionProposal proposal = new CompletionProposal(replacementString, replacementOffset, replacementLength, replacementString.length(), null,
                displayString, null, additionalProposalInfo);
        proposals.add(proposal);
    }
    return proposals.toArray(new ICompletionProposal[0]);
}
项目:Tarski    文件:LoadCompletionProcessor.java   
private void addProposals(List<ICompletionProposal> proposals, String prefix,
    int replacementOffset, String type) {

  Collection<IFile> files = null;
  if (MetaModelPartitionScanner.META_MODEL_LOADMODEL.equals(type)) {
    files = allEcoreFiles.values();
  } else if (MetaModelPartitionScanner.META_MODEL_LOADINSTANCE.equals(type)) {
    files = allFiles.values();
  }

  if (files == null)
    return;

  for (IFile iFile : files) {
    String path = iFile.getFullPath().toString();
    if (path.toLowerCase().startsWith(prefix.toLowerCase())
        || iFile.getName().toLowerCase().startsWith(prefix.toLowerCase())) {
      proposals.add(new CompletionProposal(path, replacementOffset, prefix.length(),
          path.length(), null, iFile.getName() + " - " + path, null, null));
    }
  }
}
项目:solidity-ide    文件:SolidityContentProposalPriorities.java   
@Override
protected void adjustPriority(ICompletionProposal proposal, String prefix, int priority) {
    if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal))
        return;
    ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
    if (castedProposal.getPriority() != getDefaultPriority())
        return;
    int adjustedPriority = priority;
    if (!Strings.isEmpty(prefix)) {
        if (castedProposal.getReplacementString().equals(prefix))
            adjustedPriority = (int) (adjustedPriority * sameTextMultiplier);
        else if (castedProposal.getReplacementString().startsWith(prefix))
            adjustedPriority = adjustedPriority * proposalWithPrefixMultiplier;
    }
    castedProposal.setPriority(adjustedPriority);
}
项目:egradle    文件:GradleContentAssistProcessor.java   
@Override
public void applied(ICompletionProposal proposal) {
    if (DEBUG) {
        debugCacheState("applied proposal-1");
    }
    /*
     * after apply the model must be changed and cursor position
     * normally changes as well! This often made problems
     */
    IEditorPart activeEditor = EclipseUtil.getActiveEditor();
    if (activeEditor instanceof AbstractGroovyBasedEditor) {
        GradleEditor ge = (GradleEditor) activeEditor;
        if (DEBUG) {
            debugCacheState("applied proposal-2");
        }
        ge.rebuildOutline();
        if (DEBUG) {
            debugCacheState("applied proposal-3");
        }
    }

}
项目:LibertyEiffel-Eclipse-Plugin    文件:EiffelContentAssistantProcessor.java   
@Override
    public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {

        try {
            List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>();
            IDocument document = viewer.getDocument();
            String prefix = lastWord(document, offset);
            String indent = lastIndent(document, offset);
//          EiffelModel model = EiffelModel.getModel(document, null);
//          model.getContentProposals(prefix, indent, offset, completionProposals);

            return completionProposals.toArray(new ICompletionProposal[completionProposals.size()]);

        } catch (Exception e) {
            return NO_COMPLETIONS;
        }
    }
项目:DarwinSPL    文件:DwprofileQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<de.darwinspl.preferences.resource.dwprofile.IDwprofileQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:DarwinSPL    文件:HyexpressionQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:DarwinSPL    文件:HyvalidityformulaQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:DarwinSPL    文件:HydatavalueQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:DarwinSPL    文件:HymappingQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:DarwinSPL    文件:HyconstraintsQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:DarwinSPL    文件:HymanifestQuickAssistProcessor.java   
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    int offset = -1;
    int length = 0;
    if (invocationContext instanceof TextInvocationContext) {
        TextInvocationContext textContext = (TextInvocationContext) invocationContext;
        offset = textContext.getOffset();
        length = textContext.getLength();
    }
    List<eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length);
    ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()];
    for (int i = 0; i < proposals.length; i++) {
        proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i));
    }
    return proposals;
}
项目:http4e    文件:Ch5CompletionEditor.java   
public ICompletionProposal[] computeCompletionProposals( ITextViewer textViewer, int documentOffset){
   IDocument document = textViewer.getDocument();
   int currOffset = documentOffset - 1;

   try {
      String currWord = "";
      char currChar;
      while (currOffset > 0 && !Character.isWhitespace(currChar = document.getChar(currOffset))) {
         currWord = currChar + currWord;
         currOffset--;
      }

      List suggestions = wordTracker.suggest(currWord);
      ICompletionProposal[] proposals = null;
      if (suggestions.size() > 0) {
         proposals = buildProposals(suggestions, currWord, documentOffset - currWord.length());
         lastError = null;
      }
      return proposals;
   } catch (BadLocationException e) {
      e.printStackTrace();
      lastError = e.getMessage();
      return null;
   }
}
项目:ftc    文件:FtcCompletionProcessor.java   
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {

    currentCompletions = getCompletions(viewer.getDocument().get(), documentOffset);

    ICompletionProposal[] templates = super.computeCompletionProposals(viewer, documentOffset);
    ICompletionProposal[] completions = getModelElementProposals(currentCompletions.modelElements, documentOffset, sourceViewer.getSelectedRange().y);

    ICompletionProposal[] result = new ICompletionProposal[templates.length + completions.length];

    int idx = 0;
    for (int i = 0; i < templates.length; i++) {
        result[idx] = templates[i];
        idx++;
    }
    for (int i = 0; i < completions.length; i++) {
        result[idx] = completions[i];
        idx++;
    }

    return result;
}
项目:ftc    文件:FtcVariableResolver.java   
@Override
protected String[] resolveAll(TemplateContext context) {

    Check.isTrue(context instanceof FtcDocumentTemplateContext);
    FtcDocumentTemplateContext ftcContext = (FtcDocumentTemplateContext) context;

    String pattern = ftcContext.getCurrentTemplate().getPattern();
    Check.notNull(pattern);
    String currentText = ftcContext.getDocument().get();
    ICompletionProposal[] proposals = createCompletionProposals(ftcContext.getCompletionOffset(), getType(),
            pattern, currentText);

    String[] result = new String[proposals.length];
    for (int i = 0; i < proposals.length; i++)
        result[i] = proposals[i].getDisplayString();
    return result;
}
项目:texlipse    文件:BibCompletionProcessor.java   
/**
 * Computes the abbreviation completions available based on the prefix.
 * 
 * @param offset Cursor offset in the document
 * @param replacementLength Length of the text to be replaced
 * @param prefix The start of the abbreviation or ""
 * @return An array containing all possible completions
 */
private ICompletionProposal[] computeAbbrevCompletions(int offset, int replacementLength, String prefix) {
    ReferenceEntry[] abbrevs = abbrManager.getCompletions(prefix);
    if (abbrevs == null)
        return null;

    ICompletionProposal[] result = new ICompletionProposal[abbrevs.length];

    for (int i = 0; i < abbrevs.length; i++) {         
        result[i] = new CompletionProposal(abbrevs[i].key,
                offset - replacementLength, replacementLength,
                abbrevs[i].key.length(), null, abbrevs[i].key, null,
                abbrevs[i].info);
    }
    return result;
}
项目:texlipse    文件:BibCompletionProcessor.java   
/**
 * Computes the template completions available based on the prefix.
 * 
 * @param offset Cursor offset in the document
 * @param replacementLength Length of the text to be replaced
 * @param prefix The start of the abbreviation or ""
 * @param viewer The viewer associated with this document 
 * @return An array containing all possible completions
 */
private ICompletionProposal[] computeTemplateCompletions(int offset, int replacementLength, String prefix, ITextViewer viewer) {
    List templateProposals = new ArrayList();
    this.templatesCompletion.addTemplateProposals(viewer, offset, templateProposals);
    ArrayList returnProposals = new ArrayList();

    for (Iterator iter = templateProposals.iterator(); iter.hasNext();) {
        ICompletionProposal proposal = (ICompletionProposal) iter.next();
        if (proposal.getDisplayString().startsWith(prefix)) {
            returnProposals.add(proposal);
        }
    }

    ICompletionProposal[] proposals = new ICompletionProposal[returnProposals.size()];
    returnProposals.toArray(proposals);

    Arrays.sort(proposals, proposalsComparator);
    return proposals;        
}
项目:texlipse    文件:TexTemplateCompletion.java   
/**
 * Adds all available TeX templates to the given list, available meaning here that
 * the templates match the found prefix.
 * 
 * @param viewer The viewer associated with this editor
 * @param documentOffset The offset in the document where the completions hould take place
 * @param prefix The prefix of the completion string
 * @return An <code>ArrayList</code> containing the <code>ICompletionProposals</code>
 */
public ArrayList addTemplateProposals(ITextViewer viewer, int documentOffset, String prefix) {
    ArrayList propList = new ArrayList();
    ICompletionProposal[] templateProposals = 
            computeCompletionProposals(viewer, documentOffset);

    // compute doesn't give the right proposal list for some reason,
    // so we need to filter here
    for (int j = 0; j < templateProposals.length; j++) {
        ICompletionProposal proposal = templateProposals[j];
        if (proposal.getDisplayString().startsWith(prefix)) {
            propList.add(templateProposals[j]);
        }
    }
    Collections.sort(propList, new CompletionProposalComparator());
    return propList;
}
项目:texlipse    文件:TexSpellingEngine.java   
@SuppressWarnings("unchecked")
@Override
public ICompletionProposal[] getProposals(IQuickAssistInvocationContext context) {
    List<Word> sugg = fError.getSuggestions();
    int length = fError.getInvalidWord().length();
    ICompletionProposal[] props = new ICompletionProposal[sugg.size() + 2];
    for (int i=0; i < sugg.size(); i++) {
        String suggestion = sugg.get(i).toString();
        String s = MessageFormat.format(CHANGE_TO,
                new Object[] { suggestion });
        props[i] = new CompletionProposal(suggestion, 
                fOffset, length, suggestion.length(), fCorrectionImage, s, null, null);
    }
    props[props.length - 2] = new IgnoreProposal(ignore, fError.getInvalidWord(), context.getSourceViewer());
    props[props.length - 1] = new AddToDictProposal(fError, fLang, context.getSourceViewer());
    return props;
}
项目:texlipse    文件:TexCompletionProcessor.java   
/**
 * Computes and returns reference-proposals (labels).
 * 
 * @param offset
 *            Current cursor offset
 * @param replacementLength
 *            The length of the string to be replaced
 * @param prefix
 *            The already typed prefix of the entry to assist with
 * @return An array of completion proposals to use directly or null
 */
private ICompletionProposal[] computeRefCompletions(int offset,
        int replacementLength, String prefix) {
    List<ReferenceEntry> refEntries = refManager.getCompletionsRef(prefix);
    if (refEntries == null)
        return null;

    ICompletionProposal[] result = new ICompletionProposal[refEntries
            .size()];

    for (int i = 0; i < refEntries.size(); i++) {

        String infoText = null;
        ReferenceEntry ref = refEntries.get(i);

        if (ref.info != null) {
            infoText = (ref.info.length() > assistLineLength) ? wrapString(
                    ref.info, assistLineLength) : ref.info;
        }

        result[i] = new CompletionProposal(ref.key, offset
                - replacementLength, replacementLength, ref.key.length(),
                null, ref.key, null, infoText);
    }
    return result;
}
项目:texlipse    文件:TexCompletionProcessor.java   
/**
 * Calculates and returns the template completions proposals.
 * 
 * @param offset
 *            Current cursor offset
 * @param lineStart
 *            The already typed prefix of the entry to assist with
 * @param viewer
 *            The text viewer of this document
 * @return An array of completion proposals to use directly
 */
private ICompletionProposal[] computeTemplateCompletions(int offset,
        String lineStart, ITextViewer viewer) {
    int t = lineStart.lastIndexOf(' ');
    if (t < lineStart.lastIndexOf('\t'))
        t = lineStart.lastIndexOf('\t');
    String replacement = lineStart.substring(t + 1);

    List<ICompletionProposal> returnProposals = templatesCompletion
            .addTemplateProposals(viewer, offset, replacement);
    ICompletionProposal[] proposals = new ICompletionProposal[returnProposals
            .size()];

    returnProposals.toArray(proposals);
    return proposals;
}
项目:texlipse    文件:TexCompletionProcessor.java   
private ICompletionProposal[] computeStyleProposals(String selectedText,
        Point selectedRange) {
    if (styleManager == null) {
        styleManager = TexStyleCompletionManager.getInstance();
    }
    return styleManager.getStyleCompletions(selectedText, selectedRange);
    /*
     * ICompletionProposal[] result = new
     * ICompletionProposal[STYLETAGS.length];
     * 
     * // Loop through all styles for (int i = 0; i < STYLETAGS.length; i++)
     * { String tag = STYLETAGS[i];
     * 
     * // Compute replacement text String replacement = "{" + tag + " " +
     * selectedText + "}";
     * 
     * // Derive cursor position int cursor = tag.length() + 2;
     * 
     * // Compute a suitable context information IContextInformation
     * contextInfo = new ContextInformation(null, STYLELABELS[i]+" Style");
     * 
     * // Construct proposal result[i] = new CompletionProposal(replacement,
     * selectedRange.x, selectedRange.y, cursor, null, STYLELABELS[i],
     * contextInfo, replacement); } return result;
     */
}
项目:hybris-commerce-eclipse-plugin    文件:ImpexCommandContentAssistProcessor.java   
private Collection<? extends ICompletionProposal> addHeaderAttributes(String oldWord, int offset) {

    int bracketPos = StringUtils.lastIndexOf(oldWord, "[");
    int wordLength = oldWord.length();
    int replacementPos = wordLength - bracketPos;
    String word = StringUtils.substringAfterLast(oldWord, "[");
    List<String> keywords = Formatter.IMPEX_KEYWORDS_ATTRIBUTES;
    Collection<ICompletionProposal> result = Lists.newArrayList();

    for (String keyword : keywords) {
        if (keyword.toUpperCase(Locale.ENGLISH).startsWith(word.toUpperCase(Locale.ENGLISH)) && word.length() < keyword.length()) {

            result.add(new CompletionProposal(keyword + "=", (offset - replacementPos) + 1, word.length(), keyword.length() + 1));
        }
    }
    return result;

}
项目:hybris-commerce-eclipse-plugin    文件:ImpexTypeSystemContentAssistProcessor.java   
private ICompletionProposal[] attributeProposals(int cursorPosition, List<String> autoSuggests, String currentPart) {

    int counter = 0;
    ICompletionProposal[] proposals = new ICompletionProposal[autoSuggests.size()];
    for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
        String autoSuggest = (String)iter.next();

        if (currentPart.endsWith(";") || currentPart.endsWith("(")) {
            proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
        }
        else {
            int bracketStart = currentPart.indexOf("(");
            if (bracketStart > 0) {
                int a = (cursorPosition + 1) - (currentPart.length() - bracketStart);
                int b = currentPart.length() - (bracketStart + 1);
                int c = autoSuggest.length();
                proposals[counter] = new CompletionProposal(autoSuggest, a, b, c);
            }
            else {
                proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length());
            }
        }
        counter++;
    }
    return proposals;
}
项目:hybris-commerce-eclipse-plugin    文件:ImpexTypeAttributeContentAssistProcessor.java   
private ICompletionProposal[] attributeProposals(int cursorPosition, List<String> autoSuggests, String thisAttrib, String currentPart, boolean endingSemiColon) {

    int counter = 0;
    ICompletionProposal[] suggestions = new ICompletionProposal[autoSuggests.size()];
    for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
        String autoSuggest = (String)iter.next();

        //Each proposal contains the text to propose, as well as information about where to insert the text into the document.
        if (thisAttrib.endsWith(";") || thisAttrib.endsWith("(") || !endingSemiColon) {
            suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
        }
        else {
            suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length());
        }
        counter++;
    }
    return suggestions;
}
项目:angular-eclipse    文件:HTMLAngularCompletionCollector.java   
private void addProposal(ContentAssistRequest contentAssistRequest, String name, INgBindingType bindingType,
        String displayString, Image image, String additionalProposalInfo) {
    String alternateMatch = bindingType.formatAttr(name);
    StringBuilder replacementString = new StringBuilder(alternateMatch);
    if (!hasValue) {
        replacementString.append("=\"\"");
    }
    StringBuilder replacementStringCursor = new StringBuilder(alternateMatch);
    replacementStringCursor.append("=\"\"");

    int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
    int replacementLength = contentAssistRequest.getReplacementLength();
    int cursorPosition = getCursorPositionForProposedText(replacementStringCursor.toString());

    IContextInformation contextInformation = null;

    int relevance = XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME;

    ICompletionProposal proposal = new HTMLAngularCompletionProposal(replacementString.toString(),
            replacementOffset, replacementLength, cursorPosition, image, displayString, alternateMatch,
            contextInformation, additionalProposalInfo, relevance);
    contentAssistRequest.addProposal(proposal);
}
项目:mesfavoris    文件:SpellcheckableMessageArea.java   
private void addProposals(final SubMenuManager quickFixMenu) {
    IAnnotationModel sourceModel = sourceViewer.getAnnotationModel();
    Iterator annotationIterator = sourceModel.getAnnotationIterator();
    while (annotationIterator.hasNext()) {
        Annotation annotation = (Annotation) annotationIterator.next();
        boolean isDeleted = annotation.isMarkedDeleted();
        boolean isIncluded = includes(sourceModel.getPosition(annotation),
                getTextWidget().getCaretOffset());
        boolean isFixable = sourceViewer.getQuickAssistAssistant().canFix(
                annotation);
        if (!isDeleted && isIncluded && isFixable) {
            IQuickAssistProcessor processor = sourceViewer
            .getQuickAssistAssistant()
            .getQuickAssistProcessor();
            IQuickAssistInvocationContext context = sourceViewer
            .getQuickAssistInvocationContext();
            ICompletionProposal[] proposals = processor
            .computeQuickAssistProposals(context);

            for (ICompletionProposal proposal : proposals)
                quickFixMenu.add(createQuickFixAction(proposal));
        }
    }
}
项目:mesfavoris    文件:SpellcheckableMessageArea.java   
private IAction createQuickFixAction(final ICompletionProposal proposal) {
    return new Action(proposal.getDisplayString()) {

        @Override
        public void run() {
            proposal.apply(sourceViewer.getDocument());
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            Image image = proposal.getImage();
            if (image != null)
                return ImageDescriptor.createFromImage(image);
            return null;
        }
    };
}
项目:dsl-devkit    文件:TemplatesFirstCompletionProposalComparator.java   
/** {@inheritDoc} */
@SuppressWarnings({"rawtypes", "unchecked"})
public int compare(final ICompletionProposal o1, final ICompletionProposal o2) {

  // Template sorting by relevance and then alphabetically by name
  if (o1 instanceof TemplateProposal && o2 instanceof TemplateProposal) {
    TemplateProposal t1 = (TemplateProposal) o1;
    TemplateProposal t2 = (TemplateProposal) o2;
    if (t1.getRelevance() == t2.getRelevance()) {
      return o1.getDisplayString().compareTo(o2.getDisplayString());
    }
    return ((Integer) t1.getRelevance()).compareTo(t1.getRelevance());
  }
  // Templates always first
  if (o1 instanceof TemplateProposal) {
    return -1;
  } else if (o2 instanceof TemplateProposal) {
    return 1;
  }
  // Fallback
  if ((o1 instanceof Comparable) && (o2 instanceof Comparable)) {
    return ((Comparable) o1).compareTo(o2);
  }
  return o1.getDisplayString().compareTo(o2.getDisplayString());
}
项目:dsl-devkit    文件:AbstractAcfContentAssistTest.java   
/**
 * Iterate over given computed completion proposals and compare resulting display string with each expected proposal text. Fail if one or more expected
 * proposals not found.
 *
 * @param computedProposals
 *          the computed proposals
 * @param positiveTest
 *          indicates the type of test.
 *          TRUE: the test is positive and must fail if proposals not found.
 *          FALSE: the test is negative and must fail if proposals found.
 * @param proposals
 *          the expected proposals as display strings
 */
private void assertCompletionProposal(final ICompletionProposal[] computedProposals, final boolean positiveTest, final String... proposals) {
  assertFalse(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, proposals.length == 0);
  for (final String s : proposals) {
    boolean foundProposal = false;
    for (ICompletionProposal p : computedProposals) {
      if (s.equals(p.getDisplayString())) {
        foundProposal = true;
        break;
      }
    }
    if (positiveTest && !foundProposal) {
      fail(MessageFormat.format("Expected to find proposal \"{0}\" but could only find \"{1}\"", s, getCompletionProposalDisplayStrings(computedProposals)));
    } else if (!positiveTest && foundProposal) {
      fail(MessageFormat.format("Not expected to find proposal \"{0}\" but found \"{1}\"", s, getCompletionProposalDisplayStrings(computedProposals)));
    }
  }
}
项目:dsl-devkit    文件:AbstractAcfContentAssistTest.java   
/**
 * Asserts the expected valid and invalid proposals based on the given registered source filename.
 *
 * @param sourceFileName
 *          the filename of the test source that the proposals were to be computed from, must not be {@code null}
 */
@SuppressWarnings("restriction")
private void assertSourceProposals(final String sourceFileName) {
  try {
    AcfContentAssistProcessorTestBuilder builder = newBuilder().append(getTestSource(sourceFileName).getContent());
    assertFalse(EXPECTED_PROPOSALS_NOT_SET, (acfContentAssistMarkerTagInfo.expectedProposalMap.isEmpty()
        && acfContentAssistMarkerTagInfo.notExpectedProposalMap.isEmpty() && acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.isEmpty()));
    for (int markerId : getUsedTagsItems()) {
      final ICompletionProposal[] proposals = builder.computeCompletionProposals(getOffsetForTag(markerId));
      if (acfContentAssistMarkerTagInfo.expectedProposalMap.containsKey(markerId)) {
        assertCompletionProposal(proposals, acfContentAssistMarkerTagInfo.expectedProposalMap.get(markerId));
      }
      if (acfContentAssistMarkerTagInfo.notExpectedProposalMap.containsKey(markerId)) {
        assertNotCompletionProposal(proposals, acfContentAssistMarkerTagInfo.notExpectedProposalMap.get(markerId));
      }
      if (acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.containsKey(markerId)) {
        assertExactlyCompletionProposal(proposals, acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.get(markerId));
      }
    }
    // CHECKSTYLE:OFF
  } catch (Exception e) {
    // CHECKSTYLE:ON
    throw new WrappedException("Could not assert the expected valid and invalid proposals.", e);
  }
}
项目:dsl-devkit    文件:AcfContentAssistProcessorTestBuilder.java   
/**
 * Applies a content assist proposal using the expected display string.
 *
 * @param expectedDisplayString
 *          the content assist proposal to apply
 * @param appendSpace
 *          whether to append a space
 * @return a new {@link AcfContentAssistProcessorTestBuilder} with the text applied.
 * @throws Exception
 *           if there was a problem loading the xtext resource
 */
public AcfContentAssistProcessorTestBuilder applyText(final String expectedDisplayString, final boolean appendSpace) throws Exception {
  ICompletionProposal proposal = null;
  for (final ICompletionProposal p : computeCompletionProposals(getModel(), getCursorPosition())) {
    if (expectedDisplayString.equals(p.getDisplayString())) {
      proposal = p;
      break;
    }
  }
  assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
  String text = "";
  if (proposal instanceof ConfigurableCompletionProposal) {
    text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
  } else if (proposal instanceof XtextTemplateProposal) {
    // These may occur in the context of custom content assist templates
    text = ((XtextTemplateProposal) proposal).getAdditionalProposalInfo();
  }
  AcfContentAssistProcessorTestBuilder ret = append(text);
  if (appendSpace) {
    return ret.append(" ");
  }
  return ret;
}
项目:dsl-devkit    文件:AcfContentAssistProcessorTestBuilder.java   
/**
 * {@inheritDoc} Code copied from parent. Override required to run in UI because of getSourceViewer, which creates a new Shell.
 */
@Override
public ICompletionProposal[] computeCompletionProposals(final String currentModelToParse, final int cursorPosition) throws Exception {
  Pair<ICompletionProposal[], BadLocationException> result = UiThreadDispatcher.dispatchAndWait(new Function<Pair<ICompletionProposal[], BadLocationException>>() {
    @Override
    public Pair<ICompletionProposal[], BadLocationException> run() {
      final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse));
      final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
      return internalComputeCompletionProposals(cursorPosition, xtextDocument);
    }
  });
  if (result.getSecond() != null) {
    throw result.getSecond();
  }
  return result.getFirst();
}
项目:dsl-devkit    文件:AcfContentAssistProcessorTestBuilder.java   
/**
 * Internally compute completion proposals.
 *
 * @param cursorPosition
 *          the position of the cursor in the {@link IXtextDocument}
 * @param xtextDocument
 *          the {@link IXtextDocument}
 * @return a pair of {@link ICompletionProposal}[] and {@link BadLocationException}. If the tail argument is not {@code null}, an exception occurred in the UI
 *         thread.
 */
private Pair<ICompletionProposal[], BadLocationException> internalComputeCompletionProposals(final int cursorPosition, final IXtextDocument xtextDocument) {
  XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
  Shell shell = new Shell();
  try {
    ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
    IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
    String contentType = xtextDocument.getContentType(cursorPosition);
    IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
    if (processor != null) {
      return Tuples.create(processor.computeCompletionProposals(sourceViewer, cursorPosition), null);
    }
    return Tuples.create(new ICompletionProposal[0], null);
  } catch (BadLocationException e) {
    return Tuples.create(new ICompletionProposal[0], e);
  } finally {
    shell.dispose();
  }
}