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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 2401463004: Issue 27515. Report DUPLICATE_PAR when the same library contains two part directives with the same … (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.src.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 CompilationUnit partUnit = partUnits[i]; 1503 CompilationUnit partUnit = partUnits[i];
1504 Source partSource = partUnit.element.source; 1504 Source partSource = partUnit.element.source;
1505 partUnitMap[partSource] = partUnit; 1505 partUnitMap[partSource] = partUnit;
1506 } 1506 }
1507 // 1507 //
1508 // Update "part" directives. 1508 // Update "part" directives.
1509 // 1509 //
1510 LibraryIdentifier libraryNameNode = null; 1510 LibraryIdentifier libraryNameNode = null;
1511 String partsLibraryName = _UNKNOWN_LIBRARY_NAME; 1511 String partsLibraryName = _UNKNOWN_LIBRARY_NAME;
1512 bool hasPartDirective = false; 1512 bool hasPartDirective = false;
1513 Set<String> seenPartUris = new Set<String>();
1513 FunctionElement entryPoint = 1514 FunctionElement entryPoint =
1514 _findEntryPoint(definingCompilationUnitElement); 1515 _findEntryPoint(definingCompilationUnitElement);
1515 List<Directive> directivesToResolve = <Directive>[]; 1516 List<Directive> directivesToResolve = <Directive>[];
1516 List<CompilationUnitElementImpl> sourcedCompilationUnits = 1517 List<CompilationUnitElementImpl> sourcedCompilationUnits =
1517 <CompilationUnitElementImpl>[]; 1518 <CompilationUnitElementImpl>[];
1518 NodeList<Directive> directives = definingCompilationUnit.directives; 1519 NodeList<Directive> directives = definingCompilationUnit.directives;
1519 int directiveLength = directives.length; 1520 int directiveLength = directives.length;
1520 for (int i = 0; i < directiveLength; i++) { 1521 for (int i = 0; i < directiveLength; i++) {
1521 Directive directive = directives[i]; 1522 Directive directive = directives[i];
1522 if (directive is LibraryDirective) { 1523 if (directive is LibraryDirective) {
1523 libraryNameNode = directive.name; 1524 libraryNameNode = directive.name;
1524 directivesToResolve.add(directive); 1525 directivesToResolve.add(directive);
1525 } else if (directive is PartDirective) { 1526 } else if (directive is PartDirective) {
1526 StringLiteral partUri = directive.uri; 1527 StringLiteral partUri = directive.uri;
1527 Source partSource = directive.uriSource; 1528 Source partSource = directive.uriSource;
1528 hasPartDirective = true; 1529 hasPartDirective = true;
1529 CompilationUnit partUnit = partUnitMap[partSource]; 1530 CompilationUnit partUnit = partUnitMap[partSource];
1530 if (partUnit != null) { 1531 if (partUnit != null) {
1531 CompilationUnitElementImpl partElement = partUnit.element; 1532 CompilationUnitElementImpl partElement = partUnit.element;
1532 partElement.uriOffset = partUri.offset; 1533 partElement.uriOffset = partUri.offset;
1533 partElement.uriEnd = partUri.end; 1534 partElement.uriEnd = partUri.end;
1534 partElement.uri = directive.uriContent; 1535 partElement.uri = directive.uriContent;
1535 // 1536 //
1536 // Validate that the part contains a part-of directive with the same 1537 // Validate that the part contains a part-of directive with the same
Paul Berry 2016/10/06 18:18:23 This comment is incorrect.
1537 // name as the library. 1538 // name as the library.
1538 // 1539 //
1540 if (!seenPartUris.add(directive.uriContent)) {
1541 errors.add(new AnalysisError(
1542 librarySource,
1543 partUri.offset,
1544 partUri.length,
1545 CompileTimeErrorCode.DUPLICATE_PART,
1546 [directive.uriContent]));
1547 }
1548 //
1549 // Validate that the part contains a part-of directive with the same
1550 // name as the library.
1551 //
1539 if (context.exists(partSource)) { 1552 if (context.exists(partSource)) {
1540 String partLibraryName = 1553 String partLibraryName =
1541 _getPartLibraryName(partSource, partUnit, directivesToResolve); 1554 _getPartLibraryName(partSource, partUnit, directivesToResolve);
1542 if (partLibraryName == null) { 1555 if (partLibraryName == null) {
1543 errors.add(new AnalysisError( 1556 errors.add(new AnalysisError(
1544 librarySource, 1557 librarySource,
1545 partUri.offset, 1558 partUri.offset,
1546 partUri.length, 1559 partUri.length,
1547 CompileTimeErrorCode.PART_OF_NON_PART, 1560 CompileTimeErrorCode.PART_OF_NON_PART,
1548 [partUri.toSource()])); 1561 [partUri.toSource()]));
(...skipping 4883 matching lines...) Expand 10 before | Expand all | Expand 10 after
6432 6445
6433 @override 6446 @override
6434 bool moveNext() { 6447 bool moveNext() {
6435 if (_newSources.isEmpty) { 6448 if (_newSources.isEmpty) {
6436 return false; 6449 return false;
6437 } 6450 }
6438 currentTarget = _newSources.removeLast(); 6451 currentTarget = _newSources.removeLast();
6439 return true; 6452 return true;
6440 } 6453 }
6441 } 6454 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/error/codes.dart ('k') | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698