From 685d5cde650f5f5d4cc0a5a9c76a196dccf14c7b Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 19 Aug 2010 15:38:26 +0400 Subject: [PATCH] cleanup --- .../codeInsight/template/actions/SaveAsTemplateAction.java | 2 +- .../com/intellij/execution/console/LanguageConsoleImpl.java | 2 +- .../src/com/intellij/refactoring/ui/NameSuggestionsField.java | 2 +- .../platform-api/src/com/intellij/openapi/editor/Document.java | 2 +- .../src/com/intellij/openapi/diff/actions/MergeOperations.java | 2 +- .../openapi/editor/textarea/TextComponentDocument.java | 3 ++- .../actions/handlers/XAddToWatchesFromEditorActionHandler.java | 2 +- .../com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java | 2 +- .../src/com/intellij/codeInspection/i18n/I18nizeAction.java | 2 +- .../com/intellij/spellchecker/inspections/BaseSplitter.java | 2 +- .../src/com/intellij/spellchecker/inspections/CheckArea.java | 2 +- .../intellij/spellchecker/inspections/PlainTextSplitter.java | 2 +- .../intellij/spellchecker/inspections/PropertiesSplitter.java | 2 +- .../com/intellij/spellchecker/inspections/TextSplitter.java | 2 +- .../com/intellij/spellchecker/inspections/WordSplitter.java | 2 +- 15 files changed, 16 insertions(+), 15 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java b/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java index ed9c81274c3b..499859b16ea3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java @@ -94,7 +94,7 @@ public class SaveAsTemplateAction extends AnAction { String canonicalText = reference.getCanonicalText(); TextRange referenceRange = reference.getRangeInElement(); TextRange range = element.getTextRange().cutOut(referenceRange).shiftRight(-offsetDelta); - final String oldText = range.substring(document.getText()); + final String oldText = document.getText(range); if (!canonicalText.equals(oldText)) { rangeToText.put(document.createRangeMarker(range), canonicalText); } diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index db2ab7263ce0..27194385b003 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -354,7 +354,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { HighlighterTargetArea.EXACT_RANGE); final int offset = history.getTextLength(); - final String text = textRange.substring(consoleEditor.getDocument().getText()); + final String text = consoleEditor.getDocument().getText(textRange); history.insertString(offset, text); final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(0); while (!iterator.atEnd()) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/ui/NameSuggestionsField.java b/platform/lang-impl/src/com/intellij/refactoring/ui/NameSuggestionsField.java index 3e2d33fb7309..22994aeced58 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/ui/NameSuggestionsField.java +++ b/platform/lang-impl/src/com/intellij/refactoring/ui/NameSuggestionsField.java @@ -93,7 +93,7 @@ public class NameSuggestionsField extends JPanel { Editor myEditor = getEditor(); if (myEditor == null) return; for (TextRange wordRange : ranges) { - String word = wordRange.substring(editor.getDocument().getText()); + String word = editor.getDocument().getText(wordRange); if (!word.equals(getEnteredName())) continue; final SelectionModel selectionModel = editor.getSelectionModel(); myEditor.getSelectionModel().removeSelection(); diff --git a/platform/platform-api/src/com/intellij/openapi/editor/Document.java b/platform/platform-api/src/com/intellij/openapi/editor/Document.java index f91381b63789..40d816a61151 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/Document.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/Document.java @@ -49,7 +49,7 @@ public interface Document extends UserDataHolder { */ String getText(); - String getText(TextRange range); + @NotNull String getText(@NotNull TextRange range); /** * Use this method instead of {@link #getText()} if you do not need to create a copy of the content. diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java index bf5b3f869d24..686c6dcc258b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java @@ -143,7 +143,7 @@ public class MergeOperations { } private static String getSubstring(Document document, TextRange range) { - return range.substring(document.getText()); + return document.getText(range); } private Document getOtherDocument() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentDocument.java b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentDocument.java index 5dd8a221ba08..e00328aa34c9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentDocument.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentDocument.java @@ -50,8 +50,9 @@ public class TextComponentDocument extends UserDataHolderBase implements Documen } } + @NotNull @Override - public String getText(TextRange range) { + public String getText(@NotNull TextRange range) { try { final javax.swing.text.Document document = myTextComponent.getDocument(); return document.getText(range.getStartOffset(), range.getLength()); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java index f154bae4e615..30cc57f2d08d 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java @@ -54,7 +54,7 @@ public class XAddToWatchesFromEditorActionHandler extends XDebuggerActionHandler final Document document = editor.getDocument(); final TextRange textRange = evaluator.getExpressionRangeAtOffset(session.getProject(), document, offset); if (textRange != null) { - text = textRange.substring(document.getText()); + text = document.getText(textRange); } } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java index 8797bde9ef4c..22a4c8d94756 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java @@ -62,7 +62,7 @@ public class XValueHint extends AbstractValueHint { myEvaluator = evaluator; myDebugSession = session; final Document document = editor.getDocument(); - myExpression = textRange.substring(document.getText()); + myExpression = document.getText(textRange); final VirtualFile file = FileDocumentManager.getInstance().getFile(document); myExpressionPosition = file != null ? XDebuggerUtil.getInstance().createPositionByOffset(file, textRange.getStartOffset()) : null; } diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeAction.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeAction.java index b25c14e7b732..b3d672d21d56 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeAction.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeAction.java @@ -197,7 +197,7 @@ public class I18nizeAction extends AnAction implements I18nQuickFixHandler{ TextRange selectedRange = getSelectedRange(editor, psiFile); if (selectedRange == null) return null; - String text = selectedRange.substring(editor.getDocument().getText()); + String text = editor.getDocument().getText(selectedRange); return new JavaI18nizeQuickFixDialog(project, jspFile, null, text, null, false, true){ protected String getTemplateName() { return JavaTemplateUtil.TEMPLATE_I18NIZED_JSP_EXPRESSION; diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java index 795fe9f62648..7737cb1a96af 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/BaseSplitter.java @@ -100,7 +100,7 @@ public abstract class BaseSplitter implements Splitter { int from = range.getStartOffset(); int till; boolean addLast = true; - Matcher matcher = toExclude.matcher(text.substring(range.getStartOffset(), range.getEndOffset())); + Matcher matcher = toExclude.matcher(range.substring(text)); while (matcher.find()) { checkCancelled(); diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/CheckArea.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/CheckArea.java index 1be5847a351a..a8d1a35072f0 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/CheckArea.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/CheckArea.java @@ -48,7 +48,7 @@ public class CheckArea { @Nullable public String getWord() { if (text == null || textRange == null) return null; - return text.substring(textRange.getStartOffset(), textRange.getEndOffset()); + return textRange.substring(text); } @Override diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java index ba04494aea4b..9435f63f05cb 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java @@ -38,7 +38,7 @@ public class PlainTextSplitter extends BaseSplitter { if (text == null || StringUtil.isEmpty(text)) { return null; } - if (Verifier.checkCharacterData(text.substring(range.getStartOffset(), range.getEndOffset())) != null) { + if (Verifier.checkCharacterData(range.substring(text)) != null) { return null; } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java index 1311891ce5dd..2a3dceb46645 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java @@ -40,7 +40,7 @@ public class PropertiesSplitter extends BaseSplitter { } List results = new ArrayList(); final IdentifierSplitter splitter = SplitterFactory.getInstance().getIdentifierSplitter(); - Matcher matcher = WORD.matcher(text.substring(range.getStartOffset(), range.getEndOffset())); + Matcher matcher = WORD.matcher(range.substring(text)); while (matcher.find()) { if (matcher.end() - matcher.start() < MIN_RANGE_LENGTH) { continue; diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java index e68defbe000a..8c9ec865a3cd 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java @@ -41,7 +41,7 @@ public class TextSplitter extends BaseSplitter { protected void doSplit(@NotNull String text, @NotNull TextRange range, List results) { Matcher matcher; final WordSplitter ws = SplitterFactory.getInstance().getWordSplitter(); - matcher = EXTENDED_WORD_AND_SPECIAL.matcher(text.substring(range.getStartOffset(), range.getEndOffset())); + matcher = EXTENDED_WORD_AND_SPECIAL.matcher(range.substring(text)); while (matcher.find()) { TextRange found = matcherRange(range, matcher); diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java index aa3192f2f75e..057c29da6adb 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java @@ -39,7 +39,7 @@ public class WordSplitter extends BaseSplitter { } List results = new ArrayList(); - Matcher specialMatcher = SPECIAL.matcher(text.substring(range.getStartOffset(), range.getEndOffset())); + Matcher specialMatcher = SPECIAL.matcher(range.substring(text)); if (specialMatcher.find()) { TextRange found = matcherRange(range, specialMatcher); addWord(text, results, true, found);