Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/Strings.java

Issue 9834028: Initial implementation of "Rename Local Variable" refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: LInked/inline mode for rename Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/Strings.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/Strings.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/Strings.java
similarity index 76%
copy from editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/Strings.java
copy to editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/Strings.java
index 7d8b390fea9bb9ee8e058d5fa50c7a3ccac9803f..452dd3951d873e9dff4ed522de329a013dfe4efc 100644
--- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/Strings.java
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/Strings.java
@@ -1,22 +1,8 @@
-/*
- * Copyright (c) 2011, the Dart project authors.
- *
- * Licensed under the Eclipse Public License v1.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.dart.tools.ui.internal.util;
+package com.google.dart.tools.internal.corext.refactoring.util;
import com.google.dart.tools.core.formatter.IndentManipulation;
import com.google.dart.tools.core.model.DartProject;
+import com.google.dart.tools.ui.internal.util.CodeFormatterUtil;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.action.LegacyActionTools;
@@ -24,24 +10,23 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultLineTracker;
import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.osgi.util.TextProcessor;
/**
* Helper class to provide String manipulation functions not available in standard JDK.
*/
public class Strings {
-
- private static final String JAVA_ELEMENT_DELIMITERS = TextProcessor.getDefaultDelimiters()
- + "<>(),?{} "; //$NON-NLS-1$
-
/**
- * Change the indent of, possible muti-line, code range. The current indent is removed, a new
+ * Change the indent of, possible multi-line, code range. The current indent is removed, a new
* indent added. The first line of the code will not be changed. (It is considered to have no
* indent as it might start in the middle of a line)
*
- * @param project the java project from which to get the formatter preferences, or
+ * @param code the code
+ * @param codeIndentLevel level of indentation
+ * @param project the Dart project from which to get the formatter preferences, or
* <code>null</code> for global preferences
+ * @param newIndent new indent
+ * @param lineDelim line delimiter
+ * @return the changed code
*/
public static String changeIndent(String code, int codeIndentLevel, DartProject project,
String newIndent, String lineDelim) {
@@ -54,6 +39,14 @@ public class Strings {
* Change the indent of, possible muti-line, code range. The current indent is removed, a new
* indent added. The first line of the code will not be changed. (It is considered to have no
* indent as it might start in the middle of a line)
+ *
+ * @param code the code
+ * @param codeIndentLevel indent level
+ * @param tabWidth the size of one tab in space equivalents
+ * @param indentWidth the size of the indent in space equivalents
+ * @param newIndent new indent
+ * @param lineDelim line delimiter
+ * @return the changed code
*/
public static String changeIndent(String code, int codeIndentLevel, int tabWidth,
int indentWidth, String newIndent, String lineDelim) {
@@ -65,8 +58,9 @@ public class Strings {
* Returns the indent of the given string in indentation units. Odd spaces are not counted.
*
* @param line the text line
- * @param project the java project from which to get the formatter preferences, or
+ * @param project the Dart project from which to get the formatter preferences, or
* <code>null</code> for global preferences
+ * @return the number of indent units
*/
public static int computeIndentUnits(String line, DartProject project) {
return IndentManipulation.measureIndentUnits(line, CodeFormatterUtil.getTabWidth(project),
@@ -79,6 +73,7 @@ public class Strings {
* @param line the text line
* @param tabWidth the width of the '\t' character in space equivalents
* @param indentWidth the width of one indentation unit in space equivalents
+ * @return the indent of the given string in indentation units
*/
public static int computeIndentUnits(String line, int tabWidth, int indentWidth) {
return IndentManipulation.measureIndentUnits(line, tabWidth, indentWidth);
@@ -87,6 +82,10 @@ public class Strings {
/**
* Concatenate the given strings into one strings using the passed line delimiter as a delimiter.
* No delimiter is added to the last line.
+ *
+ * @param lines the lines
+ * @param delimiter line delimiter
+ * @return the concatenated lines
*/
public static String concatenate(String[] lines, String delimiter) {
StringBuffer buffer = new StringBuffer();
@@ -100,13 +99,14 @@ public class Strings {
}
/**
- * Returns <code>true</code> if the given string only consists of white spaces according to Java.
+ * Returns <code>true</code> if the given string only consists of white spaces according to Dart.
* If the string is empty, <code>true
* </code> is returned.
*
+ * @param s the string to test
* @return <code>true</code> if the string only consists of white spaces; otherwise
* <code>false</code> is returned
- * @see java.lang.Character#isWhitespace(char)
+ * @see Dart.lang.Character#isWhitespace(char)
*/
public static boolean containsOnlyWhitespaces(String s) {
int size = s.length();
@@ -122,6 +122,7 @@ public class Strings {
* Converts the given string into an array of lines. The lines don't contain any line delimiter
* characters.
*
+ * @param input the string
* @return the string converted into an array of strings. Returns <code>
* null</code> if the input string can't be converted in an array of lines.
*/
@@ -160,7 +161,7 @@ public class Strings {
* indentation units.
*
* @param line the line to scan
- * @param project the java project from which to get the formatter preferences, or
+ * @param project the Dart project from which to get the formatter preferences, or
* <code>null</code> for global preferences
* @return the indent part of <code>line</code>, but no odd spaces
*/
@@ -183,80 +184,16 @@ public class Strings {
}
/**
- * tests if a char is lower case. Fix for 26529
+ * Tests if a char is lower case. Fix for 26529.
+ *
+ * @param ch the char
+ * @return return true if char is lower case
*/
public static boolean isLowerCase(char ch) {
return Character.toLowerCase(ch) == ch;
}
/**
- * Adds special marks so that that the given Java element label is readable in a BiDi environment.
- *
- * @param string the string
- * @return the processed styled string
- */
- public static String markJavaElementLabelLTR(String string) {
- return TextProcessor.process(string, JAVA_ELEMENT_DELIMITERS);
- }
-
- /**
- * Adds special marks so that that the given styled Java element label is readable in a BiDi
- * environment.
- *
- * @param styledString the styled string
- * @return the processed styled string
- */
- public static StyledString markJavaElementLabelLTR(StyledString styledString) {
- String inputString = styledString.getString();
- String string = TextProcessor.process(inputString, JAVA_ELEMENT_DELIMITERS);
- if (string != inputString) {
- insertMarks(styledString, inputString, string);
- }
- return styledString;
- }
-
- /**
- * Adds special marks so that that the given string is readable in a BiDi environment.
- *
- * @param string the string
- * @return the processed styled string
- */
- public static String markLTR(String string) {
- return TextProcessor.process(string);
- }
-
- /**
- * Adds special marks so that that the given string is readable in a BIDI environment.
- *
- * @param string the string
- * @param delimiters the additional delimiters
- * @return the processed styled string
- */
- public static String markLTR(String string, String delimiters) {
- return TextProcessor.process(string, delimiters);
- }
-
- /**
- * Adds special marks so that that the given styled string is readable in a BiDi environment.
- *
- * @param styledString the styled string
- * @return the processed styled string
- */
- public static StyledString markLTR(StyledString styledString) {
-
- /*
- * NOTE: For performance reasons we do not call markLTR(styledString, null)
- */
-
- String inputString = styledString.getString();
- String string = TextProcessor.process(inputString);
- if (string != inputString) {
- insertMarks(styledString, inputString, string);
- }
- return styledString;
- }
-
- /**
* Computes the visual length of the indentation of a <code>CharSequence</code>, counting a tab
* character as the size until the next tab stop and every other whitespace character as one.
*
@@ -335,8 +272,11 @@ public class Strings {
* Removes the given number of indents from the line. Asserts that the given line has the
* requested number of indents. If <code>indentsToRemove <= 0</code> the line is returned.
*
- * @param project the java project from which to get the formatter preferences, or
+ * @param line the line
+ * @param indentsToRemove the indents to remove
+ * @param project the Dart project from which to get the formatter preferences, or
* <code>null</code> for global preferences
+ * @return the trimmed line
*/
public static String trimIndent(String line, int indentsToRemove, DartProject project) {
return IndentManipulation.trimIndent(line, indentsToRemove,
@@ -346,6 +286,12 @@ public class Strings {
/**
* Removes the given number of indents from the line. Asserts that the given line has the
* requested number of indents. If <code>indentsToRemove <= 0</code> the line is returned.
+ *
+ * @param line the line
+ * @param indentsToRemove the indents to remove
+ * @param tabWidth the tab width
+ * @param indentWidth the indent width
+ * @return the trimmed line
*/
public static String trimIndent(String line, int indentsToRemove, int tabWidth, int indentWidth) {
return IndentManipulation.trimIndent(line, indentsToRemove, tabWidth, indentWidth);
@@ -391,7 +337,8 @@ public class Strings {
* Removes the common number of indents from all lines. If a line only consists out of white space
* it is ignored.
*
- * @param project the java project from which to get the formatter preferences, or
+ * @param lines the lines
+ * @param project the Dart project from which to get the formatter preferences, or
* <code>null</code> for global preferences
*/
public static void trimIndentation(String[] lines, DartProject project) {
@@ -404,8 +351,11 @@ public class Strings {
* it is ignored. If <code>
* considerFirstLine</code> is false the first line will be ignored.
*
- * @param project the java project from which to get the formatter preferences, or
+ * @param lines the lines
+ * @param project the Dart project from which to get the formatter preferences, or
* <code>null</code> for global preferences
+ * @param considerFirstLine If <code>considerFirstLine</code> is false the first line will be
+ * ignored.
*/
public static void trimIndentation(String[] lines, DartProject project, boolean considerFirstLine) {
trimIndentation(lines, CodeFormatterUtil.getTabWidth(project),
@@ -415,6 +365,10 @@ public class Strings {
/**
* Removes the common number of indents from all lines. If a line only consists out of white space
* it is ignored.
+ *
+ * @param lines the lines
+ * @param tabWidth the size of one tab in space equivalents
+ * @param indentWidth the size of the indent in space equivalents
*/
public static void trimIndentation(String[] lines, int tabWidth, int indentWidth) {
trimIndentation(lines, tabWidth, indentWidth, true);
@@ -424,6 +378,12 @@ public class Strings {
* Removes the common number of indents from all lines. If a line only consists out of white space
* it is ignored. If <code>
* considerFirstLine</code> is false the first line will be ignored.
+ *
+ * @param lines the lines
+ * @param tabWidth the size of one tab in space equivalents
+ * @param indentWidth the size of the indent in space equivalents
+ * @param considerFirstLine If <code> considerFirstLine</code> is false the first line will be
+ * ignored.
*/
public static void trimIndentation(String[] lines, int tabWidth, int indentWidth,
boolean considerFirstLine) {
@@ -464,6 +424,9 @@ public class Strings {
/**
* Removes leading tabs and spaces from the given string. If the string doesn't contain any
* leading tabs or spaces then the string itself is returned.
+ *
+ * @param line the line
+ * @return the trimmed line
*/
public static String trimLeadingTabsAndSpaces(String line) {
int size = line.length();
@@ -513,34 +476,6 @@ public class Strings {
return -1;
}
- /**
- * Inserts the marks into the given styled string.
- *
- * @param styledString the styled string
- * @param originalString the original string
- * @param processedString the processed string
- */
- private static void insertMarks(StyledString styledString, String originalString,
- String processedString) {
- int originalLength = originalString.length();
- int processedStringLength = processedString.length();
- char orig = originalLength > 0 ? originalString.charAt(0) : '\0';
- for (int o = 0, p = 0; p < processedStringLength; p++) {
- char processed = processedString.charAt(p);
- if (o < originalLength) {
- if (orig == processed) {
- o++;
- if (o < originalLength) {
- orig = originalString.charAt(o);
- }
- continue;
- }
- }
- styledString.insert(processed, p);
- }
- }
-
private Strings() {
}
-
}

Powered by Google App Engine
This is Rietveld 408576698