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.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private void amendExistingRoxygenBlock(int row, String objectName, JsArrayString argNames,
        JsArrayString argTypes, String tagName, Pattern pattern) {
    // Get the range encompassing this Roxygen block.
    Range range = getRoxygenBlockRange(row);

    // Extract that block (as an array of strings)
    JsArrayString block = extractRoxygenBlock(editor_.getWidget().getEditor(), range);

    // If the block contains roxygen parameters that require
    // non-local information (e.g. @inheritParams), then
    // bail./*from   www .  ja  v a2s  .  com*/
    for (int i = 0; i < block.length(); i++) {
        if (RE_ROXYGEN_NONLOCAL.test(block.get(i))) {
            view_.showWarningBar(
                    "Cannot automatically update roxygen blocks " + "that are not self-contained.");
            return;
        }
    }

    String roxygenDelim = RE_ROXYGEN.match(block.get(0), 0).getGroup(1);

    // The replacement block (we build by munging parts of
    // the old block
    JsArrayString replacement = JsArray.createArray().cast();

    // Scan through the block to get the names of
    // pre-existing parameters.
    JsArrayString params = listParametersInRoxygenBlock(block, pattern);

    // Figure out what parameters need to be removed, and remove them.
    // Any parameter not mentioned in the current function's argument list
    // should be stripped out.
    JsArrayString paramsToRemove = setdiff(params, argNames);

    int blockLength = block.length();
    for (int i = 0; i < blockLength; i++) {
        // If we encounter a param we don't want to extract, then
        // move over it.
        Match match = pattern.match(block.get(i), 0);
        if (match != null && contains(paramsToRemove, match.getGroup(1))) {
            i++;
            while (i < blockLength && !RE_ROXYGEN_WITH_TAG.test(block.get(i)))
                i++;

            i--;
            continue;
        }

        replacement.push(block.get(i));
    }

    // Now, add example roxygen for any parameters that are
    // present in the function prototype, but not present
    // within the roxygen block.
    int insertionPosition = findParamsInsertionPosition(replacement, pattern);
    JsArrayInteger indices = setdiffIndices(argNames, params);

    // NOTE: modifies replacement
    insertNewTags(replacement, argNames, argTypes, indices, roxygenDelim, tagName, insertionPosition);

    // Ensure space between final param and next tag
    ensureSpaceBetweenFirstParamAndPreviousEntry(replacement, roxygenDelim, pattern);
    ensureSpaceBetweenFinalParamAndNextTag(replacement, roxygenDelim, pattern);

    // Apply the replacement.
    editor_.getSession().replace(range, replacement.join("\n") + "\n");
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private void ensureSpaceBetweenFirstParamAndPreviousEntry(JsArrayString replacement, String roxygenDelim,
        Pattern pattern) {//from ww w . j  av a  2 s  .co m
    int n = replacement.length();
    for (int i = 1; i < n; i++) {
        if (pattern.test(replacement.get(i))) {
            if (!RE_ROXYGEN_EMPTY.test(replacement.get(i - 1)))
                spliceIntoArray(replacement, roxygenDelim, i);
            return;
        }
    }
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private void ensureSpaceBetweenFinalParamAndNextTag(JsArrayString replacement, String roxygenDelim,
        Pattern pattern) {/*www  .j  a v a2  s .com*/
    int n = replacement.length();
    for (int i = n - 1; i >= 0; i--) {
        if (pattern.test(replacement.get(i))) {
            i++;
            if (i < n && RE_ROXYGEN_WITH_TAG.test(replacement.get(i))) {
                spliceIntoArray(replacement, roxygenDelim, i);
            }
            return;
        }
    }
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private int findParamsInsertionPosition(JsArrayString block, Pattern pattern) {
    // Try to find the last '@param' block, and insert after that.
    int n = block.length();
    for (int i = n - 1; i >= 0; i--) {
        if (pattern.test(block.get(i))) {
            i++;//from  w w  w. ja  v a 2 s .  c o  m

            // Move up to the next tag (or end)
            while (i < n && !RE_ROXYGEN_WITH_TAG.test(block.get(i)))
                i++;

            return i - 1;
        }
    }

    // Try to find the first tag, and insert before that.
    for (int i = 0; i < n; i++)
        if (RE_ROXYGEN_WITH_TAG.test(block.get(i)))
            return i;

    // Just insert at the end
    return block.length();
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private static JsArrayString setdiff(JsArrayString self, JsArrayString other) {
    JsArrayString result = JsArray.createArray().cast();
    for (int i = 0; i < self.length(); i++)
        if (!contains(other, self.get(i)))
            result.push(self.get(i));/*  ww w. j  a v  a 2 s .c  o  m*/
    return result;
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private static JsArrayInteger setdiffIndices(JsArrayString self, JsArrayString other) {
    JsArrayInteger result = JsArray.createArray().cast();
    for (int i = 0; i < self.length(); i++)
        if (!contains(other, self.get(i)))
            result.push(i);/*  www .j  a  v a 2  s.  c  om*/
    return result;
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private JsArrayString listParametersInRoxygenBlock(JsArrayString block, Pattern pattern) {
    JsArrayString roxygenParams = JsArrayString.createArray().cast();
    for (int i = 0; i < block.length(); i++) {
        String line = block.get(i);
        Match match = pattern.match(line, 0);
        if (match != null)
            roxygenParams.push(match.getGroup(1));
    }// w  w  w .j  av  a2s. com

    return roxygenParams;
}

From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java

License:Open Source License

private String argsToExampleRoxygen(JsArrayString argNames, JsArrayString argTypes, String tagName) {
    String roxygen = "";
    if (argNames.length() == 0)
        return "";

    if (argTypes == null) {
        roxygen += argToExampleRoxygen(argNames.get(0), null, tagName);
        for (int i = 1; i < argNames.length(); i++)
            roxygen += "\n" + argToExampleRoxygen(argNames.get(i), null, tagName);
    } else {/*from   ww w  .  j  a  v  a2 s  .  c  om*/
        roxygen += argToExampleRoxygen(argNames.get(0), argTypes.get(0), tagName);
        for (int i = 1; i < argNames.length(); i++)
            roxygen += "\n" + argToExampleRoxygen(argNames.get(i), argTypes.get(i), tagName);
    }

    return roxygen;
}

From source file:org.rstudio.studio.client.common.spelling.ui.SpellingCustomDictionariesWidget.java

License:Open Source License

public void setDictionaries(JsArrayString dictionaries) {
    listBox_.clear();//from  ww w.ja  v a  2 s. c om
    for (int i = 0; i < dictionaries.length(); i++)
        listBox_.addItem(dictionaries.get(i));
}

From source file:org.rstudio.studio.client.common.spelling.view.SpellingSandboxDialog.java

License:Open Source License

private void suggestionList(String word) {
    server_.suggestionList(word, new SimpleRequestCallback<JsArrayString>() {
        @Override//from   w  ww .j  ava2 s  . co  m
        public void onResponseReceived(JsArrayString suggestions) {
            listBox_.clear();
            for (int i = 0; i < suggestions.length(); i++) {
                listBox_.addItem(suggestions.get(i));
            }
        }
    });

}