本文整理汇总了Java中com.intellij.util.DocumentUtil.getLineTextRange方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentUtil.getLineTextRange方法的具体用法?Java DocumentUtil.getLineTextRange怎么用?Java DocumentUtil.getLineTextRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.util.DocumentUtil
的用法示例。
在下文中一共展示了DocumentUtil.getLineTextRange方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFirstElementOnTheLine
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@Nullable
public static PsiElement getFirstElementOnTheLine(PsiLambdaExpression lambda, Document document, int line) {
ApplicationManager.getApplication().assertReadAccessAllowed();
TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
if (!intersects(lineRange, lambda)) return null;
PsiElement body = lambda.getBody();
if (body == null || !intersects(lineRange, body)) return null;
if (body instanceof PsiCodeBlock) {
for (PsiStatement statement : ((PsiCodeBlock)body).getStatements()) {
if (intersects(lineRange, statement)) {
return statement;
}
}
return null;
}
return body;
}
示例2: getLineElements
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private static Iterable<PsiElement> getLineElements(final PsiFile file, int lineNumber) {
ApplicationManager.getApplication().assertReadAccessAllowed();
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null || lineNumber >= document.getLineCount()) {
return EmptyIterable.getInstance();
}
final TextRange lineRange = DocumentUtil.getLineTextRange(document, lineNumber);
return new Iterable<PsiElement>() {
@Override
public Iterator<PsiElement> iterator() {
return new Iterator<PsiElement>() {
PsiElement myElement = DebuggerUtilsEx.findElementAt(file, lineRange.getStartOffset());
@Override
public boolean hasNext() {
return myElement != null;
}
@Override
public PsiElement next() {
PsiElement res = myElement;
do {
myElement = PsiTreeUtil.nextLeaf(myElement);
if (myElement == null || myElement.getTextOffset() > lineRange.getEndOffset()) {
myElement = null;
break;
}
} while (myElement.getTextLength() == 0);
return res;
}
@Override
public void remove() {}
};
}
};
}
示例3: addHighlighter
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void addHighlighter() {
adjustCounter(myEditor, 1);
int line = mySourcePosition.getLine();
Document document = myEditor.getDocument();
if (line < 0 || line >= document.getLineCount()) return;
//if (myNotTopFrame) {
// myEditor.getSelectionModel().setSelection(document.getLineStartOffset(line), document.getLineEndOffset(line) + document.getLineSeparatorLength(line));
// return;
//}
if (myRangeHighlighter != null) return;
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
TextAttributes attributes = myNotTopFrame ? scheme.getAttributes(DebuggerColors.NOT_TOP_FRAME_ATTRIBUTES)
: scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES);
MarkupModel markupModel = DocumentMarkupModel.forDocument(document, myProject, true);
if (mySourcePosition instanceof HighlighterProvider) {
TextRange range = ((HighlighterProvider)mySourcePosition).getHighlightRange();
if (range != null) {
TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
range = range.intersection(lineRange);
if (range != null && !range.isEmpty() && !range.equals(lineRange)) {
myRangeHighlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(),
DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes,
HighlighterTargetArea.EXACT_RANGE);
}
}
}
if (myRangeHighlighter == null) {
myRangeHighlighter = markupModel.addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes);
}
myRangeHighlighter.putUserData(EXECUTION_POINT_HIGHLIGHTER_KEY, true);
myRangeHighlighter.setGutterIconRenderer(myGutterIconRenderer);
}
示例4: addHighlighter
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private void addHighlighter() {
adjustCounter(myEditor, 1);
int line = mySourcePosition.getLine();
Document document = myEditor.getDocument();
if (line < 0 || line >= document.getLineCount()) return;
//if (myNotTopFrame) {
// myEditor.getSelectionModel().setSelection(document.getLineStartOffset(line), document.getLineEndOffset(line) + document.getLineSeparatorLength(line));
// return;
//}
if (myRangeHighlighter != null) return;
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
TextAttributes attributes = myNotTopFrame ? scheme.getAttributes(DebuggerColors.NOT_TOP_FRAME_ATTRIBUTES)
: scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES);
MarkupModel markupModel = DocumentMarkupModel.forDocument(document, myProject, true);
if (mySourcePosition instanceof HighlighterProvider) {
TextRange range = ((HighlighterProvider)mySourcePosition).getHighlightRange();
if (range != null) {
TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
range = range.intersection(lineRange);
if (range != null && !range.isEmpty() && !range.equals(lineRange)) {
myRangeHighlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(),
DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes,
HighlighterTargetArea.EXACT_RANGE);
}
}
}
if (myRangeHighlighter == null) {
myRangeHighlighter = markupModel.addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes);
}
myRangeHighlighter.putUserData(EXECUTION_POINT_HIGHLIGHTER_KEY, true);
myRangeHighlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());
myRangeHighlighter.setGutterIconRenderer(myGutterIconRenderer);
}
示例5: collectLambdas
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
public static List<PsiLambdaExpression> collectLambdas(@NotNull SourcePosition position, final boolean onlyOnTheLine) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFile file = position.getFile();
final int line = position.getLine();
final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null || line >= document.getLineCount()) {
return Collections.emptyList();
}
PsiElement element = position.getElementAt();
final TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
do {
PsiElement parent = element.getParent();
if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) {
break;
}
element = parent;
}
while(true);
final List<PsiLambdaExpression> lambdas = new ArrayList<PsiLambdaExpression>(3);
final PsiElementVisitor lambdaCollector = new JavaRecursiveElementVisitor() {
@Override
public void visitLambdaExpression(PsiLambdaExpression expression) {
super.visitLambdaExpression(expression);
if (!onlyOnTheLine || getFirstElementOnTheLine(expression, document, line) != null) {
lambdas.add(expression);
}
}
};
element.accept(lambdaCollector);
// add initial lambda if we're inside already
PsiElement method = getContainingMethod(element);
if (method instanceof PsiLambdaExpression) {
lambdas.add((PsiLambdaExpression)method);
}
for (PsiElement sibling = getNextElement(element); sibling != null; sibling = getNextElement(sibling)) {
if (!intersects(lineRange, sibling)) {
break;
}
sibling.accept(lambdaCollector);
}
return lambdas;
}
示例6: preprocessEnter
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@Override
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffsetRef, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) {
if (file instanceof JSGraphQLEndpointDocFile) {
int caretPos = caretOffsetRef.get();
final TextRange lineTextRange = DocumentUtil.getLineTextRange(editor.getDocument(), editor.offsetToLogicalPosition(caretPos).line);
final TextRange lineBeforeCaret = TextRange.create(lineTextRange.getStartOffset(), caretPos);
final TextRange lineAfterCaret = TextRange.create(caretPos, lineTextRange.getEndOffset());
if (!lineBeforeCaret.isEmpty()) {
final String lineBeforeCaretText = editor.getDocument().getText(lineBeforeCaret);
if (lineBeforeCaretText.contains("#")) {
EditorModificationUtil.insertStringAtCaret(editor, "# ");
if (lineAfterCaret.isEmpty()) {
caretAdvance.set(2);
} else {
// if there's text after the caret, the injected doc editor will be broken into two editors
// this means that we get an assertion error for isValid in case we try to move the caret
// instead, we schedule a re-indent plus end of line
if (editor instanceof EditorWindow) {
final Project project = file.getProject();
final Editor parentEditor = ((EditorWindow) editor).getDelegate();
final Application application = ApplicationManager.getApplication();
application.invokeLater(() -> {
final PsiFile parentPsiFile = PsiDocumentManager.getInstance(project).getPsiFile(parentEditor.getDocument());
if (parentPsiFile != null) {
application.runWriteAction(() -> {
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
if(!parentPsiFile.isValid()) {
return;
}
CodeStyleManager.getInstance(project).adjustLineIndent(parentPsiFile, parentEditor.getCaretModel().getOffset());
AnAction editorLineEnd = ActionManager.getInstance().getAction("EditorLineEnd");
if (editorLineEnd != null) {
final AnActionEvent actionEvent = AnActionEvent.createFromDataContext(
ActionPlaces.UNKNOWN,
null,
new DataManagerImpl.MyDataContext(parentEditor.getComponent())
);
editorLineEnd.actionPerformed(actionEvent);
}
}
}.execute();
});
}
});
}
}
}
}
}
return Result.Continue;
}
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:58,代码来源:JSGraphQLEndpointEnterHandlerDelegate.java
示例7: collectExecutableChildren
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@RequiredReadAction
public static Set<PsiElement> collectExecutableChildren(PsiFile psiFile, int line)
{
final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
if(document == null || line >= document.getLineCount())
{
return Collections.emptySet();
}
PsiElement element = DotNetDebuggerUtil.findPsiElement(psiFile, line);
final TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
do
{
if(element == null)
{
break;
}
PsiElement parent = element.getParent();
if(parent == null || (parent.getTextOffset() < lineRange.getStartOffset()))
{
break;
}
element = parent;
}
while(true);
PsiElement likeMethod = PsiTreeUtil.getParentOfType(element, DotNetQualifiedElement.class);
if(likeMethod == null)
{
return Collections.emptySet();
}
DotNetDebuggerSourceLineResolver resolver = DotNetDebuggerSourceLineResolverEP.INSTANCE.forLanguage(psiFile.getLanguage());
Set<PsiElement> allExecutableChildren = resolver.getAllExecutableChildren(element);
if(allExecutableChildren.isEmpty())
{
return Collections.emptySet();
}
Set<PsiElement> newSet = new LinkedHashSet<PsiElement>(allExecutableChildren.size() + 1);
newSet.add(likeMethod);
newSet.addAll(allExecutableChildren);
return newSet;
}
示例8: getLineElements
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
private static Iterable<PsiElement> getLineElements(final PsiFile file, int lineNumber)
{
ApplicationManager.getApplication().assertReadAccessAllowed();
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if(document == null || lineNumber < 0 || lineNumber >= document.getLineCount())
{
return EmptyIterable.getInstance();
}
final TextRange lineRange = DocumentUtil.getLineTextRange(document, lineNumber);
return new Iterable<PsiElement>()
{
@Override
public Iterator<PsiElement> iterator()
{
return new Iterator<PsiElement>()
{
PsiElement myElement = DebuggerUtilsEx.findElementAt(file, lineRange.getStartOffset());
@Override
public boolean hasNext()
{
return myElement != null;
}
@Override
public PsiElement next()
{
PsiElement res = myElement;
do
{
myElement = PsiTreeUtil.nextLeaf(myElement);
if(myElement == null || myElement.getTextOffset() > lineRange.getEndOffset())
{
myElement = null;
break;
}
}
while(myElement.getTextLength() == 0);
return res;
}
@Override
public void remove()
{
}
};
}
};
}
示例9: collectLambdas
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
public static List<PsiLambdaExpression> collectLambdas(@NotNull SourcePosition position, final boolean onlyOnTheLine)
{
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFile file = position.getFile();
final int line = position.getLine();
final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if(document == null || line >= document.getLineCount())
{
return Collections.emptyList();
}
PsiElement element = position.getElementAt();
if(element == null)
{
return Collections.emptyList();
}
final TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
do
{
PsiElement parent = element.getParent();
if(parent == null || (parent.getTextOffset() < lineRange.getStartOffset()))
{
break;
}
element = parent;
}
while(true);
final List<PsiLambdaExpression> lambdas = new SmartList<>();
final PsiElementVisitor lambdaCollector = new JavaRecursiveElementVisitor()
{
@Override
public void visitLambdaExpression(PsiLambdaExpression expression)
{
super.visitLambdaExpression(expression);
if(!onlyOnTheLine || getFirstElementOnTheLine(expression, document, line) != null)
{
lambdas.add(expression);
}
}
};
element.accept(lambdaCollector);
for(PsiElement sibling = getNextElement(element); sibling != null; sibling = getNextElement(sibling))
{
if(!intersects(lineRange, sibling))
{
break;
}
sibling.accept(lambdaCollector);
}
// add initial lambda if we're inside already
PsiElement method = getContainingMethod(element);
if(method instanceof PsiLambdaExpression && !lambdas.contains(method))
{
lambdas.add((PsiLambdaExpression) method);
}
return lambdas;
}
示例10: getFirstElementOnTheLine
import com.intellij.util.DocumentUtil; //导入方法依赖的package包/类
@Nullable
public static PsiElement getFirstElementOnTheLine(PsiLambdaExpression lambda, Document document, int line)
{
ApplicationManager.getApplication().assertReadAccessAllowed();
TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
if(!intersects(lineRange, lambda))
{
return null;
}
PsiElement body = lambda.getBody();
if(body == null || !intersects(lineRange, body))
{
return null;
}
if(body instanceof PsiCodeBlock)
{
PsiStatement[] statements = ((PsiCodeBlock) body).getStatements();
if(statements.length > 0)
{
for(PsiStatement statement : statements)
{
// return first statement starting on the line
if(lineRange.contains(statement.getTextOffset()))
{
return statement;
}
// otherwise check all children
else if(intersects(lineRange, statement))
{
for(PsiElement element : SyntaxTraverser.psiTraverser(statement))
{
if(lineRange.contains(element.getTextOffset()))
{
return element;
}
}
}
}
return null;
}
}
return body;
}