mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
TextRange utility methods
This commit is contained in:
@@ -553,7 +553,7 @@ public class CompilerTask extends Task.Backgroundable {
|
||||
int offset = ((OpenFileDescriptor)navigatable).getOffset();
|
||||
return new TextRange(offset, offset);
|
||||
}
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
private class CloseListener extends ContentManagerAdapter implements ProjectManagerListener {
|
||||
|
||||
@@ -699,7 +699,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
private boolean containsErrorsPreventingOptimize(PsiFile file) {
|
||||
// ignore unresolved imports errors
|
||||
PsiImportList importList = ((PsiJavaFile)file).getImportList();
|
||||
final TextRange importsRange = importList == null ? new TextRange(0,0) : importList.getTextRange();
|
||||
final TextRange importsRange = importList == null ? TextRange.EMPTY_RANGE : importList.getTextRange();
|
||||
boolean hasErrorsExceptUnresolvedImports = !DaemonCodeAnalyzerImpl.processHighlights(myDocument, myProject, HighlightSeverity.ERROR, 0, myDocument.getTextLength(), new Processor<HighlightInfo>() {
|
||||
public boolean process(HighlightInfo error) {
|
||||
int infoStart = error.getActualStartOffset();
|
||||
|
||||
+3
-3
@@ -99,7 +99,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
textRange = new TextRange(0, 0);
|
||||
textRange = TextRange.EMPTY_RANGE;
|
||||
}
|
||||
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, message);
|
||||
IntentionAction fix = QUICK_FIX_FACTORY.createModifierListFix(method, PsiUtil.getAccessModifier(superAccessLevel), true, false);
|
||||
@@ -175,7 +175,7 @@ public class HighlightMethodUtil {
|
||||
PsiType returnType,
|
||||
String detailMessage) {
|
||||
String message = MessageFormat.format("{0}; {1}", createClashMethodMessage(method, superMethod, true), detailMessage);
|
||||
TextRange textRange = includeRealPositionInfo ? methodToHighlight.getReturnTypeElement().getTextRange() : new TextRange(0, 0);
|
||||
TextRange textRange = includeRealPositionInfo ? methodToHighlight.getReturnTypeElement().getTextRange() : TextRange.EMPTY_RANGE;
|
||||
HighlightInfo errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, message);
|
||||
IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, substitutedSuperReturnType, false);
|
||||
QuickFixAction.registerQuickFixAction(errorResult, fix);
|
||||
@@ -257,7 +257,7 @@ public class HighlightMethodUtil {
|
||||
textRange = exceptionContext.getTextRange();
|
||||
}
|
||||
else {
|
||||
textRange = new TextRange(0, 0);
|
||||
textRange = TextRange.EMPTY_RANGE;
|
||||
}
|
||||
HighlightInfo errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, message);
|
||||
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMethodThrowsFix(method, exception, false, false));
|
||||
|
||||
+1
-1
@@ -203,7 +203,7 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
|
||||
public static TextRange getMethodDeclarationTextRange(@NotNull PsiMethod method) {
|
||||
if (method instanceof JspHolderMethod) return new TextRange(0,0);
|
||||
if (method instanceof JspHolderMethod) return TextRange.EMPTY_RANGE;
|
||||
int start = stripAnnotationsFromModifierList(method.getModifierList());
|
||||
int end = method.getThrowsList().getTextRange().getEndOffset();
|
||||
return new TextRange(start, end);
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class MethodOrClassSelectioner extends BasicSelectioner {
|
||||
TextRange range = new TextRange(children[i].getTextRange().getStartOffset(), e.getTextRange().getEndOffset());
|
||||
result.addAll(expandToWholeLine(editorText, range));
|
||||
|
||||
range = new TextRange(firstChild.getTextRange().getStartOffset(), firstChild.getTextRange().getEndOffset());
|
||||
range = TextRange.create(firstChild.getTextRange());
|
||||
result.addAll(expandToWholeLine(editorText, range));
|
||||
}
|
||||
else if (firstChild instanceof PsiComment) {
|
||||
|
||||
@@ -533,7 +533,7 @@ public class JavaFoldingBuilder extends FoldingBuilderEx implements DumbAware {
|
||||
final String text = list.getText();
|
||||
if (text.startsWith("<") && text.endsWith(">") && text.length() > ifLongerThan) {
|
||||
final TextRange range = list.getTextRange();
|
||||
addFoldRegion(foldElements, list, document, true, new TextRange(range.getStartOffset(), range.getEndOffset()));
|
||||
addFoldRegion(foldElements, list, document, true, range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil
|
||||
|
||||
public final TextRange getTextRange() {
|
||||
PsiElement mirror = getMirror();
|
||||
return mirror != null ? mirror.getTextRange() : new TextRange(0, 0);
|
||||
return mirror != null ? mirror.getTextRange() : TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
public final int getStartOffsetInParent() {
|
||||
|
||||
@@ -146,7 +146,7 @@ public class PsiNameValuePairImpl extends CompositePsiElement implements PsiName
|
||||
if (id != null) {
|
||||
return new TextRange(0, id.getTextLength());
|
||||
}
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
public PsiElement resolve() {
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.util.Segment;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -37,7 +38,7 @@ import java.util.List;
|
||||
* @see AnnotationHolder
|
||||
* @see com.intellij.openapi.editor.markup.RangeHighlighter
|
||||
*/
|
||||
public final class Annotation {
|
||||
public final class Annotation implements Segment {
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
private final HighlightSeverity mySeverity;
|
||||
@@ -64,7 +65,7 @@ public final class Annotation {
|
||||
|
||||
@Deprecated
|
||||
public QuickFixInfo(final IntentionAction quickFix, final TextRange textRange, final List<IntentionAction> options, String displayName) {
|
||||
this.key = null;
|
||||
key = null;
|
||||
this.quickFix = quickFix;
|
||||
this.textRange = textRange;
|
||||
this.displayName = quickFix.getText();
|
||||
|
||||
@@ -198,7 +198,7 @@ public class FileStatusMap implements Disposable {
|
||||
}
|
||||
LOG.assertTrue(status.dirtyScopes.containsKey(passId), "Unknown pass " + passId);
|
||||
RangeMarker marker = status.dirtyScopes.get(passId);
|
||||
return marker == null ? null : marker.isValid() ? new TextRange(marker.getStartOffset(), marker.getEndOffset()) : new TextRange(0, document.getTextLength());
|
||||
return marker == null ? null : marker.isValid() ? TextRange.create(marker) : new TextRange(0, document.getTextLength());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public class FileStatusMap implements Disposable {
|
||||
if (old == null) {
|
||||
return document.createRangeMarker(scope);
|
||||
}
|
||||
TextRange oldRange = new TextRange(old.getStartOffset(), old.getEndOffset());
|
||||
TextRange oldRange = TextRange.create(old);
|
||||
TextRange union = scope.union(oldRange);
|
||||
if (old.isValid() && union.equals(oldRange)) {
|
||||
return old;
|
||||
|
||||
+1
-1
@@ -452,7 +452,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
private static TextRange findNearestTextRange(final DocumentWindow documentWindow, final int startOffset) {
|
||||
TextRange textRange = null;
|
||||
for (RangeMarker marker : documentWindow.getHostRanges()) {
|
||||
TextRange curRange = InjectedLanguageUtil.toTextRange(marker);
|
||||
TextRange curRange = ProperTextRange.create(marker);
|
||||
if (curRange.getStartOffset() > startOffset && textRange != null) break;
|
||||
textRange = curRange;
|
||||
}
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass implements DumbAware {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.LocalInspectionsPass");
|
||||
private static final int NUM_ELEMENTS_PER_CHECK_CANCELLED = 5;
|
||||
public static final TextRange EMPTY_PRIORITY_RANGE = new TextRange(0, 0);
|
||||
public static final TextRange EMPTY_PRIORITY_RANGE = TextRange.EMPTY_RANGE;
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
private final TextRange myPriorityRange;
|
||||
|
||||
+1
-2
@@ -44,7 +44,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -138,7 +137,7 @@ public class UpdateHighlightersUtil {
|
||||
};
|
||||
|
||||
void recycleHighlighter(RangeHighlighter highlighter) {
|
||||
incinerator.putValue(InjectedLanguageUtil.toTextRange(highlighter), highlighter);
|
||||
incinerator.putValue(ProperTextRange.create(highlighter), highlighter);
|
||||
}
|
||||
|
||||
RangeHighlighter pickupHighlighterFromGarbageBin(int startOffset, int endOffset, int layer){
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String pastedText = document.getText(new TextRange(bounds.getStartOffset(), bounds.getEndOffset()));
|
||||
String pastedText = document.getText(TextRange.create(bounds));
|
||||
if (pastedText.trim().indexOf("\n") < 0) {
|
||||
// don't indent single-line text
|
||||
return;
|
||||
|
||||
@@ -231,7 +231,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
caretModel.moveToOffset(bounds.getEndOffset());
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
selectionModel.removeSelection();
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION, new TextRange(bounds.getStartOffset(), bounds.getEndOffset()));
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION, TextRange.create(bounds));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class DocumentFoldingInfo implements JDOMExternalizable, CodeFoldingState
|
||||
boolean expanded = region.isExpanded();
|
||||
boolean collapseByDefault = element != null &&
|
||||
FoldingPolicy.isCollapseByDefault(element) &&
|
||||
!FoldingUtil.caretInsideRange(editor, new TextRange(region.getStartOffset(), region.getEndOffset()));
|
||||
!FoldingUtil.caretInsideRange(editor, TextRange.create(region));
|
||||
if (collapseByDefault != !expanded || element == null) {
|
||||
if (element != null) {
|
||||
myPsiElementsOrRangeMarkers.add(element);
|
||||
|
||||
+1
-1
@@ -182,7 +182,7 @@ class UpdateFoldRegionsOperation implements Runnable {
|
||||
}
|
||||
else if (region.isValid() && info.isLightRegion(region)) {
|
||||
boolean isExpanded = region.isExpanded();
|
||||
rangeToExpandStatusMap.put(new TextRange(region.getStartOffset(), region.getEndOffset()),
|
||||
rangeToExpandStatusMap.put(TextRange.create(region),
|
||||
isExpanded ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
else {
|
||||
|
||||
+2
-2
@@ -321,7 +321,7 @@ public class HighlightUsagesHandler extends HighlightHandlerBase {
|
||||
RangeHighlighter[] highlighters = ((HighlightManagerImpl)HighlightManager.getInstance(editor.getProject())).getHighlighters(editor);
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
for (RangeHighlighter highlighter : highlighters) {
|
||||
if (new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset()).grown(1).contains(caretOffset)) {
|
||||
if (TextRange.create(highlighter).grown(1).contains(caretOffset)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -348,7 +348,7 @@ public class HighlightUsagesHandler extends HighlightHandlerBase {
|
||||
int j = 0;
|
||||
while (i < highlighters.length && j < rangesToHighlight.size()) {
|
||||
RangeHighlighter highlighter = highlighters[i];
|
||||
TextRange highlighterRange = new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset());
|
||||
TextRange highlighterRange = TextRange.create(highlighter);
|
||||
TextRange refRange = rangesToHighlight.get(j);
|
||||
if (refRange.equals(highlighterRange) && attributes.equals(highlighter.getTextAttributes()) &&
|
||||
highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.impl.source.tree.injected.Place;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
@@ -235,7 +234,7 @@ public class DocumentWindowImpl extends UserDataHolderBase implements Disposable
|
||||
public TextRange getHostRange(int hostOffset) {
|
||||
for (PsiLanguageInjectionHost.Shred shred : myShreds) {
|
||||
RangeMarker currentRange = shred.getHostRangeMarker();
|
||||
TextRange textRange = InjectedLanguageUtil.toTextRange(currentRange);
|
||||
TextRange textRange = ProperTextRange.create(currentRange);
|
||||
if (textRange.grown(1).contains(hostOffset)) return textRange;
|
||||
}
|
||||
return null;
|
||||
@@ -629,7 +628,7 @@ public class DocumentWindowImpl extends UserDataHolderBase implements Disposable
|
||||
for (PsiLanguageInjectionHost.Shred shred : myShreds) {
|
||||
RangeMarker hostRange = shred.getHostRangeMarker();
|
||||
if (!hostRange.isValid()) continue;
|
||||
TextRange textRange = InjectedLanguageUtil.toTextRange(hostRange);
|
||||
TextRange textRange = ProperTextRange.create(hostRange);
|
||||
if (textRange.contains(new ProperTextRange(start, end))) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -665,7 +664,7 @@ public class DocumentWindowImpl extends UserDataHolderBase implements Disposable
|
||||
while (i < myShreds.size() && j < documentWindow.myShreds.size()) {
|
||||
RangeMarker range = myShreds.get(i).getHostRangeMarker();
|
||||
RangeMarker otherRange = documentWindow.myShreds.get(j).getHostRangeMarker();
|
||||
if (InjectedLanguageUtil.toTextRange(range).intersects(InjectedLanguageUtil.toTextRange(otherRange))) return true;
|
||||
if (ProperTextRange.create(range).intersects(ProperTextRange.create(otherRange))) return true;
|
||||
if (range.getEndOffset() > otherRange.getStartOffset()) i++;
|
||||
else if (range.getStartOffset() < otherRange.getEndOffset()) j++;
|
||||
else {
|
||||
|
||||
+2
-2
@@ -430,7 +430,7 @@ public class PostprocessReformattingAspect implements PomModelAspect, Disposable
|
||||
if (!freeFormatingActions.isEmpty()) {
|
||||
FormatTextRanges ranges = new FormatTextRanges();
|
||||
for (PostprocessFormattingTask action : freeFormatingActions) {
|
||||
TextRange range = new TextRange(action.getStartOffset(), action.getEndOffset());
|
||||
TextRange range = TextRange.create(action);
|
||||
ranges.add(range, action instanceof ReformatWithHeadingWhitespaceTask);
|
||||
}
|
||||
result.add(new ReformatRangesAction(ranges));
|
||||
@@ -572,7 +572,7 @@ public class PostprocessReformattingAspect implements PomModelAspect, Disposable
|
||||
return codeFormatter;
|
||||
}
|
||||
|
||||
private abstract static class PostprocessFormattingTask implements Comparable<PostprocessFormattingTask> {
|
||||
private abstract static class PostprocessFormattingTask implements Comparable<PostprocessFormattingTask>, Segment {
|
||||
private final RangeMarker myRange;
|
||||
|
||||
public PostprocessFormattingTask(RangeMarker rangeMarker) {
|
||||
|
||||
+1
-1
@@ -175,7 +175,7 @@ public class CodeFormatterFacade {
|
||||
for (FormatTextRanges.FormatTextRange range : textRanges) {
|
||||
RangeMarker marker = markers[i];
|
||||
if (marker != null) {
|
||||
range.setTextRange(new TextRange(marker.getStartOffset(), marker.getEndOffset()));
|
||||
range.setTextRange(TextRange.create(marker));
|
||||
marker.dispose();
|
||||
}
|
||||
i++;
|
||||
|
||||
-4
@@ -94,10 +94,6 @@ public class InjectedLanguageUtil {
|
||||
return result.isEmpty() ? null : result;
|
||||
}
|
||||
|
||||
public static TextRange toTextRange(RangeMarker marker) {
|
||||
return new ProperTextRange(marker.getStartOffset(), marker.getEndOffset());
|
||||
}
|
||||
|
||||
public static List<Trinity<IElementType, PsiLanguageInjectionHost, TextRange>> getHighlightTokens(PsiFile file) {
|
||||
return file.getUserData(HIGHLIGHT_TOKENS);
|
||||
}
|
||||
|
||||
+2
-2
@@ -414,11 +414,11 @@ public class MultiHostRegistrarImpl implements MultiHostRegistrar {
|
||||
private static void cacheInjectedRegion(DocumentWindowImpl documentWindow, DocumentEx hostDocument) {
|
||||
List<RangeMarker> injectedRegions = InjectedLanguageUtil.getCachedInjectedRegions(hostDocument);
|
||||
RangeMarker newMarker = documentWindow.getHostRanges()[0];
|
||||
TextRange newRange = InjectedLanguageUtil.toTextRange(newMarker);
|
||||
TextRange newRange = ProperTextRange.create(newMarker);
|
||||
for (int i = 0; i < injectedRegions.size(); i++) {
|
||||
RangeMarker stored = injectedRegions.get(i);
|
||||
if (!stored.isValid()) continue;
|
||||
TextRange storedRange = InjectedLanguageUtil.toTextRange(stored);
|
||||
TextRange storedRange = ProperTextRange.create(stored);
|
||||
if (storedRange.intersects(newRange)) {
|
||||
injectedRegions.set(i, newMarker);
|
||||
break;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class FragmentContent extends DiffContent {
|
||||
Document document = rangeMarker.getDocument();
|
||||
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
|
||||
FileType type = FileTypeManager.getInstance().getFileTypeByFile(file);
|
||||
return new FragmentContent(new DocumentContent(project, document), new TextRange(rangeMarker.getStartOffset(), rangeMarker.getEndOffset()), project, type);
|
||||
return new FragmentContent(new DocumentContent(project, document), TextRange.create(rangeMarker), project, type);
|
||||
}
|
||||
|
||||
private class MyDocumentsSynchonizer extends DocumentsSynchonizer {
|
||||
@@ -149,4 +149,4 @@ public class FragmentContent extends DiffContent {
|
||||
replaceString(original, originalOffset, originalEnd, newText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.editor;
|
||||
|
||||
import com.intellij.openapi.util.Segment;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -31,7 +32,7 @@ import java.util.Comparator;
|
||||
*
|
||||
* @see Document#createRangeMarker(int, int)
|
||||
*/
|
||||
public interface RangeMarker extends UserDataHolder{
|
||||
public interface RangeMarker extends UserDataHolder, Segment {
|
||||
/**
|
||||
* Returns the document to which the marker belongs.
|
||||
*
|
||||
|
||||
@@ -125,7 +125,7 @@ class ByWord implements DiffPolicy{
|
||||
static Word[] buildWords(String text, ComparisonPolicy policy) {
|
||||
ArrayList<Word> words = new ArrayList<Word>();
|
||||
if (text.length() == 0 || !Character.isWhitespace(text.charAt(0)))
|
||||
words.add(policy.createFormatting(text, new TextRange(0, 0)));
|
||||
words.add(policy.createFormatting(text, TextRange.EMPTY_RANGE));
|
||||
int start = 0;
|
||||
boolean withinFormatting = true;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ public class MergeBuilderTest extends TestCase {
|
||||
addLeft(base, version);
|
||||
addRight(base, version);
|
||||
CHECK.singleElement(finish(2, 1, 2),
|
||||
fragment(new TextRange(0, 1), new TextRange(0, 0), new TextRange(0, 1)));
|
||||
fragment(new TextRange(0, 1), TextRange.EMPTY_RANGE, new TextRange(0, 1)));
|
||||
}
|
||||
|
||||
public void testSameInsertsConflicts2() {
|
||||
@@ -61,7 +61,7 @@ public class MergeBuilderTest extends TestCase {
|
||||
addRight(range, new TextRange(1, 2));
|
||||
addLeft(range, range);
|
||||
CHECK.singleElement(finish(1, 1, 2),
|
||||
fragment(null, new TextRange(0, 0), new TextRange(0, 1)));
|
||||
fragment(null, TextRange.EMPTY_RANGE, new TextRange(0, 1)));
|
||||
}
|
||||
|
||||
public void testOneSideChange() {
|
||||
@@ -87,7 +87,7 @@ public class MergeBuilderTest extends TestCase {
|
||||
addRight(new TextRange(6, 7), new TextRange(5, 6));
|
||||
addLeft(new TextRange(9, 10), new TextRange(9, 10));
|
||||
CHECK.compareAll(new MergeBuilder.MergeFragment[]{
|
||||
fragment(new TextRange(0, 1), new TextRange(0, 1), new TextRange(0, 0)),
|
||||
fragment(new TextRange(0, 1), new TextRange(0, 1), TextRange.EMPTY_RANGE),
|
||||
fragment(null, new TextRange(2, 3), new TextRange(1, 1)),
|
||||
fragment(null, new TextRange(4, 4), new TextRange(2, 3)),
|
||||
fragment(null, new TextRange(5, 6), new TextRange(4, 5)),
|
||||
|
||||
@@ -74,4 +74,9 @@ public class ProperTextRange extends TextRange {
|
||||
TextRange range = super.union(textRange);
|
||||
return new ProperTextRange(range);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ProperTextRange create(@NotNull Segment segment) {
|
||||
return new ProperTextRange(segment.getStartOffset(), segment.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TextRange implements Segment{
|
||||
public static final TextRange EMPTY_RANGE = new TextRange(0,0);
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
|
||||
@@ -101,6 +102,10 @@ public class TextRange implements Segment{
|
||||
public static TextRange create(int startOffset, int endOffset) {
|
||||
return new TextRange(startOffset, endOffset);
|
||||
}
|
||||
@NotNull
|
||||
public static TextRange create(@NotNull Segment segment) {
|
||||
return create(segment.getStartOffset(), segment.getEndOffset());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String replace(@NotNull String original, @NotNull String replacement) {
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ public class GroovyUnusedImportPass extends TextEditorHighlightingPass {
|
||||
final int end = imports[imports.length - 1].getTextRange().getEndOffset();
|
||||
ignoreRange = new TextRange(start, end);
|
||||
} else {
|
||||
ignoreRange = new TextRange(0, 0);
|
||||
ignoreRange = TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
boolean hasErrorsExceptUnresolvedImports = !DaemonCodeAnalyzerImpl.processHighlights(myDocument, myProject, HighlightSeverity.ERROR, 0, myDocument.getTextLength(), new Processor<HighlightInfo>() {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class GrAnnotationNameValuePairImpl extends GroovyPsiElementImpl implemen
|
||||
if (nameId != null) {
|
||||
return nameId.getTextRange().shiftRight(-getTextRange().getStartOffset());
|
||||
}
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class GroovyMethodInliner implements InlineHandler.Inliner {
|
||||
Editor editor = manager.getSelectedTextEditor();
|
||||
|
||||
//GroovyRefactoringUtil.highlightOccurrences(myProject, editor, new PsiElement[]{pointer.getElement()});
|
||||
TextRange range = new TextRange(marker.getStartOffset(), marker.getEndOffset());
|
||||
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"));
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class BaseSplitter implements Splitter {
|
||||
if (groupToInclude > 0) {
|
||||
TextRange contentFound = matcherRange(range, matcher, groupToInclude);
|
||||
if (tooSmall(contentFound.getEndOffset(), contentFound.getStartOffset())) {
|
||||
toCheck.add(new TextRange(contentFound.getStartOffset(), contentFound.getEndOffset()));
|
||||
toCheck.add(TextRange.create(contentFound));
|
||||
}
|
||||
}
|
||||
from = found.getEndOffset();
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class ReferenceInForm implements PsiReference {
|
||||
}
|
||||
|
||||
public TextRange getRangeInElement() {
|
||||
return new TextRange(myRangeMarker.getStartOffset(), myRangeMarker.getEndOffset());
|
||||
return TextRange.create(myRangeMarker);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class XmlAttributeValueManipulator extends AbstractElementManipulator<Xml
|
||||
public TextRange getRangeInElement(final XmlAttributeValue xmlAttributeValue) {
|
||||
final PsiElement child = xmlAttributeValue.getFirstChild();
|
||||
if (child == null) {
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
final ASTNode node = child.getNode();
|
||||
assert node != null;
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ public class XmlTagManipulator extends AbstractElementManipulator<XmlTag> {
|
||||
public TextRange getRangeInElement(final XmlTag tag) {
|
||||
if (tag.getSubTags().length > 0) {
|
||||
// Text range in tag with subtags is not supported, return empty range, consider making this function nullable.
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
final XmlTagValue value = tag.getValue();
|
||||
@@ -56,7 +56,7 @@ public class XmlTagManipulator extends AbstractElementManipulator<XmlTag> {
|
||||
case 1:
|
||||
return getValueRange(texts[0]);
|
||||
default:
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -668,7 +668,7 @@ public class SchemaReferencesProvider extends PsiReferenceProvider {
|
||||
int offset = (element instanceof XmlAttributeValue) ?
|
||||
XmlUtil.findPrefixByQualifiedName(((XmlAttributeValue)element).getValue()).length() : 0;
|
||||
if (offset > 0) offset++;
|
||||
final TypeOrElementOrAttributeReference ref = new TypeOrElementOrAttributeReference(element, length >= 2 ? new TextRange(1 + offset, length - 1) : new TextRange(0,0));
|
||||
final TypeOrElementOrAttributeReference ref = new TypeOrElementOrAttributeReference(element, length >= 2 ? new TextRange(1 + offset, length - 1) : TextRange.EMPTY_RANGE);
|
||||
ref.setNamespacePrefix(ns);
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class TagNameReference implements PsiReference {
|
||||
public TextRange getRangeInElement() {
|
||||
final ASTNode nameElement = getNameElement();
|
||||
if (nameElement == null){
|
||||
return new TextRange(0, 0);
|
||||
return TextRange.EMPTY_RANGE;
|
||||
}
|
||||
|
||||
int colon = nameElement.getText().indexOf(':') + 1;
|
||||
|
||||
Reference in New Issue
Block a user