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

Side by Side Diff: pkg/front_end/lib/src/fasta/source/source_library_builder.dart

Issue 2967143002: Improve warnings related to incorrect 'part of' declarations. (Closed)
Patch Set: Address Johnni's comment. Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.source_library_builder; 5 library fasta.source_library_builder;
6 6
7 import 'package:front_end/src/scanner/token.dart' show Token; 7 import 'package:front_end/src/scanner/token.dart' show Token;
8 8
9 import 'package:kernel/ast.dart' show ProcedureKind; 9 import 'package:kernel/ast.dart' show ProcedureKind;
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 final List<List> implementationBuilders = <List<List>>[]; 59 final List<List> implementationBuilders = <List<List>>[];
60 60
61 /// Indicates whether type inference (and type promotion) should be disabled 61 /// Indicates whether type inference (and type promotion) should be disabled
62 /// for this library. 62 /// for this library.
63 final bool disableTypeInference; 63 final bool disableTypeInference;
64 64
65 String name; 65 String name;
66 66
67 String partOfName; 67 String partOfName;
68 68
69 Uri partOfUri; 69 String partOfUri;
70 70
71 List<MetadataBuilder> metadata; 71 List<MetadataBuilder> metadata;
72 72
73 /// The current declaration that is being built. When we start parsing a 73 /// The current declaration that is being built. When we start parsing a
74 /// declaration (class, method, and so on), we don't have enough information 74 /// declaration (class, method, and so on), we don't have enough information
75 /// to create a builder and this object records its members and types until, 75 /// to create a builder and this object records its members and types until,
76 /// for example, [addClass] is called. 76 /// for example, [addClass] is called.
77 DeclarationBuilder<T> currentDeclaration; 77 DeclarationBuilder<T> currentDeclaration;
78 78
79 bool canAddImplementationBuilders = false; 79 bool canAddImplementationBuilders = false;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (uri.scheme != "package") { 170 if (uri.scheme != "package") {
171 newFileUri = fileUri.resolve(path); 171 newFileUri = fileUri.resolve(path);
172 } 172 }
173 } 173 }
174 parts.add(loader.read(resolvedUri, charOffset, 174 parts.add(loader.read(resolvedUri, charOffset,
175 fileUri: newFileUri, accessor: this)); 175 fileUri: newFileUri, accessor: this));
176 } 176 }
177 177
178 void addPartOf(List<MetadataBuilder> metadata, String name, String uri) { 178 void addPartOf(List<MetadataBuilder> metadata, String name, String uri) {
179 partOfName = name; 179 partOfName = name;
180 partOfUri = uri == null ? null : this.uri.resolve(uri); 180 partOfUri = uri;
181 } 181 }
182 182
183 void addClass( 183 void addClass(
184 List<MetadataBuilder> metadata, 184 List<MetadataBuilder> metadata,
185 int modifiers, 185 int modifiers,
186 String name, 186 String name,
187 List<TypeVariableBuilder> typeVariables, 187 List<TypeVariableBuilder> typeVariables,
188 T supertype, 188 T supertype,
189 List<T> interfaces, 189 List<T> interfaces,
190 int charOffset); 190 int charOffset);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } else if (seenParts.add(part.fileUri)) { 406 } else if (seenParts.add(part.fileUri)) {
407 includePart(part); 407 includePart(part);
408 } else { 408 } else {
409 addCompileTimeError( 409 addCompileTimeError(
410 -1, "Can't use '${part.fileUri}' as a part more than once."); 410 -1, "Can't use '${part.fileUri}' as a part more than once.");
411 } 411 }
412 } 412 }
413 } 413 }
414 414
415 void includePart(SourceLibraryBuilder<T, R> part) { 415 void includePart(SourceLibraryBuilder<T, R> part) {
416 if (name != null) { 416 if (part.partOfUri != null) {
417 if (!part.isPart) { 417 if (uri.resolve(part.partOfUri) != uri) {
418 addCompileTimeError( 418 // This is a warning, but the part is still included.
419 -1,
420 "Can't use ${part.fileUri} as a part, because it has no 'part of'"
421 " declaration.");
422 parts.remove(part);
423 return;
424 }
425 if (part.partOfName != name && part.partOfUri != uri) {
426 String partName = part.partOfName ?? "${part.partOfUri}";
427 String myName = name == null ? "'$uri'" : "'${name}' ($uri)";
428 addWarning( 419 addWarning(
429 -1, 420 -1,
430 "Using '${part.fileUri}' as part of '$myName' but its 'part of'" 421 "Using '${part.relativeFileUri}' as part of '$uri' but its "
431 " declaration says '$partName'."); 422 "'part of' declaration says '${part.partOfUri}'.");
432 // The part is still included. 423 if (uri.scheme == "dart" && relativeFileUri.endsWith(part.partOfUri)) {
424 addWarning(-1, "See https://github.com/dart-lang/sdk/issues/30072.");
425 }
433 } 426 }
427 } else if (part.partOfName != null) {
428 if (name != null) {
429 if (part.partOfName != name) {
430 // This is a warning, but the part is still included.
431 addWarning(
432 -1,
433 "Using '${part.relativeFileUri}' as part of '$name' but its "
434 "'part of' declaration says '${part.partOfName}'.");
435 }
436 } else {
437 // This is a warning, but the part is still included.
438 addWarning(
439 -1,
440 "Using '${part.relativeFileUri}' as part of '${relativeFileUri}' "
441 "but its 'part of' declaration says '${part.partOfName}'.\n"
442 "Try changing the 'part of' declaration to use a relative "
443 "file name.");
444 }
445 } else if (name != null) {
446 // This is an error, and the part isn't included.
447 assert(!part.isPart);
448 addCompileTimeError(
449 -1,
450 "Can't use ${part.fileUri} as a part, because it has no 'part of'"
451 " declaration.");
452 parts.remove(part);
453 return;
434 } 454 }
435 part.forEach((String name, Builder builder) { 455 part.forEach((String name, Builder builder) {
436 if (builder.next != null) { 456 if (builder.next != null) {
437 assert(builder.next.next == null); 457 assert(builder.next.next == null);
438 addBuilder(name, builder.next, builder.next.charOffset); 458 addBuilder(name, builder.next, builder.next.charOffset);
439 } 459 }
440 addBuilder(name, builder, builder.charOffset); 460 addBuilder(name, builder, builder.charOffset);
441 }); 461 });
442 types.addAll(part.types); 462 types.addAll(part.types);
443 constructorReferences.addAll(part.constructorReferences); 463 constructorReferences.addAll(part.constructorReferences);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 /// synthesize type variables on the factory matching the class'. 628 /// synthesize type variables on the factory matching the class'.
609 void addFactoryDeclaration( 629 void addFactoryDeclaration(
610 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { 630 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) {
611 factoryDeclarations[procedure] = factoryDeclaration; 631 factoryDeclarations[procedure] = factoryDeclaration;
612 } 632 }
613 633
614 Scope toScope(Scope parent) { 634 Scope toScope(Scope parent) {
615 return new Scope(members, setters, parent, isModifiable: false); 635 return new Scope(members, setters, parent, isModifiable: false);
616 } 636 }
617 } 637 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698