Example usage for com.google.gwt.core.client JsArray unshift

List of usage examples for com.google.gwt.core.client JsArray unshift

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArray unshift.

Prototype

public final native void unshift(T value) ;

Source Link

Document

Shifts a value onto the beginning of the array.

Usage

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionRequest.java

License:Open Source License

public void updateUI(boolean autoAccept) {
    if (invalidationToken_.isInvalid())
        return;/*from   w  w w. j  av a 2  s. c o  m*/

    // if we don't have the completion list back from the server yet
    // then just ignore this (this function will get called again when
    // the request completes)
    if (completions_ == null)
        return;

    // discover text already entered
    String userTypedText = getUserTypedText();

    // build list of entries (filter on text already entered)
    JsArray<CppCompletion> filtered = JsArray.createArray().cast();
    for (int i = 0; i < completions_.length(); i++) {
        CppCompletion completion = completions_.get(i);
        String typedText = completion.getTypedText();
        if ((userTypedText.length() == 0) || typedText.startsWith(userTypedText)) {
            // be more picky for member scope completions because clang
            // returns a bunch of noise like constructors, destructors, 
            // compiler generated assignments, etc.
            if (completionPosition_.getScope() == CompletionPosition.Scope.Member) {
                if (completion.getType() == CppCompletion.VARIABLE
                        || (completion.getType() == CppCompletion.FUNCTION
                                && !typedText.startsWith("operator="))) {
                    filtered.push(completion);
                }

            } else {
                filtered.push(completion);
            }
        }
    }

    // add in snippets if they are enabled andthis is a global scope
    if (uiPrefs_.enableSnippets().getValue()
            && (completionPosition_.getScope() == CompletionPosition.Scope.Global)) {
        ArrayList<String> snippets = snippets_.getAvailableSnippets();
        for (String snippet : snippets)
            if (snippet.startsWith(userTypedText)) {
                String content = snippets_.getSnippet(snippet).getContent();
                content = content.replace("\t", "  ");
                filtered.unshift(CppCompletion.createSnippetCompletion(snippet, content));
            }
    }

    // check for no hits on explicit request
    if ((filtered.length() == 0) && explicit_) {
        showCompletionPopup("(No matches)");
    }
    // check for auto-accept
    else if ((filtered.length() == 1) && autoAccept && explicit_) {
        applyValue(filtered.get(0));
    }
    // check for one completion that's already present
    else if (filtered.length() == 1 && filtered.get(0).getTypedText() == getUserTypedText()
            && filtered.get(0).getType() != CppCompletion.SNIPPET) {
        terminate();
    } else {
        showCompletionPopup(filtered);
    }
}