use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class SliceTestUtil method fill.
private static void fill(Map<String, RangeMarker> sliceUsageName2Offset, String name, int offset, final TIntObjectHashMap<IntArrayList> flownOffsets) {
for (int i = 1; i < 9; i++) {
String newName = name + i;
RangeMarker marker = sliceUsageName2Offset.get(newName);
if (marker == null)
break;
IntArrayList offsets = flownOffsets.get(offset);
if (offsets == null) {
offsets = new IntArrayList();
flownOffsets.put(offset, offsets);
}
int newStartOffset = marker.getStartOffset();
offsets.add(newStartOffset);
fill(sliceUsageName2Offset, newName, newStartOffset, flownOffsets);
}
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class ShowIntentionsPass method addAvailableFixesForGroups.
private static void addAvailableFixesForGroups(@NotNull HighlightInfo info, @NotNull Editor editor, @NotNull PsiFile file, @NotNull List<HighlightInfo.IntentionActionDescriptor> outList, int group, int offset) {
if (info.quickFixActionMarkers == null)
return;
if (group != -1 && group != info.getGroup())
return;
boolean fixRangeIsNotEmpty = !info.getFixTextRange().isEmpty();
Editor injectedEditor = null;
PsiFile injectedFile = null;
for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
RangeMarker range = pair.second;
if (!range.isValid() || fixRangeIsNotEmpty && isEmpty(range))
continue;
if (DumbService.isDumb(file.getProject()) && !DumbService.isDumbAware(actionInGroup.getAction())) {
continue;
}
int start = range.getStartOffset();
int end = range.getEndOffset();
final Project project = file.getProject();
if (start > offset || offset > end) {
continue;
}
Editor editorToUse;
PsiFile fileToUse;
if (info.isFromInjection()) {
if (injectedEditor == null) {
injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(file, offset);
injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
}
editorToUse = injectedEditor;
fileToUse = injectedFile;
} else {
editorToUse = editor;
fileToUse = file;
}
if (actionInGroup.getAction().isAvailable(project, editorToUse, fileToUse)) {
outList.add(actionInGroup);
}
}
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class InstanceofExpressionPostfixTemplate method surroundExpression.
private static void surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull PsiExpression expr) throws IncorrectOperationException {
assert expr.isValid();
PsiType[] types = GuessManager.getInstance(project).guessTypeToCast(expr);
final boolean parenthesesNeeded = expr instanceof PsiPolyadicExpression || expr instanceof PsiConditionalExpression || expr instanceof PsiAssignmentExpression;
String exprText = parenthesesNeeded ? "(" + expr.getText() + ")" : expr.getText();
Template template = generateTemplate(project, exprText, types);
TextRange range;
if (expr.isPhysical()) {
range = expr.getTextRange();
} else {
RangeMarker rangeMarker = expr.getUserData(ElementToWorkOn.TEXT_RANGE);
if (rangeMarker == null) {
PostfixTemplatesUtils.showErrorHint(project, editor);
return;
}
range = new TextRange(rangeMarker.getStartOffset(), rangeMarker.getEndOffset());
}
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
editor.getCaretModel().moveToOffset(range.getStartOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
TemplateManager.getInstance(project).startTemplate(editor, template);
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class StatementMover method surroundWithCodeBlock.
private void surroundWithCodeBlock(@NotNull final MoveInfo info, final boolean down) {
try {
final Document document = PsiDocumentManager.getInstance(statementToSurroundWithCodeBlock.getProject()).getDocument(statementToSurroundWithCodeBlock.getContainingFile());
int startOffset = document.getLineStartOffset(info.toMove.startLine);
int endOffset = getLineStartSafeOffset(document, info.toMove.endLine);
if (document.getText().charAt(endOffset - 1) == '\n')
endOffset--;
final RangeMarker lineRangeMarker = document.createRangeMarker(startOffset, endOffset);
final PsiElementFactory factory = JavaPsiFacade.getInstance(statementToSurroundWithCodeBlock.getProject()).getElementFactory();
PsiCodeBlock codeBlock = factory.createCodeBlock();
codeBlock.add(statementToSurroundWithCodeBlock);
final PsiBlockStatement blockStatement = (PsiBlockStatement) factory.createStatementFromText("{}", statementToSurroundWithCodeBlock);
blockStatement.getCodeBlock().replace(codeBlock);
PsiBlockStatement newStatement = (PsiBlockStatement) statementToSurroundWithCodeBlock.replace(blockStatement);
newStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(newStatement);
info.toMove = new LineRange(document.getLineNumber(lineRangeMarker.getStartOffset()), document.getLineNumber(lineRangeMarker.getEndOffset()) + 1);
PsiCodeBlock newCodeBlock = newStatement.getCodeBlock();
if (down) {
PsiElement blockChild = firstNonWhiteElement(newCodeBlock.getFirstBodyElement(), true);
if (blockChild == null)
blockChild = newCodeBlock.getRBrace();
info.toMove2 = new //document.getLineNumber(newCodeBlock.getParent().getTextRange().getStartOffset()),
LineRange(//document.getLineNumber(newCodeBlock.getParent().getTextRange().getStartOffset()),
info.toMove2.startLine, document.getLineNumber(blockChild.getTextRange().getStartOffset()));
} else {
int start = document.getLineNumber(newCodeBlock.getRBrace().getTextRange().getStartOffset());
int end = info.toMove.startLine;
if (start > end)
end = start;
info.toMove2 = new LineRange(start, end);
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class Bookmark method getLine.
public int getLine() {
int targetLine = myTarget.getLine();
if (targetLine == -1)
return targetLine;
//What user sees in gutter
RangeHighlighterEx highlighter = findMyHighlighter();
if (highlighter != null && highlighter.isValid()) {
Document document = getDocument();
if (document != null) {
return document.getLineNumber(highlighter.getStartOffset());
}
}
RangeMarker marker = myTarget.getRangeMarker();
if (marker != null && marker.isValid()) {
Document document = marker.getDocument();
return document.getLineNumber(marker.getStartOffset());
}
return targetLine;
}
Aggregations