Example usage for com.google.gwt.core.client JsArrayString get

List of usage examples for com.google.gwt.core.client JsArrayString get

Introduction

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

Prototype

public final native String get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:org.rstudio.studio.client.workbench.ui.PaneConfig.java

License:Open Source License

private static JsArrayString copy(JsArrayString array) {
    if (array == null)
        return null;

    JsArrayString copy = JsArrayString.createArray().cast();
    for (int i = 0; i < array.length(); i++)
        copy.push(array.get(i));
    return copy;//from  w  ww  . j  a  v a2s  . co  m
}

From source file:org.rstudio.studio.client.workbench.ui.PaneManager.java

License:Open Source License

private ArrayList<LogicalWindow> createPanes(PaneConfig config) {
    ArrayList<LogicalWindow> results = new ArrayList<LogicalWindow>();

    JsArrayString panes = config.getPanes();
    for (int i = 0; i < 4; i++) {
        results.add(panesByName_.get(panes.get(i)));
    }/*from  ww  w  .jav a  2  s .  c o m*/
    return results;
}

From source file:org.rstudio.studio.client.workbench.ui.PaneManager.java

License:Open Source License

private ArrayList<Tab> tabNamesToTabs(JsArrayString tabNames) {
    ArrayList<Tab> tabList = new ArrayList<Tab>();
    for (int j = 0; j < tabNames.length(); j++)
        tabList.add(Enum.valueOf(Tab.class, tabNames.get(j)));
    return tabList;
}

From source file:org.rstudio.studio.client.workbench.views.connections.model.NewSparkConnectionContext.java

License:Open Source License

public final List<String> getClusterServers() {
    // start with primed servers
    ArrayList<String> servers = getDefaultClusterConnections();

    // add mru as necessary
    JsArrayString mruServers = getRemoteServers();
    for (int i = 0; i < mruServers.length(); i++)
        if (!servers.contains(mruServers.get(i)))
            servers.add(mruServers.get(i));

    return servers;
}

From source file:org.rstudio.studio.client.workbench.views.connections.model.NewSparkConnectionContext.java

License:Open Source License

