mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:20:31 +00:00
Fix ConvertQuotes and ConvertToMutilineString when unterminated string.
I finally understood how to reproduce it :-) R=brianwilkerson@google.com, pquitslund@google.com Change-Id: Id75fa54057f7db49e8d3f8f3b6f2f25785ed4977 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175822 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
4bee6db9cf
commit
b16c212776
6 changed files with 83 additions and 6 deletions
|
@ -27,8 +27,8 @@ abstract class ConvertQuotes extends CorrectionProducer {
|
|||
? (_fromDouble ? "'''" : '"""')
|
||||
: (_fromDouble ? "'" : '"');
|
||||
var quoteLength = literal.isMultiline ? 3 : 1;
|
||||
var lexeme = literal.literal.lexeme;
|
||||
if (!lexeme.contains(newQuote)) {
|
||||
var token = literal.literal;
|
||||
if (!token.isSynthetic && !token.lexeme.contains(newQuote)) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(
|
||||
SourceRange(
|
||||
|
@ -53,8 +53,8 @@ abstract class ConvertQuotes extends CorrectionProducer {
|
|||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
if (element is InterpolationString) {
|
||||
var lexeme = element.contents.lexeme;
|
||||
if (lexeme.contains(newQuote)) {
|
||||
var token = element.contents;
|
||||
if (token.isSynthetic || token.lexeme.contains(newQuote)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class ConvertToMutilineString extends CorrectionProducer {
|
|||
}
|
||||
if (node is SingleStringLiteral) {
|
||||
var literal = node;
|
||||
if (!literal.isMultiline) {
|
||||
if (!literal.isSynthetic && !literal.isMultiline) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
var newQuote = literal.isSingleQuoted ? "'''" : '"""';
|
||||
builder.addReplacement(
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
|
|||
import 'package:analysis_server/src/services/correction/assist.dart';
|
||||
import 'package:analysis_server/src/services/correction/assist_internal.dart';
|
||||
import 'package:analysis_server/src/services/correction/change_workspace.dart';
|
||||
import 'package:analyzer/exception/exception.dart';
|
||||
import 'package:analyzer/instrumentation/service.dart';
|
||||
import 'package:analyzer/src/test_utilities/platform.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart'
|
||||
|
@ -193,7 +194,7 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
|
|||
|
||||
Future<List<Assist>> _computeAssists() async {
|
||||
var context = DartAssistContextImpl(
|
||||
InstrumentationService.NULL_SERVICE,
|
||||
_TestInstrumentationService(),
|
||||
workspace,
|
||||
testAnalysisResult,
|
||||
_offset,
|
||||
|
@ -212,3 +213,19 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest {
|
|||
return positions;
|
||||
}
|
||||
}
|
||||
|
||||
class _TestInstrumentationService implements InstrumentationService {
|
||||
@override
|
||||
void logException(
|
||||
exception, [
|
||||
StackTrace stackTrace,
|
||||
List<InstrumentationServiceAttachment> attachments,
|
||||
]) {
|
||||
throw CaughtException(exception, stackTrace);
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) {
|
||||
return super.noSuchMethod(invocation);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,16 @@ main() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_one_interpolation_unterminated() async {
|
||||
verifyNoTestUnitErrors = false;
|
||||
await resolveTestCode(r'''
|
||||
void f(int a) {
|
||||
'$a
|
||||
}
|
||||
''');
|
||||
await assertNoAssistAt("'");
|
||||
}
|
||||
|
||||
Future<void> test_one_raw() async {
|
||||
await resolveTestCode('''
|
||||
main() {
|
||||
|
@ -80,6 +90,16 @@ main() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_one_simple_unterminated_empty() async {
|
||||
verifyNoTestUnitErrors = false;
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
'
|
||||
}
|
||||
''');
|
||||
await assertNoAssistAt("'");
|
||||
}
|
||||
|
||||
Future<void> test_three_embeddedTarget() async {
|
||||
await resolveTestCode("""
|
||||
main() {
|
||||
|
|
|
@ -103,6 +103,16 @@ abc""");
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_doubleQuoted_unterminated() async {
|
||||
verifyNoTestUnitErrors = false;
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
"
|
||||
}
|
||||
''');
|
||||
await assertNoAssistAt('"');
|
||||
}
|
||||
|
||||
Future<void> test_singleQuoted() async {
|
||||
await resolveTestCode('''
|
||||
main() {
|
||||
|
@ -177,4 +187,14 @@ abc''');
|
|||
}
|
||||
""");
|
||||
}
|
||||
|
||||
Future<void> test_singleQuoted_unterminated() async {
|
||||
verifyNoTestUnitErrors = false;
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
'
|
||||
}
|
||||
''');
|
||||
await assertNoAssistAt("'");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,16 @@ main() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_one_interpolation_unterminated() async {
|
||||
verifyNoTestUnitErrors = false;
|
||||
await resolveTestCode(r'''
|
||||
void f(int a) {
|
||||
"$a
|
||||
}
|
||||
''');
|
||||
await assertNoAssistAt('"');
|
||||
}
|
||||
|
||||
Future<void> test_one_raw() async {
|
||||
await resolveTestCode('''
|
||||
main() {
|
||||
|
@ -92,6 +102,16 @@ main() {
|
|||
await assertNoAssist();
|
||||
}
|
||||
|
||||
Future<void> test_one_simple_unterminated_empty() async {
|
||||
verifyNoTestUnitErrors = false;
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
"
|
||||
}
|
||||
''');
|
||||
await assertNoAssistAt('"');
|
||||
}
|
||||
|
||||
Future<void> test_three_embeddedTarget() async {
|
||||
await resolveTestCode('''
|
||||
main() {
|
||||
|
|
Loading…
Reference in a new issue