| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 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/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| (...skipping 4621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4632 if (parent2 is FunctionDeclaration && | 4632 if (parent2 is FunctionDeclaration && |
| 4633 parent2.parent is! FunctionDeclarationStatement) { | 4633 parent2.parent is! FunctionDeclarationStatement) { |
| 4634 return parent.body == body; | 4634 return parent.body == body; |
| 4635 } | 4635 } |
| 4636 } | 4636 } |
| 4637 return false; | 4637 return false; |
| 4638 } | 4638 } |
| 4639 } | 4639 } |
| 4640 | 4640 |
| 4641 /** | 4641 /** |
| 4642 * Instances of the class `PubVerifier` traverse an AST structure looking for de
viations from | |
| 4643 * pub best practices. | |
| 4644 */ | |
| 4645 class PubVerifier extends RecursiveAstVisitor<Object> { | |
| 4646 // static String _PUBSPEC_YAML = "pubspec.yaml"; | |
| 4647 | |
| 4648 /** | |
| 4649 * The analysis context containing the sources to be analyzed | |
| 4650 */ | |
| 4651 final AnalysisContext _context; | |
| 4652 | |
| 4653 /** | |
| 4654 * The error reporter by which errors will be reported. | |
| 4655 */ | |
| 4656 final ErrorReporter _errorReporter; | |
| 4657 | |
| 4658 PubVerifier(this._context, this._errorReporter); | |
| 4659 | |
| 4660 @override | |
| 4661 Object visitImportDirective(ImportDirective directive) { | |
| 4662 return null; | |
| 4663 } | |
| 4664 | |
| 4665 // /** | |
| 4666 // * This verifies that the passed file import directive is not contained in a
source inside a | |
| 4667 // * package "lib" directory hierarchy referencing a source outside that packa
ge "lib" directory | |
| 4668 // * hierarchy. | |
| 4669 // * | |
| 4670 // * @param uriLiteral the import URL (not `null`) | |
| 4671 // * @param path the file path being verified (not `null`) | |
| 4672 // * @return `true` if and only if an error code is generated on the passed no
de | |
| 4673 // * See [PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]. | |
| 4674 // */ | |
| 4675 // bool | |
| 4676 // _checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiter
al, | |
| 4677 // String path) { | |
| 4678 // Source source = _getSource(uriLiteral); | |
| 4679 // String fullName = _getSourceFullName(source); | |
| 4680 // if (fullName != null) { | |
| 4681 // int pathIndex = 0; | |
| 4682 // int fullNameIndex = fullName.length; | |
| 4683 // while (pathIndex < path.length && | |
| 4684 // StringUtilities.startsWith3(path, pathIndex, 0x2E, 0x2E, 0x2F)) { | |
| 4685 // fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); | |
| 4686 // if (fullNameIndex < 4) { | |
| 4687 // return false; | |
| 4688 // } | |
| 4689 // // Check for "/lib" at a specified place in the fullName | |
| 4690 // if (StringUtilities.startsWith4( | |
| 4691 // fullName, | |
| 4692 // fullNameIndex - 4, | |
| 4693 // 0x2F, | |
| 4694 // 0x6C, | |
| 4695 // 0x69, | |
| 4696 // 0x62)) { | |
| 4697 // String relativePubspecPath = | |
| 4698 // path.substring(0, pathIndex + 3) + | |
| 4699 // _PUBSPEC_YAML; | |
| 4700 // Source pubspecSource = | |
| 4701 // _context.sourceFactory.resolveUri(source, relativePubspecPath); | |
| 4702 // if (_context.exists(pubspecSource)) { | |
| 4703 // // Files inside the lib directory hierarchy should not reference | |
| 4704 // // files outside | |
| 4705 // _errorReporter.reportErrorForNode( | |
| 4706 // HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE, | |
| 4707 // uriLiteral); | |
| 4708 // } | |
| 4709 // return true; | |
| 4710 // } | |
| 4711 // pathIndex += 3; | |
| 4712 // } | |
| 4713 // } | |
| 4714 // return false; | |
| 4715 // } | |
| 4716 | |
| 4717 // /** | |
| 4718 // * This verifies that the passed file import directive is not contained in a
source outside a | |
| 4719 // * package "lib" directory hierarchy referencing a source inside that packag
e "lib" directory | |
| 4720 // * hierarchy. | |
| 4721 // * | |
| 4722 // * @param uriLiteral the import URL (not `null`) | |
| 4723 // * @param path the file path being verified (not `null`) | |
| 4724 // * @return `true` if and only if an error code is generated on the passed no
de | |
| 4725 // * See [PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]. | |
| 4726 // */ | |
| 4727 // bool | |
| 4728 // _checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiter
al, | |
| 4729 // String path) { | |
| 4730 // if (StringUtilities.startsWith4(path, 0, 0x6C, 0x69, 0x62, 0x2F)) { | |
| 4731 // if (_checkForFileImportOutsideLibReferencesFileInsideAtIndex( | |
| 4732 // uriLiteral, | |
| 4733 // path, | |
| 4734 // 0)) { | |
| 4735 // return true; | |
| 4736 // } | |
| 4737 // } | |
| 4738 // int pathIndex = | |
| 4739 // StringUtilities.indexOf5(path, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F); | |
| 4740 // while (pathIndex != -1) { | |
| 4741 // if (_checkForFileImportOutsideLibReferencesFileInsideAtIndex( | |
| 4742 // uriLiteral, | |
| 4743 // path, | |
| 4744 // pathIndex + 1)) { | |
| 4745 // return true; | |
| 4746 // } | |
| 4747 // pathIndex = | |
| 4748 // StringUtilities.indexOf5(path, pathIndex + 4, 0x2F, 0x6C, 0x69, 0x62
, 0x2F); | |
| 4749 // } | |
| 4750 // return false; | |
| 4751 // } | |
| 4752 | |
| 4753 // bool | |
| 4754 // _checkForFileImportOutsideLibReferencesFileInsideAtIndex(StringLiteral u
riLiteral, | |
| 4755 // String path, int pathIndex) { | |
| 4756 // Source source = _getSource(uriLiteral); | |
| 4757 // String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; | |
| 4758 // Source pubspecSource = | |
| 4759 // _context.sourceFactory.resolveUri(source, relativePubspecPath); | |
| 4760 // if (!_context.exists(pubspecSource)) { | |
| 4761 // return false; | |
| 4762 // } | |
| 4763 // String fullName = _getSourceFullName(source); | |
| 4764 // if (fullName != null) { | |
| 4765 // if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F)
< | |
| 4766 // 0) { | |
| 4767 // // Files outside the lib directory hierarchy should not reference file
s | |
| 4768 // // inside ... use package: url instead | |
| 4769 // _errorReporter.reportErrorForNode( | |
| 4770 // HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE, | |
| 4771 // uriLiteral); | |
| 4772 // return true; | |
| 4773 // } | |
| 4774 // } | |
| 4775 // return false; | |
| 4776 // } | |
| 4777 | |
| 4778 // /** | |
| 4779 // * This verifies that the passed package import directive does not contain "
.." | |
| 4780 // * | |
| 4781 // * @param uriLiteral the import URL (not `null`) | |
| 4782 // * @param path the path to be validated (not `null`) | |
| 4783 // * @return `true` if and only if an error code is generated on the passed no
de | |
| 4784 // * See [PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]. | |
| 4785 // */ | |
| 4786 // bool _checkForPackageImportContainsDotDot(StringLiteral uriLiteral, | |
| 4787 // String path) { | |
| 4788 // if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || | |
| 4789 // StringUtilities.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) { | |
| 4790 // // Package import should not to contain ".." | |
| 4791 // _errorReporter.reportErrorForNode( | |
| 4792 // HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT, | |
| 4793 // uriLiteral); | |
| 4794 // return true; | |
| 4795 // } | |
| 4796 // return false; | |
| 4797 // } | |
| 4798 | |
| 4799 // /** | |
| 4800 // * Answer the source associated with the compilation unit containing the giv
en AST node. | |
| 4801 // * | |
| 4802 // * @param node the node (not `null`) | |
| 4803 // * @return the source or `null` if it could not be determined | |
| 4804 // */ | |
| 4805 // Source _getSource(AstNode node) { | |
| 4806 // Source source = null; | |
| 4807 // CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit)
; | |
| 4808 // if (unit != null) { | |
| 4809 // CompilationUnitElement element = unit.element; | |
| 4810 // if (element != null) { | |
| 4811 // source = element.source; | |
| 4812 // } | |
| 4813 // } | |
| 4814 // return source; | |
| 4815 // } | |
| 4816 | |
| 4817 // /** | |
| 4818 // * Answer the full name of the given source. The returned value will have al
l | |
| 4819 // * [File.separatorChar] replace by '/'. | |
| 4820 // * | |
| 4821 // * @param source the source | |
| 4822 // * @return the full name or `null` if it could not be determined | |
| 4823 // */ | |
| 4824 // String _getSourceFullName(Source source) { | |
| 4825 // if (source != null) { | |
| 4826 // String fullName = source.fullName; | |
| 4827 // if (fullName != null) { | |
| 4828 // return fullName.replaceAll(r'\', '/'); | |
| 4829 // } | |
| 4830 // } | |
| 4831 // return null; | |
| 4832 // } | |
| 4833 } | |
| 4834 | |
| 4835 /** | |
| 4836 * Kind of the redirecting constructor. | 4642 * Kind of the redirecting constructor. |
| 4837 */ | 4643 */ |
| 4838 class RedirectingConstructorKind | 4644 class RedirectingConstructorKind |
| 4839 implements Comparable<RedirectingConstructorKind> { | 4645 implements Comparable<RedirectingConstructorKind> { |
| 4840 static const RedirectingConstructorKind CONST = | 4646 static const RedirectingConstructorKind CONST = |
| 4841 const RedirectingConstructorKind('CONST', 0); | 4647 const RedirectingConstructorKind('CONST', 0); |
| 4842 | 4648 |
| 4843 static const RedirectingConstructorKind NORMAL = | 4649 static const RedirectingConstructorKind NORMAL = |
| 4844 const RedirectingConstructorKind('NORMAL', 1); | 4650 const RedirectingConstructorKind('NORMAL', 1); |
| 4845 | 4651 |
| (...skipping 6006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10852 return null; | 10658 return null; |
| 10853 } | 10659 } |
| 10854 if (identical(node.staticElement, variable)) { | 10660 if (identical(node.staticElement, variable)) { |
| 10855 if (node.inSetterContext()) { | 10661 if (node.inSetterContext()) { |
| 10856 result = true; | 10662 result = true; |
| 10857 } | 10663 } |
| 10858 } | 10664 } |
| 10859 return null; | 10665 return null; |
| 10860 } | 10666 } |
| 10861 } | 10667 } |
| OLD | NEW |