private final List<String> getConnectionsOption() {
    ArrayList<String> connectionsOption = new ArrayList<String>();
    if (Desktop.isDesktop()) {
        connectionsOption.add(MASTER_LOCAL);
        connectionsOption.add(MASTER_CLUSTER);
    } else {// w w w .jav  a  2  s  .com
        JsArrayString connectionsNative = getConnectionsOptionNative();
        for (int i = 0; i < connectionsNative.length(); i++)
            connectionsOption.add(connectionsNative.get(i));
    }

    return connectionsOption;
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionCache.java

License:Open Source License

private Completions narrow(String line, String substring, Completions original) {
    // no need to narrow when line + substring are equivalent
    if (line.equals(substring))
        return original;

    // Construct the new completion token by taking the original
    // completion token, and adding the delta between the new line and
    // the original completion line used.
    String token = original.getToken() + line.substring(substring.length());

    // Extract the vector elements of the completion string
    JsArrayString completions = original.getCompletions();
    JsArrayString packages = original.getPackages();
    JsArrayBoolean quote = original.getQuote();
    JsArrayInteger type = original.getType();
    JsArrayString meta = original.getMeta();

    // Now, generate narrowed versions of the above
    final JsVectorString completionsNarrow = JsVectorString.createVector().cast();
    final JsVectorString packagesNarrow = JsVectorString.createVector().cast();
    final JsVectorBoolean quoteNarrow = JsVectorBoolean.createVector().cast();
    final JsVectorInteger typeNarrow = JsVectorInteger.createVector().cast();
    final JsVectorString metaNarrow = JsVectorString.createVector().cast();

    for (int i = 0, n = completions.length(); i < n; i++) {
        boolean isSubsequence = StringUtil.isSubsequence(completions.get(i), token, true);
        if (isSubsequence) {
            completionsNarrow.push(completions.get(i));
            packagesNarrow.push(packages.get(i));
            quoteNarrow.push(quote.get(i));
            typeNarrow.push(type.get(i));
            metaNarrow.push(meta.get(i));
        }/*from w  w w . j av a2 s.c  om*/
    }

    // Finally, sort these based on score
    List<Integer> indices = new ArrayList<Integer>();
    for (int i = 0, n = completionsNarrow.size(); i < n; i++)
        indices.add(i);

    // Sort our indices vector
    Collections.sort(indices, new Comparator<Integer>() {
        @Override
        public int compare(Integer lhs, Integer rhs) {
            int lhsType = typeNarrow.get(lhs);
            int rhsType = typeNarrow.get(rhs);

            String lhsName = completionsNarrow.get(lhs);
            String rhsName = completionsNarrow.get(rhs);

            int lhsScore = CodeSearchOracle.scoreMatch(lhsName, token, false);
            int rhsScore = CodeSearchOracle.scoreMatch(rhsName, token, false);

            if (lhsType == RCompletionType.ARGUMENT)
                lhsType -= 3;
            if (rhsType == RCompletionType.ARGUMENT)
                rhsType -= 3;

            if (lhsScore == rhsScore)
                return lhsName.compareTo(rhsName);

            return lhsScore < rhsScore ? -1 : 1;
        }
    });

    // Finally, re-arrange our vectors.
    final JsVectorString completionsSorted = JsVectorString.createVector().cast();
    final JsVectorString packagesSorted = JsVectorString.createVector().cast();
    final JsVectorBoolean quoteSorted = JsVectorBoolean.createVector().cast();
    final JsVectorInteger typeSorted = JsVectorInteger.createVector().cast();
    final JsVectorString metaSorted = JsVectorString.createVector().cast();

    for (int i = 0, n = indices.size(); i < n; i++) {
        int index = indices.get(i);
        completionsSorted.push(completionsNarrow.get(index));
        packagesSorted.push(packagesNarrow.get(index));
        quoteSorted.push(quoteNarrow.get(index));
        typeSorted.push(typeNarrow.get(index));
        metaSorted.push(metaNarrow.get(index));
    }

    // And return the completion result
    return Completions.createCompletions(token, completionsSorted.cast(), packagesSorted.cast(),
            quoteSorted.cast(), typeSorted.cast(), metaSorted.cast(), original.getGuessedFunctionName(),
            original.getExcludeOtherCompletions(), original.getOverrideInsertParens(), original.isCacheable(),
            original.getHelpHandler(), original.getLanguage());
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.java

License:Open Source License

private void fillCompletionResult(Completions response, boolean implicit,
        ServerRequestCallback<CompletionResult> callback) {
    JsArrayString comp = response.getCompletions();
    JsArrayString pkgs = response.getPackages();
    JsArrayBoolean quote = response.getQuote();
    JsArrayInteger type = response.getType();
    ArrayList<QualifiedName> newComp = new ArrayList<QualifiedName>();
    for (int i = 0; i < comp.length(); i++) {
        newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i)));
    }// w  w  w . j  av a2 s  .c o m

    CompletionResult result = new CompletionResult(response.getToken(), newComp,
            response.getGuessedFunctionName(), response.getSuggestOnAccept(),
            response.getOverrideInsertParens());

    if (response.isCacheable()) {
        cachedCompletions_.put("", result);
    }

    if (!implicit || result.completions.size() != 0)
        callback.onResponseReceived(result);

}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.java

License:Open Source License

