当前位置: 首页>>代码示例>>Java>>正文


Java Document.getTextLength方法代码示例

本文整理汇总了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);
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:EduAnswerPlaceholderPainter.java

示例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));
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:6,代码来源:QuoteHandler.java

示例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;
}
 
开发者ID:xylo,项目名称:intellij-postfix-templates,代码行数:63,代码来源:CustomJavaStringPostfixTemplate.java

示例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;
}
 
开发者ID:xylo,项目名称:intellij-postfix-templates,代码行数:54,代码来源:CustomKotlinStringPostfixTemplate.java

示例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;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:47,代码来源:ResourceToManifoldUtil.java


注:本文中的com.intellij.openapi.editor.Document.getTextLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。