Issue 32765. Improve guess for type name identifier.
R=brianwilkerson@google.com
Bug: https://github.com/dart-lang/sdk/issues/32765
Change-Id: I7587fd2aaba50e4e07c9192d95141ece80d423b1
Reviewed-on: https://dart-review.googlesource.com/54303
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/test/services/correction/fix_test.dart b/pkg/analysis_server/test/services/correction/fix_test.dart
index c607d0e..a95b938 100644
--- a/pkg/analysis_server/test/services/correction/fix_test.dart
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart
@@ -4139,6 +4139,27 @@
''');
}
+ test_importLibraryProject_withClass_instanceCreation_const_namedConstructor() async {
+ testFile = '/project/lib/test.dart';
+ addSource('/project/lib/lib.dart', '''
+class Test {
+ const Test.named();
+}
+''');
+ await resolveTestUnit('''
+main() {
+ const Test.named();
+}
+''');
+ await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, '''
+import 'lib.dart';
+
+main() {
+ const Test.named();
+}
+''');
+ }
+
test_importLibraryProject_withClass_instanceCreation_implicit() async {
testFile = '/project/lib/test.dart';
addSource('/project/lib/lib.dart', '''
@@ -4181,6 +4202,27 @@
''');
}
+ test_importLibraryProject_withClass_instanceCreation_new_namedConstructor() async {
+ testFile = '/project/lib/test.dart';
+ addSource('/project/lib/lib.dart', '''
+class Test {
+ Test.named();
+}
+''');
+ await resolveTestUnit('''
+main() {
+ new Test.named();
+}
+''');
+ await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, '''
+import 'lib.dart';
+
+main() {
+ new Test.named();
+}
+''');
+ }
+
test_importLibraryProject_withFunction() async {
testFile = '/project/lib/test.dart';
addSource('/project/lib/lib.dart', '''
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index c93ad27..503d7b1 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -8504,7 +8504,17 @@
if (typeName is SimpleIdentifier) {
return typeName;
} else {
- return (typeName as PrefixedIdentifier).identifier;
+ PrefixedIdentifier prefixed = typeName;
+ SimpleIdentifier prefix = prefixed.prefix;
+ // The prefixed identifier can be:
+ // 1. new importPrefix.TypeName()
+ // 2. new TypeName.constructorName()
+ // 3. new unresolved.Unresolved()
+ if (prefix.staticElement is PrefixElement) {
+ return prefixed.identifier;
+ } else {
+ return prefix;
+ }
}
}