本文整理匯總了Java中com.intellij.openapi.editor.Document.getCharsSequence方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getCharsSequence方法的具體用法?Java Document.getCharsSequence怎麽用?Java Document.getCharsSequence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.Document
的用法示例。
在下文中一共展示了Document.getCharsSequence方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLineExtensions
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
@Override
public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) {
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document == null) {
return null;
}
Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (selectedTextEditor == null) {
return null;
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
LineNumbering lineNumbering = new LineNumbering(document.getCharsSequence());
Collection<PsiLet> letStatements = PsiTreeUtil.findChildrenOfType(psiFile, PsiLet.class);
String inferredType = null;
for (PsiLet letStatement : letStatements) {
int letOffset = letStatement.getTextOffset();
// TODO: I'm using the LineNumbering class to avoid frequent exceptions about read access,
// but I would prefer to use runReadAction method.
MerlinPosition letPosition = lineNumbering.offsetToPosition(letOffset);
// LogicalPosition letPosition = new LogicalPosition;
// letPosition[0] = selectedTextEditor.offsetToLogicalPosition(letOffset);
if (letPosition.line - 1 == lineNumber) {
inferredType = letStatement.getInferredType();
break;
}
}
/*
Function<PsiLet, String> findInferredType = letStatement -> {
// Found a let statement, try to get its type if in correct line number
final int[] letOffset = new int[]{-1};
// ApplicationManager.getApplication().runReadAction(() -> { // Freezing pb ?
letOffset[0] = letStatement.getTextOffset();
// });
// TODO: I'm using the LineNumbering class to avoid frequent exceptions about read access,
// but I would prefer to use runReadAction method.
MerlinPosition letPosition = lineNumbering.offsetToPosition(letOffset[0]);
// LogicalPosition letPosition = new LogicalPosition;
// ApplicationManager.getApplication().runReadAction(() -> {
// letPosition[0] = selectedTextEditor.offsetToLogicalPosition(letOffset);
// });
return letPosition.line - 1 == lineNumber ? letStatement.getInferredType() : null;
};
String inferredType;
inferredType = letStatements.parallelStream().map(findInferredType).filter(Objects::nonNull).findFirst().orElse(null);
*/
if (inferredType == null) {
return null;
}
final TextAttributes attributes = getNormalAttributes();
LineExtensionInfo info = new LineExtensionInfo(" " + inferredType, attributes);
return Collections.singletonList(info);
}
示例2: 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;
}
示例3: 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;
}