use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlEncodingReferenceProvider method xmlAttributeValueRange.
protected static TextRange xmlAttributeValueRange(final XmlAttributeValue xmlAttributeValue) {
ASTNode valueNode = XmlChildRole.ATTRIBUTE_VALUE_VALUE_FINDER.findChild(xmlAttributeValue.getNode());
PsiElement toHighlight = valueNode == null ? xmlAttributeValue : valueNode.getPsi();
TextRange childRange = toHighlight.getTextRange();
TextRange range = xmlAttributeValue.getTextRange();
return childRange.shiftRight(-range.getStartOffset());
}
use of com.intellij.openapi.util.TextRange in project kotlin by JetBrains.
the class DiagnosticUtils method sortedDiagnostics.
@NotNull
public static List<Diagnostic> sortedDiagnostics(@NotNull Collection<Diagnostic> diagnostics) {
Comparator<Diagnostic> diagnosticComparator = new Comparator<Diagnostic>() {
@Override
public int compare(@NotNull Diagnostic d1, @NotNull Diagnostic d2) {
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
if (!path1.equals(path2))
return path1.compareTo(path2);
TextRange range1 = firstRange(d1.getTextRanges());
TextRange range2 = firstRange(d2.getTextRanges());
if (!range1.equals(range2)) {
return TEXT_RANGE_COMPARATOR.compare(range1, range2);
}
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
}
};
List<Diagnostic> result = Lists.newArrayList(diagnostics);
Collections.sort(result, diagnosticComparator);
return result;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GroovyMethodInliner method inlineUsage.
@Override
public void inlineUsage(@NotNull UsageInfo usage, @NotNull PsiElement referenced) {
PsiElement element = usage.getElement();
if (!(element instanceof GrExpression && element.getParent() instanceof GrCallExpression))
return;
final Editor editor = getCurrentEditorIfApplicable(element);
GrCallExpression call = (GrCallExpression) element.getParent();
RangeMarker marker = inlineReferenceImpl(call, myMethod, isOnExpressionOrReturnPlace(call), GroovyInlineMethodUtil.isTailMethodCall(call), editor);
// highlight replaced result
if (marker != null) {
Project project = referenced.getProject();
TextRange range = TextRange.create(marker);
GroovyRefactoringUtil.highlightOccurrencesByRanges(project, editor, new TextRange[] { range });
WindowManager.getInstance().getStatusBar(project).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting"));
if (editor != null) {
editor.getCaretModel().moveToOffset(marker.getEndOffset());
}
}
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GrInplaceParameterIntroducer method updateTitle.
@Override
protected void updateTitle(@Nullable GrVariable variable, String value) {
if (getPreviewEditor() == null || variable == null)
return;
final PsiElement declarationScope = ((PsiParameter) variable).getDeclarationScope();
if (declarationScope instanceof PsiMethod) {
final PsiMethod psiMethod = (PsiMethod) declarationScope;
final StringBuilder buf = new StringBuilder();
buf.append(psiMethod.getName()).append(" (");
boolean frst = true;
final List<TextRange> ranges2Remove = new ArrayList<>();
TextRange addedRange = null;
int i = 0;
for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
if (frst) {
frst = false;
} else {
buf.append(", ");
}
int startOffset = buf.length();
/*if (myMustBeFinal || myPanel.isGenerateFinal()) {
buf.append("final ");
}*/
buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName());
int endOffset = buf.length();
if (variable == parameter) {
addedRange = new TextRange(startOffset, endOffset);
} else if (myParametersToRemove.contains(i)) {
ranges2Remove.add(new TextRange(startOffset, endOffset));
}
i++;
}
assert addedRange != null;
buf.append(")");
setPreviewText(buf.toString());
final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true);
markupModel.removeAllHighlighters();
for (TextRange textRange : ranges2Remove) {
markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE);
}
markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE);
//revalidate();
}
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class ExtractUtil method getRangeOfRefactoring.
public static TextRange getRangeOfRefactoring(ExtractInfoHelper helper) {
final StringPartInfo stringPartInfo = helper.getStringPartInfo();
if (stringPartInfo != null) {
return stringPartInfo.getRange();
} else {
final GrStatement[] statements = helper.getStatements();
int start = statements[0].getTextRange().getStartOffset();
int end = statements[statements.length - 1].getTextRange().getEndOffset();
return new TextRange(start, end);
}
}
Aggregations