org.netbeans.editor.Utilities.getRowFirstNonWhite()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.netbeans.editor.Utilities.getRowFirstNonWhite()方法的一些代码示例,展示了Utilities.getRowFirstNonWhite()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.getRowFirstNonWhite()方法的具体详情如下:
包路径:org.netbeans.editor.Utilities
类名称:Utilities
方法名:getRowFirstNonWhite

Utilities.getRowFirstNonWhite介绍

[英]Get the first non-white character on the line. The document.isWhitespace() is used to test whether the particular character is white space or not.
[中]获取行中的第一个非白色字符。文件。isWhitespace()用于测试特定字符是否为空白。

代码示例

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor

public DisableHint(BaseDocument doc, int offset) {
  this.doc = doc;
  try {
    this.offset = Utilities.getRowFirstNonWhite(doc, offset);
  } catch (BadLocationException ble) {
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

/** Get indentation on the current line. If this line is white then
* return -1.
* @param doc document to operate on
* @param offset position in document anywhere on the line
* @return indentation or -1 if the line is white
*/
public static int getRowIndent(BaseDocument doc, int offset)
throws BadLocationException {
  offset = getRowFirstNonWhite(doc, offset);
  if (offset == -1) {
    return -1;
  }
  return doc.getVisColFromPos(offset);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor

/**
 * Return true iff the line for the given offset is a comment line.
 * This will return false for lines that contain comments (even when the
 * offset is within the comment portion) but also contain code.
 */
public static boolean isCommentOnlyLine(BaseDocument doc, int offset)
  throws BadLocationException {
  int begin = Utilities.getRowFirstNonWhite(doc, offset);
  if (begin == -1) {
    return false; // whitespace only
  }
  if (begin == doc.getLength()) {
    return false;
  }
  return false; //doc.getText(begin, 2).equals("//") || doc.getText(begin, 1).equals("*");
}

代码示例来源:origin: net.java.abeille/abeille

/**
 * Get indentation on the current line. If this line is white then return
 * -1.
 * 
 * @param doc
 *            document to operate on
 * @param offset
 *            position in document anywhere on the line
 * @return indentation or -1 if the line is white
 */
public static int getRowIndent(BaseDocument doc, int offset) throws BadLocationException {
  offset = getRowFirstNonWhite(doc, offset);
  if (offset == -1) {
    return -1;
  }
  return doc.op.getVisColFromPos(offset);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

/** Get indentation on the current line. If this line is white then
* go either up or down an return indentation of the first non-white row.
* The <tt>getRowFirstNonWhite()</tt> is used to find the indentation
* on particular line.
* @param doc document to operate on
* @param offset position in document anywhere on the line
* @param downDir if this flag is set to true then if the row is white
*   then the indentation of the next first non-white row is returned. If it's
*   false then the indentation of the previous first non-white row is returned.
* @return indentation or -1 if there's no non-white line in the specified direction
*/
public static int getRowIndent(BaseDocument doc, int offset, boolean downDir)
throws BadLocationException {
  int p = getRowFirstNonWhite(doc, offset);
  if (p == -1) {
    p = getFirstNonWhiteRow(doc, offset, downDir);
    if (p == -1) {
      return -1; // non-white line not found
    }
    p = getRowFirstNonWhite(doc, p);
    if (p == -1) {
      return -1; // non-white line not found
    }
  }
  return doc.getVisColFromPos(p);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-rhtml

private boolean allComments(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
  for (int offset = startOffset; lineCount > 0; lineCount--) {
    int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
    if (firstNonWhitePos != -1) { // Ignore empty lines
      if (!isLineCommented(doc, firstNonWhitePos)) {
        return false;
      }
    }
    
    offset = Utilities.getRowStart(doc, offset, +1);
  }
  return true;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby

/**
 * Return true iff the line for the given offset is a Ruby comment line.
 * This will return false for lines that contain comments (even when the
 * offset is within the comment portion) but also contain code.
 */
public static boolean isCommentOnlyLine(BaseDocument doc, int offset)
  throws BadLocationException {
  int begin = Utilities.getRowFirstNonWhite(doc, offset);
  if (begin == -1) {
    return false; // whitespace only
  }
  if (begin == doc.getLength()) {
    return false;
  }
  return doc.getText(begin, 1).equals("#");
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

protected boolean hasTextBefore(JTextComponent target, String typedText) {
  BaseDocument doc = Utilities.getDocument(target);
  int dotPos = target.getCaret().getDot();
  try {
    int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
    return dotPos != fnw+typedText.length();
  } catch (BadLocationException e) {
    return false;
  }
}

代码示例来源:origin: net.java.abeille/abeille

protected boolean hasTextBefore(JTextComponent target, String typedText) {
  BaseDocument doc = Utilities.getDocument(target);
  int dotPos = target.getCaret().getDot();
  try {
    int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
    return dotPos != fnw + typedText.length();
  } catch (BadLocationException e) {
    return false;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor

private boolean isJavaDocComment(BaseDocument doc, int offset, int endOfLine) throws BadLocationException {
  int pos = Utilities.getRowFirstNonWhite(doc, offset);
  if (pos != -1) {
    Token<GroovyTokenId> token = LexUtilities.getToken(doc, pos);
    if (token != null) {
      TokenId id = token.id();
      if (id == GroovyTokenId.BLOCK_COMMENT) {
        String text = doc.getText(offset, endOfLine - offset);
        if (text.trim().startsWith("*")) {
          return true;
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor

/**
 * Return true iff the line for the given offset is a JavaScript comment line.
 * This will return false for lines that contain comments (even when the
 * offset is within the comment portion) but also contain code.
 */
public static boolean isCommentOnlyLine(BaseDocument doc, int offset)
  throws BadLocationException {
  int begin = Utilities.getRowFirstNonWhite(doc, offset);
  if (begin == -1) {
    return false; // whitespace only
  }
  Token<? extends PHPTokenId> token = LexUtilities.getToken(doc, begin);
  if (token != null) {
    return token.id() == PHPTokenId.PHP_LINE_COMMENT;
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor

private boolean isJustCommentOnLine(int rowStartOffset) throws BadLocationException {
  boolean result = false;
  int rowFirstNonWhite = Utilities.getRowFirstNonWhite(baseDocument, rowStartOffset);
  int rowLastNonWhite = Utilities.getRowLastNonWhite(baseDocument, rowStartOffset);
  for (OffsetRange commentRange : commentRanges) {
    if (commentRange.containsInclusive(rowFirstNonWhite) && commentRange.containsInclusive(rowLastNonWhite)) {
      result = true;
      break;
    }
  }
  return result;
}

代码示例来源:origin: net.java.abeille/abeille

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
      Caret caret = target.getCaret();
      try {
        int pos = Utilities.getRowFirstNonWhite((BaseDocument) target.getDocument(), caret.getDot());
        if (pos >= 0) {
          if (select) {
            caret.moveDot(pos);
          }
          else {
            caret.setDot(pos);
          }
        }
      } catch (BadLocationException e) {
        target.getToolkit().beep();
      }
    }
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
      Caret caret = target.getCaret();
      try {
        int pos = Utilities.getRowFirstNonWhite((BaseDocument)target.getDocument(),
                            caret.getDot());
        if (pos >= 0) {
          if (select) {
            caret.moveDot(pos);
          } else {
            caret.setDot(pos);
          }
        }
      } catch (BadLocationException e) {
        target.getToolkit().beep();
      }
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelutil

public static String getContextLine(CsmFile csmFile, final int stToken, final int endToken) {
  CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(csmFile);
  StyledDocument stDoc = CsmUtilities.openDocument(ces);
  String displayText = null;
  if (stDoc instanceof BaseDocument) {
    BaseDocument doc = (BaseDocument) stDoc;
    try {
      int startLine = Utilities.getRowFirstNonWhite(doc, stToken);
      int endLine = Utilities.getRowLastNonWhite(doc, endToken) + 1;
      displayText = doc.getText(startLine, endLine - startLine);
    } catch (BadLocationException ex) {
      // skip
    }
  }
  return displayText;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor

private boolean isEndIndent(BaseDocument doc, int offset) throws BadLocationException {
  int lineBegin = Utilities.getRowFirstNonWhite(doc, offset);
  if (lineBegin != -1) {
    Token<GroovyTokenId> token = LexUtilities.getToken(doc, lineBegin);
    if (token == null) {
      return false;
    }
    TokenId id = token.id();
    // If the line starts with an end-marker, such as "end", "}", "]", etc.,
    // find the corresponding opening marker, and indent the line to the same
    // offset as the beginning of that line.
    return (LexUtilities.isIndentToken(id) && !LexUtilities.isBeginToken(id, doc, offset)) ||
      id == GroovyTokenId.RBRACE || id == GroovyTokenId.RBRACKET || id == GroovyTokenId.RPAREN;
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-refactoring

private boolean isScope(CsmReference ref) {
  CsmFile csmFile = ref.getContainingFile();
  int stToken = ref.getStartOffset();
  int endToken = ref.getEndOffset();
  CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(csmFile);
  StyledDocument stDoc = CsmUtilities.openDocument(ces);
  if (stDoc instanceof BaseDocument) {
    BaseDocument doc = (BaseDocument) stDoc;
    try {
      int startLine = Utilities.getRowFirstNonWhite(doc, stToken);
      int endLine = Utilities.getRowLastNonWhite(doc, endToken) + 1;
      String restText = doc.getText(endToken, endLine - startLine).trim();
      return restText.startsWith("::"); //NOI18N
    } catch (BadLocationException ex) {
      // skip
    }
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelutil

public static String getContextLineHtml(CsmFile csmFile, final int stToken, final int endToken, boolean tokenInBold) {
  CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(csmFile);
  StyledDocument stDoc = CsmUtilities.openDocument(ces);
  String displayText = null;
  if (stDoc instanceof BaseDocument) {
    BaseDocument doc = (BaseDocument) stDoc;
    try {
      int stOffset = stToken;
      int endOffset = endToken;
      int startLine = Utilities.getRowFirstNonWhite(doc, stOffset);
      int endLine = Utilities.getRowLastNonWhite(doc, endOffset) + 1;
      if (!tokenInBold) {
        stOffset = -1;
        endOffset = -1;
      }
      displayText = getLineHtml(startLine, endLine, stOffset, endOffset, doc);
    } catch (BadLocationException ex) {
      // skip
    }
  }
  return displayText;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby

int rowStart = Utilities.getRowFirstNonWhite(doc, lexOffset);
if (rowStart != -1 && lexOffset <= rowStart) {
  lexOffset = rowStart + 1;

代码示例来源:origin: net.java.abeille/abeille

/**
 * Change the indent of the given row. Document is atomically locked during
 * this operation.
 */
public void changeRowIndent(BaseDocument doc, int pos, int newIndent) throws BadLocationException {
  doc.atomicLock();
  try {
    if (newIndent < 0) {
      newIndent = 0;
    }
    int firstNW = Utilities.getRowFirstNonWhite(doc, pos);
    if (firstNW == -1) { // valid first non-blank
      firstNW = Utilities.getRowEnd(doc, pos);
    }
    int bolPos = Utilities.getRowStart(doc, pos);
    doc.remove(bolPos, firstNW - bolPos); // !!! indent by spaces/tabs
    doc.insertString(bolPos, getIndentString(doc, newIndent), null);
  } finally {
    doc.atomicUnlock();
  }
}

相关文章