mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:20:36 +00:00
Stop using the remaining methods of StringUtilities.
Change-Id: I099c4f79f2cd5dede474412e72d6d53ef555deff Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/223300 Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
5f32f4d7b6
commit
95644dcde5
|
@ -15,7 +15,6 @@ import 'package:analyzer/src/dart/analysis/driver.dart';
|
|||
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
|
||||
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
|
||||
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/lint/linter.dart';
|
||||
|
@ -279,7 +278,7 @@ class ContextManagerImpl implements ContextManager {
|
|||
var convertedErrors = const <protocol.AnalysisError>[];
|
||||
try {
|
||||
var content = _readFile(path);
|
||||
var lineInfo = _computeLineInfo(content);
|
||||
var lineInfo = LineInfo.fromContent(content);
|
||||
var errors = analyzeAnalysisOptions(
|
||||
resourceProvider.getFile(path).createSource(),
|
||||
content,
|
||||
|
@ -304,7 +303,7 @@ class ContextManagerImpl implements ContextManager {
|
|||
var content = _readFile(path);
|
||||
var validator =
|
||||
ManifestValidator(resourceProvider.getFile(path).createSource());
|
||||
var lineInfo = _computeLineInfo(content);
|
||||
var lineInfo = LineInfo.fromContent(content);
|
||||
var errors = validator.validate(
|
||||
content, driver.analysisOptions.chromeOsManifestChecks);
|
||||
var converter = AnalyzerConverter();
|
||||
|
@ -331,7 +330,8 @@ class ContextManagerImpl implements ContextManager {
|
|||
parser.parse(content);
|
||||
var converter = AnalyzerConverter();
|
||||
convertedErrors = converter.convertAnalysisErrors(errorListener.errors,
|
||||
lineInfo: _computeLineInfo(content), options: driver.analysisOptions);
|
||||
lineInfo: LineInfo.fromContent(content),
|
||||
options: driver.analysisOptions);
|
||||
} catch (exception) {
|
||||
// If the file cannot be analyzed, fall through to clear any previous
|
||||
// errors.
|
||||
|
@ -349,7 +349,7 @@ class ContextManagerImpl implements ContextManager {
|
|||
if (node is YamlMap) {
|
||||
var validator = PubspecValidator(
|
||||
resourceProvider, resourceProvider.getFile(path).createSource());
|
||||
var lineInfo = _computeLineInfo(content);
|
||||
var lineInfo = LineInfo.fromContent(content);
|
||||
var errors = validator.validate(node.nodes);
|
||||
var converter = AnalyzerConverter();
|
||||
convertedErrors = converter.convertAnalysisErrors(errors,
|
||||
|
@ -412,12 +412,6 @@ class ContextManagerImpl implements ContextManager {
|
|||
}
|
||||
}
|
||||
|
||||
/// Compute line information for the given [content].
|
||||
LineInfo _computeLineInfo(String content) {
|
||||
var lineStarts = StringUtilities.computeLineStarts(content);
|
||||
return LineInfo(lineStarts);
|
||||
}
|
||||
|
||||
void _createAnalysisContexts() {
|
||||
_destroyAnalysisContexts();
|
||||
_fileContentCache.invalidateAll();
|
||||
|
|
|
@ -12,7 +12,6 @@ import 'package:analyzer/dart/ast/token.dart';
|
|||
import 'package:analyzer/error/listener.dart' as error;
|
||||
import 'package:analyzer/src/dart/scanner/reader.dart';
|
||||
import 'package:analyzer/src/dart/scanner/scanner.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/util/glob.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
|
@ -497,7 +496,7 @@ class FileEdit {
|
|||
throw ArgumentError('Unhandled change of type ${record.status}');
|
||||
} else {
|
||||
content = File(filePath).readAsStringSync();
|
||||
lineInfo = LineInfo(StringUtilities.computeLineStarts(content));
|
||||
lineInfo = LineInfo.fromContent(content);
|
||||
}
|
||||
currentContent = content;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
|
||||
/// The location of a character represented as a line and column pair.
|
||||
class CharacterLocation {
|
||||
/// The one-based index of the line containing the character.
|
||||
|
@ -45,9 +43,32 @@ class LineInfo {
|
|||
}
|
||||
|
||||
/// Initialize a newly created set of line information corresponding to the
|
||||
/// given file [content].
|
||||
factory LineInfo.fromContent(String content) =>
|
||||
LineInfo(StringUtilities.computeLineStarts(content));
|
||||
/// given file [content]. Lines end with `\r`, `\n` or `\r\n`.
|
||||
factory LineInfo.fromContent(String content) {
|
||||
const slashN = 0x0A;
|
||||
const slashR = 0x0D;
|
||||
|
||||
var lineStarts = <int>[0];
|
||||
var length = content.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
var unit = content.codeUnitAt(i);
|
||||
// Special-case \r\n.
|
||||
if (unit == slashR) {
|
||||
// Peek ahead to detect a following \n.
|
||||
if (i + 1 < length && content.codeUnitAt(i + 1) == slashN) {
|
||||
// Line start will get registered at next index at the \n.
|
||||
} else {
|
||||
lineStarts.add(i + 1);
|
||||
}
|
||||
}
|
||||
// \n
|
||||
if (unit == slashN) {
|
||||
lineStarts.add(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return LineInfo(lineStarts);
|
||||
}
|
||||
|
||||
/// The number of lines.
|
||||
int get lineCount => lineStarts.length;
|
||||
|
|
|
@ -390,7 +390,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
|
|||
// TODO (jwren) revisit- should we append '=' here or require clients to
|
||||
// include it?
|
||||
// Do we need the check for isSetter below?
|
||||
if (!StringUtilities.endsWithChar(setterName, 0x3D)) {
|
||||
if (!setterName.endsWith('=')) {
|
||||
setterName += '=';
|
||||
}
|
||||
for (PropertyAccessorElement accessor in accessors) {
|
||||
|
@ -2085,8 +2085,7 @@ abstract class ElementImpl implements Element {
|
|||
|
||||
/// Initialize a newly created element to have the given [name] at the given
|
||||
/// [_nameOffset].
|
||||
ElementImpl(String? name, this._nameOffset, {this.reference}) {
|
||||
_name = name != null ? StringUtilities.intern(name) : null;
|
||||
ElementImpl(this._name, this._nameOffset, {this.reference}) {
|
||||
reference?.element = this;
|
||||
}
|
||||
|
||||
|
@ -4723,8 +4722,8 @@ class ParameterElementImpl extends VariableElementImpl
|
|||
@override
|
||||
final ParameterKind parameterKind;
|
||||
|
||||
/// The Dart code of the default value.
|
||||
String? _defaultValueCode;
|
||||
@override
|
||||
String? defaultValueCode;
|
||||
|
||||
/// True if this parameter inherits from a covariant parameter. This happens
|
||||
/// when it overrides a method in a supertype that has a corresponding
|
||||
|
@ -4755,18 +4754,6 @@ class ParameterElementImpl extends VariableElementImpl
|
|||
@override
|
||||
ParameterElement get declaration => this;
|
||||
|
||||
@override
|
||||
String? get defaultValueCode {
|
||||
return _defaultValueCode;
|
||||
}
|
||||
|
||||
/// Set Dart code of the default value.
|
||||
set defaultValueCode(String? defaultValueCode) {
|
||||
_defaultValueCode = defaultValueCode != null
|
||||
? StringUtilities.intern(defaultValueCode)
|
||||
: null;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get hasDefaultValue {
|
||||
return defaultValueCode != null;
|
||||
|
|
|
@ -42,7 +42,6 @@ import 'package:analyzer/src/error/use_result_verifier.dart';
|
|||
import 'package:analyzer/src/generated/element_resolver.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/error_detection_helpers.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
|
||||
import 'package:analyzer/src/generated/this_access_tracker.dart';
|
||||
import 'package:analyzer/src/utilities/extensions/string.dart';
|
||||
|
@ -4935,11 +4934,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
/// Return the name of the library that defines given [element].
|
||||
String _getLibraryName(Element? element) {
|
||||
if (element == null) {
|
||||
return StringUtilities.EMPTY;
|
||||
return '';
|
||||
}
|
||||
var library = element.library;
|
||||
if (library == null) {
|
||||
return StringUtilities.EMPTY;
|
||||
return '';
|
||||
}
|
||||
List<ImportElement> imports = _currentLibrary.imports;
|
||||
int count = imports.length;
|
||||
|
|
|
@ -10,40 +10,7 @@ export 'package:analyzer/exception/exception.dart';
|
|||
typedef Predicate<E> = bool Function(E argument);
|
||||
|
||||
class StringUtilities {
|
||||
static const String EMPTY = '';
|
||||
static const List<String> EMPTY_ARRAY = <String>[];
|
||||
|
||||
static Interner INTERNER = NullInterner();
|
||||
|
||||
/// Compute line starts for the given [content].
|
||||
/// Lines end with `\r`, `\n` or `\r\n`.
|
||||
static List<int> computeLineStarts(String content) {
|
||||
List<int> lineStarts = <int>[0];
|
||||
int length = content.length;
|
||||
int unit;
|
||||
for (int index = 0; index < length; index++) {
|
||||
unit = content.codeUnitAt(index);
|
||||
// Special-case \r\n.
|
||||
if (unit == 0x0D /* \r */) {
|
||||
// Peek ahead to detect a following \n.
|
||||
if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) {
|
||||
// Line start will get registered at next index at the \n.
|
||||
} else {
|
||||
lineStarts.add(index + 1);
|
||||
}
|
||||
}
|
||||
// \n
|
||||
if (unit == 0x0A) {
|
||||
lineStarts.add(index + 1);
|
||||
}
|
||||
}
|
||||
return lineStarts;
|
||||
}
|
||||
|
||||
static bool endsWithChar(String str, int c) {
|
||||
int length = str.length;
|
||||
return length > 0 && str.codeUnitAt(length - 1) == c;
|
||||
}
|
||||
|
||||
static String intern(String string) => INTERNER.intern(string);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:analyzer/dart/ast/token.dart';
|
|||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/utilities.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
|
||||
import 'package:analyzer/src/generated/utilities_collection.dart';
|
||||
|
@ -23,7 +22,6 @@ main() {
|
|||
defineReflectiveTests(LineInfoTest);
|
||||
defineReflectiveTests(NodeReplacerTest);
|
||||
defineReflectiveTests(SourceRangeTest);
|
||||
defineReflectiveTests(StringUtilitiesTest);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1045,6 +1043,21 @@ class LineInfoTest {
|
|||
}, throwsArgumentError);
|
||||
}
|
||||
|
||||
void test_fromContent_n() {
|
||||
var lineInfo = LineInfo.fromContent('a\nbb\nccc');
|
||||
expect(lineInfo.lineStarts, <int>[0, 2, 5]);
|
||||
}
|
||||
|
||||
void test_fromContent_r() {
|
||||
var lineInfo = LineInfo.fromContent('a\rbb\rccc');
|
||||
expect(lineInfo.lineStarts, <int>[0, 2, 5]);
|
||||
}
|
||||
|
||||
void test_fromContent_rn() {
|
||||
var lineInfo = LineInfo.fromContent('a\r\nbb\r\nccc');
|
||||
expect(lineInfo.lineStarts, <int>[0, 3, 7]);
|
||||
}
|
||||
|
||||
void test_getLocation_firstLine() {
|
||||
LineInfo info = LineInfo(<int>[0, 12, 34]);
|
||||
var location = info.getLocation(4);
|
||||
|
@ -2560,36 +2573,3 @@ class SourceRangeTest {
|
|||
expect(r.toString(), "[offset=10, length=1]");
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class StringUtilitiesTest {
|
||||
void test_computeLineStarts_n() {
|
||||
List<int> starts = StringUtilities.computeLineStarts('a\nbb\nccc');
|
||||
expect(starts, <int>[0, 2, 5]);
|
||||
}
|
||||
|
||||
void test_computeLineStarts_r() {
|
||||
List<int> starts = StringUtilities.computeLineStarts('a\rbb\rccc');
|
||||
expect(starts, <int>[0, 2, 5]);
|
||||
}
|
||||
|
||||
void test_computeLineStarts_rn() {
|
||||
List<int> starts = StringUtilities.computeLineStarts('a\r\nbb\r\nccc');
|
||||
expect(starts, <int>[0, 3, 7]);
|
||||
}
|
||||
|
||||
void test_EMPTY() {
|
||||
expect(StringUtilities.EMPTY, "");
|
||||
expect(StringUtilities.EMPTY.isEmpty, isTrue);
|
||||
}
|
||||
|
||||
void test_EMPTY_ARRAY() {
|
||||
expect(StringUtilities.EMPTY_ARRAY.length, 0);
|
||||
}
|
||||
|
||||
void test_endsWithChar() {
|
||||
expect(StringUtilities.endsWithChar("a", 0x61), isTrue);
|
||||
expect(StringUtilities.endsWithChar("b", 0x61), isFalse);
|
||||
expect(StringUtilities.endsWithChar("", 0x61), isFalse);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
|
|||
import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
import 'package:analyzer/src/dart/analysis/results.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/interner.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/lint/linter.dart';
|
||||
import 'package:analyzer/src/lint/pub.dart';
|
||||
|
@ -95,8 +93,6 @@ class Driver implements CommandLineStarter {
|
|||
_isStarted = true;
|
||||
var startTime = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
StringUtilities.INTERNER = MappedInterner();
|
||||
|
||||
linter.registerLintRules();
|
||||
|
||||
// Parse commandline options.
|
||||
|
|
Loading…
Reference in a new issue