public void getCompletions(final String token, final List<String> assocData, final List<Integer> dataType,
        final List<Integer> numCommas, final String functionCallString, final String chainDataName,
        final JsArrayString chainAdditionalArgs, final JsArrayString chainExcludeArgs,
        final boolean chainExcludeArgsFromObject, final String filePath, final String documentId,
        final boolean implicit, final ServerRequestCallback<CompletionResult> callback) {
    boolean isHelp = dataType.size() > 0 && dataType.get(0) == AutocompletionContext.TYPE_HELP;

    if (usingCache(token, isHelp, callback))
        return;/*from   w w w. java2 s .  co m*/

    doGetCompletions(token, assocData, dataType, numCommas, functionCallString, chainDataName,
            chainAdditionalArgs, chainExcludeArgs, chainExcludeArgsFromObject, filePath, documentId,
            new ServerRequestCallback<Completions>() {
                @Override
                public void onError(ServerError error) {
                    callback.onError(error);
                }

                @Override
                public void onResponseReceived(Completions response) {
                    cachedLinePrefix_ = token;
                    String token = response.getToken();

                    JsArrayString comp = response.getCompletions();
                    JsArrayString pkgs = response.getPackages();
                    JsArrayBoolean quote = response.getQuote();
                    JsArrayInteger type = response.getType();
                    ArrayList<QualifiedName> newComp = new ArrayList<QualifiedName>();

                    // Get function completions from the server
                    for (int i = 0; i < comp.length(); i++)
                        if (comp.get(i).endsWith(" = "))
                            newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i)));

                    // Try getting our own function argument completions
                    if (!response.getExcludeOtherCompletions()) {
                        addFunctionArgumentCompletions(token, newComp);
                        addScopedArgumentCompletions(token, newComp);
                    }

                    // Get variable completions from the current scope
                    if (!response.getExcludeOtherCompletions()) {
                        addScopedCompletions(token, newComp, "variable");
                        addScopedCompletions(token, newComp, "function");
                    }

                    // Get other server completions
                    for (int i = 0; i < comp.length(); i++)
                        if (!comp.get(i).endsWith(" = "))
                            newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i)));

                    // Get snippet completions. Bail if this isn't a top-level
                    // completion -- TODO is to add some more context that allows us
                    // to properly ascertain this.
                    if (isTopLevelCompletionRequest())
                        addSnippetCompletions(token, newComp);

                    // Remove duplicates
                    newComp = resolveDuplicates(newComp);

                    CompletionResult result = new CompletionResult(response.getToken(), newComp,
                            response.getGuessedFunctionName(), response.getSuggestOnAccept(),
                            response.getOverrideInsertParens());

                    if (response.isCacheable()) {
                        cachedCompletions_.put("", result);
                    }

                    callback.onResponseReceived(result);
                }
            });
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.java

License:Open Source License

private void addScopedArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
    AceEditor editor = (AceEditor) editor_;

    // NOTE: this will be null in the console, so protect against that
    if (editor != null) {
        Position cursorPosition = editor.getSession().getSelection().getCursor();
        CodeModel codeModel = editor.getSession().getMode().getRCodeModel();
        JsArray<RFunction> scopedFunctions = codeModel.getFunctionsInScope(cursorPosition);

        if (scopedFunctions.length() == 0)
            return;

        String tokenLower = token.toLowerCase();

        for (int i = 0; i < scopedFunctions.length(); i++) {
            RFunction scopedFunction = scopedFunctions.get(i);
            String functionName = scopedFunction.getFunctionName();

            JsArrayString argNames = scopedFunction.getFunctionArgs();
            for (int j = 0; j < argNames.length(); j++) {
                String argName = argNames.get(j);
                if (argName.toLowerCase().startsWith(tokenLower)) {
                    if (functionName == null || functionName == "") {
                        completions.add(new QualifiedName(argName, "<anonymous function>", false,
                                RCompletionType.CONTEXT));
                    } else {
                        completions/*  w  w  w . j  a  v a2  s.  c o  m*/
                                .add(new QualifiedName(argName, functionName, false, RCompletionType.CONTEXT));
                    }
                }
            }
        }
    }
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.java

License:Open Source License

private void addFunctionArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
    AceEditor editor = (AceEditor) editor_;

    if (editor != null) {
        Position cursorPosition = editor.getSession().getSelection().getCursor();
        CodeModel codeModel = editor.getSession().getMode().getRCodeModel();

        // Try to see if we can find a function name
        TokenCursor cursor = codeModel.getTokenCursor();

        // NOTE: This can fail if the document is empty
        if (!cursor.moveToPosition(cursorPosition))
            return;

        String tokenLower = token.toLowerCase();
        if (cursor.currentValue() == "(" || cursor.findOpeningBracket("(", false)) {
            if (cursor.moveToPreviousToken()) {
                // Check to see if this really is the name of a function
                JsArray<ScopeFunction> functionsInScope = codeModel.getAllFunctionScopes();

                String tokenName = cursor.currentValue();
                for (int i = 0; i < functionsInScope.length(); i++) {
                    ScopeFunction rFunction = functionsInScope.get(i);
                    String fnName = rFunction.getFunctionName();
                    if (tokenName == fnName) {
                        JsArrayString args = rFunction.getFunctionArgs();
                        for (int j = 0; j < args.length(); j++) {
                            String arg = args.get(j);
                            if (arg.toLowerCase().startsWith(tokenLower))
                                completions.add(new QualifiedName(args.get(j) + " = ", fnName, false,
                                        RCompletionType.CONTEXT));
                        }//from   www.j a va 2s  .  c  om
                    }
                }
            }
        }
    }
}