diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index 0ba8dbf392ce..dc31998d72e3 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -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 { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java index f4a06332f0f1..961244c467c6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java @@ -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() { public boolean process(HighlightInfo error) { int infoStart = error.getActualStartOffset(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index 578f65ec9f4b..a68745e64ce9 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -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)); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java index 69005f861060..ddc62701ed18 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java @@ -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); diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java index 88375c734710..c4cfeebd080d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java @@ -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) { diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java index 1a26a4dcdb9f..975ac746d471 100644 --- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java @@ -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); } } diff --git a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java index e8c591ec5fa0..b52e4980e196 100644 --- a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java @@ -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() { diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java index 3597fea5840c..ca6890759a9b 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java @@ -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() { diff --git a/platform/lang-api/src/com/intellij/lang/annotation/Annotation.java b/platform/lang-api/src/com/intellij/lang/annotation/Annotation.java index 7251e2be3801..412cffe99586 100644 --- a/platform/lang-api/src/com/intellij/lang/annotation/Annotation.java +++ b/platform/lang-api/src/com/intellij/lang/annotation/Annotation.java @@ -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 options, String displayName) { - this.key = null; + key = null; this.quickFix = quickFix; this.textRange = textRange; this.displayName = quickFix.getText(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java index c67285dcf5bb..ac290d399d3b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java @@ -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; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index e2832f852c80..b055d66e2a85 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -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; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index 76a6ce8f008b..c33e18838e3d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -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; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java index b13022438f17..11aa9543d307 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java @@ -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){ diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java index ed59492c5fee..9476402c0c0a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java @@ -131,7 +131,7 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor otherRange.getStartOffset()) i++; else if (range.getStartOffset() < otherRange.getEndOffset()) j++; else { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java index 433e464474f9..abaf335880ff 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java @@ -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 { + private abstract static class PostprocessFormattingTask implements Comparable, Segment { private final RangeMarker myRange; public PostprocessFormattingTask(RangeMarker rangeMarker) { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java index 41eba331b17b..a6d8152bc3ff 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java @@ -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++; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java index cbb3f482acce..5ac481ad5638 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java @@ -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> getHighlightTokens(PsiFile file) { return file.getUserData(HIGHLIGHT_TOKENS); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java index 1af0f5b82ca5..e808c63d460b 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/MultiHostRegistrarImpl.java @@ -414,11 +414,11 @@ public class MultiHostRegistrarImpl implements MultiHostRegistrar { private static void cacheInjectedRegion(DocumentWindowImpl documentWindow, DocumentEx hostDocument) { List 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; diff --git a/platform/platform-api/src/com/intellij/openapi/diff/FragmentContent.java b/platform/platform-api/src/com/intellij/openapi/diff/FragmentContent.java index cf226fb53a5d..4ffe3988aada 100644 --- a/platform/platform-api/src/com/intellij/openapi/diff/FragmentContent.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/FragmentContent.java @@ -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); } } -} \ No newline at end of file +} diff --git a/platform/platform-api/src/com/intellij/openapi/editor/RangeMarker.java b/platform/platform-api/src/com/intellij/openapi/editor/RangeMarker.java index e38b5a27b1ff..7fc06fd80f63 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/RangeMarker.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/RangeMarker.java @@ -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. * diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/ByWord.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/ByWord.java index 890788a32ebd..4cff8397fec6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/ByWord.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/ByWord.java @@ -125,7 +125,7 @@ class ByWord implements DiffPolicy{ static Word[] buildWords(String text, ComparisonPolicy policy) { ArrayList words = new ArrayList(); 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++) { diff --git a/platform/platform-impl/testSrc/com/intellij/openapi/diff/impl/incrementalMerge/MergeBuilderTest.java b/platform/platform-impl/testSrc/com/intellij/openapi/diff/impl/incrementalMerge/MergeBuilderTest.java index b97fa997b761..05d325a7d855 100644 --- a/platform/platform-impl/testSrc/com/intellij/openapi/diff/impl/incrementalMerge/MergeBuilderTest.java +++ b/platform/platform-impl/testSrc/com/intellij/openapi/diff/impl/incrementalMerge/MergeBuilderTest.java @@ -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)), diff --git a/platform/util/src/com/intellij/openapi/util/ProperTextRange.java b/platform/util/src/com/intellij/openapi/util/ProperTextRange.java index ff46e66666e3..542a6135325f 100644 --- a/platform/util/src/com/intellij/openapi/util/ProperTextRange.java +++ b/platform/util/src/com/intellij/openapi/util/ProperTextRange.java @@ -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()); + } } diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java index a38fa5788b25..27d1d834d00d 100644 --- a/platform/util/src/com/intellij/openapi/util/TextRange.java +++ b/platform/util/src/com/intellij/openapi/util/TextRange.java @@ -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) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyUnusedImportPass.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyUnusedImportPass.java index b71f419f463b..228d6610a4d7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyUnusedImportPass.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyUnusedImportPass.java @@ -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() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java index 946dd01b3110..fd5416da498d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java @@ -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 diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyMethodInliner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyMethodInliner.java index 14f7b91c9bc0..20926bcafdfd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyMethodInliner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyMethodInliner.java @@ -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")); diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java index 7737cb1a96af..4cc13bae796a 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java @@ -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(); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ReferenceInForm.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ReferenceInForm.java index 36baa07f2695..23dad6fc1f6a 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ReferenceInForm.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ReferenceInForm.java @@ -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 diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/XmlAttributeValueManipulator.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/XmlAttributeValueManipulator.java index 1265ed40664f..f646e4e84398 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/XmlAttributeValueManipulator.java +++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/XmlAttributeValueManipulator.java @@ -69,7 +69,7 @@ public class XmlAttributeValueManipulator extends AbstractElementManipulator { 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 { case 1: return getValueRange(texts[0]); default: - return new TextRange(0, 0); + return TextRange.EMPTY_RANGE; } } diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java index ecaabdc7064c..6ba8c7a1f586 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java +++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java @@ -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; } diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java b/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java index 2529949ba40e..576b3db32181 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java @@ -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;