本文整理匯總了Java中com.intellij.openapi.editor.Document.getTextLength方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getTextLength方法的具體用法?Java Document.getTextLength怎麽用?Java Document.getTextLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.Document
的用法示例。
在下文中一共展示了Document.getTextLength方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createGuardedBlocks
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder) {
Document document = editor.getDocument();
if (document instanceof DocumentImpl) {
DocumentImpl documentImpl = (DocumentImpl)document;
List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
Integer start = offsets.first;
Integer end = offsets.second;
if (start != 0) {
createGuardedBlock(editor, blocks, start - 1, start);
}
if (end != document.getTextLength()) {
createGuardedBlock(editor, blocks, end, end + 1);
}
}
}
示例2: getNextChar
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private String getNextChar(Document document, int offset) {
return offset >= document.getTextLength()
? " "
: document.getText(new TextRange(offset, offset + 1));
}
示例3: collectExpressions
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static List<PsiExpression> collectExpressions(final PsiFile file,
final Document document,
final int offset,
boolean acceptVoid) {
CharSequence text = document.getCharsSequence();
int correctedOffset = offset;
int textLength = document.getTextLength();
if (offset >= textLength) {
correctedOffset = textLength - 1;
} else if (!Character.isJavaIdentifierPart(text.charAt(offset))) {
correctedOffset--;
}
if (correctedOffset < 0) {
correctedOffset = offset;
} else if (!Character.isJavaIdentifierPart(text.charAt(correctedOffset))) {
if (text.charAt(correctedOffset) == ';') {//initially caret on the end of line
correctedOffset--;
}
if (correctedOffset < 0 || text.charAt(correctedOffset) != ')') {
correctedOffset = offset;
}
}
final PsiElement elementAtCaret = file.findElementAt(correctedOffset);
final List<PsiExpression> expressions = new ArrayList<>();
/*for (PsiElement element : statementsInRange) {
if (element instanceof PsiExpressionStatement) {
final PsiExpression expression = ((PsiExpressionStatement)element).getExpression();
if (expression.getType() != PsiType.VOID) {
expressions.add(expression);
}
}
}*/
PsiExpression expression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
while (expression != null) {
if (!expressions.contains(expression) && !(expression instanceof PsiParenthesizedExpression) && !(expression instanceof PsiSuperExpression) &&
(acceptVoid || !PsiType.VOID.equals(expression.getType()))) {
if (expression instanceof PsiMethodReferenceExpression) {
expressions.add(expression);
} else if (!(expression instanceof PsiAssignmentExpression)) {
if (!(expression instanceof PsiReferenceExpression)) {
expressions.add(expression);
} else {
if (!(expression.getParent() instanceof PsiMethodCallExpression)) {
final PsiElement resolve = ((PsiReferenceExpression) expression).resolve();
if (!(resolve instanceof PsiClass) && !(resolve instanceof PsiPackage)) {
expressions.add(expression);
}
}
}
}
}
expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class);
}
/*
for (PsiElement psiElement : expressions) {
System.out.println("parent: " + psiElement + " at " + psiElement.getTextRange());
}
*/
return expressions;
}
示例4: collectExpressions
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static List<PsiElement> collectExpressions(final PsiFile file,
final Document document,
final int offset,
boolean acceptVoid) {
CharSequence text = document.getCharsSequence();
int correctedOffset = offset;
int textLength = document.getTextLength();
if (offset >= textLength) {
correctedOffset = textLength - 1;
} else if (!Character.isJavaIdentifierPart(text.charAt(offset))) {
correctedOffset--;
}
if (correctedOffset < 0) {
correctedOffset = offset;
} else if (!Character.isJavaIdentifierPart(text.charAt(correctedOffset))) {
if (text.charAt(correctedOffset) == ';') {//initially caret on the end of line
correctedOffset--;
}
if (correctedOffset < 0 || text.charAt(correctedOffset) != ')') {
correctedOffset = offset;
}
}
final PsiElement elementAtCaret = file.findElementAt(correctedOffset);
final List<PsiElement> expressions = new ArrayList<>();
PsiElement expression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiElement.class);
while (expression != null && expression.getTextRange().getEndOffset() == elementAtCaret.getTextRange().getEndOffset()) {
//System.out.println(expression + " - " + expression.getText() + " - " + expression.getTextRange());
final PsiElement finalExpression = expression;
if (expression.getPrevSibling() == null || expression.getPrevSibling().getNode().getElementType() == TokenType.WHITE_SPACE) {
if (expressions.stream().noneMatch(pe -> finalExpression.getTextRange().equals(pe.getTextRange()))) {
expressions.add(expression);
}
} else {
//System.out.println("prevSilbing: " + expression.getPrevSibling().getNode().getElementType());
}
//expression = PsiTreeUtil.getParentOfType(expression, KtExpression.class);
expression = expression.getParent();
}
// TODO: For an unknown reason this code completion works only with a single expression and not with multiple ones.
// TODO: Therefore we have to cut our list to a singleton list.
if (expressions.isEmpty()) {
return expressions;
}
ArrayList<PsiElement> es = new ArrayList<>();
es.add(expressions.get(0));
//es.add(expressions.get(expressions.size()-1));
return es;
}
示例5: getWordAtCaretEnd
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static int getWordAtCaretEnd( Project project, String filePath )
{
Editor[] editor = new Editor[1];
editor[0] = getActiveEditor( project );
if( !(editor[0] instanceof EditorImpl) )
{
return -1;
}
EditorImpl editorImpl = (EditorImpl)editor[0];
if( !editorImpl.getVirtualFile().getPath().equals( filePath ) )
{
return -1;
}
CaretModel cm = editorImpl.getCaretModel();
Document document = editorImpl.getDocument();
int offset = cm.getOffset();
if( offset >= document.getTextLength() - 1 || document.getLineCount() == 0 )
{
return offset;
}
int newOffset = offset + 1;
int lineNumber = cm.getLogicalPosition().line;
int maxOffset = document.getLineEndOffset( lineNumber );
if( newOffset > maxOffset )
{
if( lineNumber + 1 >= document.getLineCount() )
{
return offset;
}
maxOffset = document.getLineEndOffset( lineNumber + 1 );
}
for( ; newOffset < maxOffset; newOffset++ )
{
if( EditorActionUtil.isWordOrLexemeEnd( editorImpl, newOffset, false ) )
{
break;
}
}
return newOffset;
}