List of usage examples for com.google.gwt.core.client JsArrayString length
public final native int length() ;
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 ww w . j a v a 2 s .co m 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) {/* ww w . j a v a 2 s . c o 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 va 2 s . c om 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 ww w. j a 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));//from w w w . j a v a2 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);/*from w w w .j ava2 s.com*/ 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)); }/*from w w w . j a va 2 s . c om*/ return roxygenParams; }
From source file:org.rstudio.studio.client.common.r.roxygen.RoxygenHelper.java
License:Open Source License
private void insertRoxygenTemplate(String name, JsArrayString argNames, JsArrayString argTypes, String argTagName, String type, Position position) { String roxygenParams = argsToExampleRoxygen(argNames, argTypes, argTagName); // Add some spacing between params and the next tags, // if there were one or more arguments. if (argNames.length() != 0) roxygenParams += "\n#'\n"; String block = "#' Title\n" + "#'\n" + roxygenParams + "#' @return\n" + "#' @export\n" + "#'\n" + "#' @examples\n"; Position insertionPosition = Position.create(position.getRow(), 0); editor_.insertCode(insertionPosition, block); }
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 {/* w w w . ja v a 2s. co m*/ 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 w w w .j a v a 2 s. co m for (int i = 0; i < dictionaries.length(); i++) listBox_.addItem(dictionaries.get(i)); }