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

Side by Side Diff: pkg/analysis_services/lib/src/correction/fix.dart

Issue 427473003: Uncomment and test fixes for importing libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library services.src.correction.fix; 8 library services.src.correction.fix;
9 9
10 import 'dart:collection';
11
10 import 'package:analysis_services/correction/change.dart'; 12 import 'package:analysis_services/correction/change.dart';
11 import 'package:analysis_services/correction/fix.dart'; 13 import 'package:analysis_services/correction/fix.dart';
12 import 'package:analysis_services/search/hierarchy.dart'; 14 import 'package:analysis_services/search/hierarchy.dart';
13 import 'package:analysis_services/search/search_engine.dart'; 15 import 'package:analysis_services/search/search_engine.dart';
14 import 'package:analysis_services/src/correction/levenshtein.dart'; 16 import 'package:analysis_services/src/correction/levenshtein.dart';
15 import 'package:analysis_services/src/correction/name_suggestion.dart'; 17 import 'package:analysis_services/src/correction/name_suggestion.dart';
16 import 'package:analysis_services/src/correction/source_buffer.dart'; 18 import 'package:analysis_services/src/correction/source_buffer.dart';
17 import 'package:analysis_services/src/correction/source_range.dart' as rf; 19 import 'package:analysis_services/src/correction/source_range.dart' as rf;
18 import 'package:analysis_services/src/correction/strings.dart'; 20 import 'package:analysis_services/src/correction/strings.dart';
19 import 'package:analysis_services/src/correction/util.dart'; 21 import 'package:analysis_services/src/correction/util.dart';
20 import 'package:analyzer/src/generated/ast.dart'; 22 import 'package:analyzer/src/generated/ast.dart';
21 import 'package:analyzer/src/generated/element.dart'; 23 import 'package:analyzer/src/generated/element.dart';
24 import 'package:analyzer/src/generated/engine.dart';
22 import 'package:analyzer/src/generated/error.dart'; 25 import 'package:analyzer/src/generated/error.dart';
23 import 'package:analyzer/src/generated/java_core.dart'; 26 import 'package:analyzer/src/generated/java_core.dart';
24 import 'package:analyzer/src/generated/parser.dart'; 27 import 'package:analyzer/src/generated/parser.dart';
25 import 'package:analyzer/src/generated/scanner.dart'; 28 import 'package:analyzer/src/generated/scanner.dart';
29 import 'package:analyzer/src/generated/sdk.dart';
26 import 'package:analyzer/src/generated/source.dart'; 30 import 'package:analyzer/src/generated/source.dart';
27 import 'package:analyzer/src/generated/utilities_dart.dart'; 31 import 'package:analyzer/src/generated/utilities_dart.dart';
32 import 'package:path/path.dart';
28 33
29 34
30 /** 35 /**
31 * A predicate is a one-argument function that returns a boolean value. 36 * A predicate is a one-argument function that returns a boolean value.
32 */ 37 */
33 typedef bool Predicate<E>(E argument); 38 typedef bool Predicate<E>(E argument);
34 39
35 40
36 /** 41 /**
37 * The computer for Dart fixes. 42 * The computer for Dart fixes.
38 */ 43 */
39 class FixProcessor { 44 class FixProcessor {
40 static const int MAX_LEVENSHTEIN_DISTANCE = 3; 45 static const int MAX_LEVENSHTEIN_DISTANCE = 3;
41 46
42 final SearchEngine searchEngine; 47 final SearchEngine searchEngine;
43 final Source source; 48 final Source source;
44 final String file; 49 final String file;
45 final CompilationUnit unit; 50 final CompilationUnit unit;
46 final AnalysisError error; 51 final AnalysisError error;
47 CompilationUnitElement unitElement; 52 CompilationUnitElement unitElement;
48 LibraryElement unitLibraryElement; 53 LibraryElement unitLibraryElement;
54 String unitLibraryFile;
55 String unitLibraryFolder;
49 56
50 final List<Edit> edits = <Edit>[]; 57 final List<Edit> edits = <Edit>[];
51 final Map<String, LinkedPositionGroup> linkedPositionGroups = <String, 58 final Map<String, LinkedPositionGroup> linkedPositionGroups = <String,
52 LinkedPositionGroup>{}; 59 LinkedPositionGroup>{};
53 Position endPosition = null; 60 Position endPosition = null;
54 final List<Fix> fixes = <Fix>[]; 61 final List<Fix> fixes = <Fix>[];
55 62
56 CorrectionUtils utils; 63 CorrectionUtils utils;
57 int errorOffset; 64 int errorOffset;
58 int errorLength; 65 int errorLength;
59 int errorEnd; 66 int errorEnd;
60 AstNode node; 67 AstNode node;
61 AstNode coveredNode; 68 AstNode coveredNode;
62 69
63 70
64 FixProcessor(this.searchEngine, this.source, this.file, this.unit, this.error) 71 FixProcessor(this.searchEngine, this.source, this.file, this.unit, this.error)
65 { 72 {
66 unitElement = unit.element; 73 unitElement = unit.element;
67 unitLibraryElement = unitElement.library; 74 unitLibraryElement = unitElement.library;
75 unitLibraryFile = unitLibraryElement.source.fullName;
76 unitLibraryFolder = dirname(unitLibraryFile);
68 } 77 }
69 78
70 DartType get coreTypeBool => _getCoreType("bool"); 79 DartType get coreTypeBool => _getCoreType("bool");
71 80
72 /** 81 /**
73 * Returns the EOL to use for this [CompilationUnit]. 82 * Returns the EOL to use for this [CompilationUnit].
74 */ 83 */
75 String get eol => utils.endOfLine; 84 String get eol => utils.endOfLine;
76 85
77 List<Fix> compute() { 86 List<Fix> compute() {
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // new CreateFileCorrectionProposal( 733 // new CreateFileCorrectionProposal(
725 // newFile, 734 // newFile,
726 // source, 735 // source,
727 // FixKind.CREATE_PART, 736 // FixKind.CREATE_PART,
728 // [uriString])); 737 // [uriString]));
729 // } 738 // }
730 // } 739 // }
731 } 740 }
732 741
733 void _addFix_importLibrary(FixKind kind, String importPath) { 742 void _addFix_importLibrary(FixKind kind, String importPath) {
734 // TODO(scheglov) implement 743 CompilationUnitElement libraryUnitElement =
735 // CompilationUnitElement libraryUnitElement = 744 unitLibraryElement.definingCompilationUnit;
736 // _unitLibraryElement.definingCompilationUnit; 745 CompilationUnit libraryUnit = libraryUnitElement.node;
737 // CompilationUnit libraryUnit = libraryUnitElement.node; 746 // prepare new import location
738 // // prepare new import location 747 int offset = 0;
739 // int offset = 0; 748 String prefix;
740 // String prefix; 749 String suffix;
741 // String suffix; 750 {
742 // { 751 // if no directives
743 // // if no directives 752 prefix = "";
744 // prefix = ""; 753 suffix = eol;
745 // suffix = eol; 754 CorrectionUtils libraryUtils = new CorrectionUtils(libraryUnit);
746 // CorrectionUtils libraryUtils = new CorrectionUtils(libraryUnit); 755 // after last directive in library
747 // // after last directive in library 756 for (Directive directive in libraryUnit.directives) {
748 // for (Directive directive in libraryUnit.directives) { 757 if (directive is LibraryDirective || directive is ImportDirective) {
749 // if (directive is LibraryDirective || directive is ImportDirective) { 758 offset = directive.end;
750 // offset = directive.end; 759 prefix = eol;
751 // prefix = eol; 760 suffix = "";
752 // suffix = ""; 761 }
753 // } 762 }
754 // } 763 // if still beginning of file, skip shebang and line comments
755 // // if still beginning of file, skip shebang and line comments 764 if (offset == 0) {
756 // if (offset == 0) { 765 CorrectionUtils_InsertDesc desc = libraryUtils.insertDescTop;
757 // CorrectionUtils_InsertDesc desc = libraryUtils.insertDescTop; 766 offset = desc.offset;
758 // offset = desc.offset; 767 prefix = desc.prefix;
759 // prefix = desc.prefix; 768 suffix = "${desc.suffix}${eol}";
760 // suffix = "${desc.suffix}${eol}"; 769 }
761 // } 770 }
762 // } 771 // insert new import
763 // // insert new import 772 String importSource = "${prefix}import '${importPath}';${suffix}";
764 // String importSource = "${prefix}import '${importPath}';${suffix}"; 773 _addInsertEdit(offset, importSource);
765 // _addInsertEdit(offset, importSource); 774 // add proposal
766 // // add proposal 775 _addFix(kind, [importPath], fixFile: libraryUnitElement.source.fullName);
767 // _addUnitCorrectionProposal2(libraryUnitElement.source, kind, [importPath]) ;
768 } 776 }
769 777
770 void _addFix_importLibrary_withElement(String name, ElementKind kind) { 778 void _addFix_importLibrary_withElement(String name, ElementKind kind) {
771 // TODO(scheglov) implement 779 // ignore if private
772 // // ignore if private 780 if (name.startsWith("_")) {
773 // if (name.startsWith("_")) { 781 return;
774 // return; 782 }
775 // } 783
776 // // may be there is an existing import, but it is with prefix and we don't use this prefix 784 // may be there is an existing import,
777 // for (ImportElement imp in _unitLibraryElement.imports) { 785 // but it is with prefix and we don't use this prefix
778 // // prepare element 786 for (ImportElement imp in unitLibraryElement.imports) {
779 // LibraryElement libraryElement = imp.importedLibrary; 787 // prepare element
780 // Element element = 788 LibraryElement libraryElement = imp.importedLibrary;
781 // CorrectionUtils.getExportedElement(libraryElement, name); 789 Element element = getExportedElement(libraryElement, name);
782 // if (element == null) { 790 if (element == null) {
783 // continue; 791 continue;
784 // } 792 }
785 // if (element is PropertyAccessorElement) { 793 if (element is PropertyAccessorElement) {
786 // element = (element as PropertyAccessorElement).variable; 794 element = (element as PropertyAccessorElement).variable;
787 // } 795 }
788 // if (element.kind != kind) { 796 if (element.kind != kind) {
789 // continue; 797 continue;
790 // } 798 }
791 // // may be apply prefix 799 // may be apply prefix
792 // PrefixElement prefix = imp.prefix; 800 PrefixElement prefix = imp.prefix;
793 // if (prefix != null) { 801 if (prefix != null) {
794 // SourceRange range = SourceRangeFactory.rangeStartLength(node, 0); 802 SourceRange range = rf.rangeStartLength(node, 0);
795 // _addReplaceEdit(range, "${prefix.displayName}."); 803 _addReplaceEdit(range, "${prefix.displayName}.");
796 // _addFix( 804 _addFix(
797 // FixKind.IMPORT_LIBRARY_PREFIX, 805 FixKind.IMPORT_LIBRARY_PREFIX,
798 // [libraryElement.displayName, prefix.displayName]); 806 [libraryElement.displayName, prefix.displayName]);
799 // continue; 807 continue;
800 // } 808 }
801 // // may be update "show" directive 809 // may be update "show" directive
802 // List<NamespaceCombinator> combinators = imp.combinators; 810 List<NamespaceCombinator> combinators = imp.combinators;
803 // if (combinators.length == 1 && combinators[0] is ShowElementCombinator) { 811 if (combinators.length == 1 && combinators[0] is ShowElementCombinator) {
804 // ShowElementCombinator showCombinator = 812 ShowElementCombinator showCombinator =
805 // combinators[0] as ShowElementCombinator; 813 combinators[0] as ShowElementCombinator;
806 // // prepare new set of names to show 814 // prepare new set of names to show
807 // Set<String> showNames = new Set<String>(); 815 Set<String> showNames = new SplayTreeSet<String>();
808 // showNames.addAll(showCombinator.shownNames); 816 showNames.addAll(showCombinator.shownNames);
809 // showNames.add(name); 817 showNames.add(name);
810 // // prepare library name - unit name or 'dart:name' for SDK library 818 // prepare library name - unit name or 'dart:name' for SDK library
811 // String libraryName = libraryElement.definingCompilationUnit.displayNam e; 819 String libraryName = libraryElement.definingCompilationUnit.displayName;
812 // if (libraryElement.isInSdk) { 820 if (libraryElement.isInSdk) {
813 // libraryName = imp.uri; 821 libraryName = imp.uri;
814 // } 822 }
815 // // update library 823 // update library
816 // String newShowCode = "show ${StringUtils.join(showNames, ", ")}"; 824 String newShowCode = "show ${StringUtils.join(showNames, ", ")}";
817 // // TODO(scheglov) 825 _addReplaceEdit(rf.rangeOffsetEnd(showCombinator), newShowCode);
818 // _addReplaceEdit( 826 _addFix(
819 // SourceRangeFactory.rangeShowCombinator(showCombinator), 827 FixKind.IMPORT_LIBRARY_SHOW,
820 // newShowCode); 828 [libraryName],
821 // _addUnitCorrectionProposal2( 829 fixFile: unitLibraryFile);
822 // _unitLibraryElement.source, 830 // we support only one import without prefix
823 // FixKind.IMPORT_LIBRARY_SHOW, 831 return;
824 // [libraryName]); 832 }
825 // // we support only one import without prefix 833 }
826 // return; 834 // check SDK libraries
827 // } 835 AnalysisContext context = unitLibraryElement.context;
828 // } 836 {
829 // // check SDK libraries 837 DartSdk sdk = context.sourceFactory.dartSdk;
830 // AnalysisContext context = _unitLibraryElement.context; 838 List<SdkLibrary> sdkLibraries = sdk.sdkLibraries;
831 // { 839 for (SdkLibrary sdkLibrary in sdkLibraries) {
832 // DartSdk sdk = context.sourceFactory.dartSdk; 840 SourceFactory sdkSourceFactory = context.sourceFactory;
833 // List<SdkLibrary> sdkLibraries = sdk.sdkLibraries; 841 String libraryUri = sdkLibrary.shortName;
834 // for (SdkLibrary sdkLibrary in sdkLibraries) { 842 Source librarySource = sdkSourceFactory.resolveUri(null, libraryUri);
835 // SourceFactory sdkSourceFactory = context.sourceFactory; 843 // prepare LibraryElement
836 // String libraryUri = sdkLibrary.shortName; 844 LibraryElement libraryElement =
837 // Source librarySource = sdkSourceFactory.resolveUri(null, libraryUri); 845 context.getLibraryElement(librarySource);
838 // // prepare LibraryElement 846 if (libraryElement == null) {
839 // LibraryElement libraryElement = 847 continue;
840 // context.getLibraryElement(librarySource); 848 }
841 // if (libraryElement == null) { 849 // prepare exported Element
842 // continue; 850 Element element = getExportedElement(libraryElement, name);
843 // } 851 if (element == null) {
844 // // prepare exported Element 852 continue;
845 // Element element = 853 }
846 // CorrectionUtils.getExportedElement(libraryElement, name); 854 if (element is PropertyAccessorElement) {
847 // if (element == null) { 855 element = (element as PropertyAccessorElement).variable;
848 // continue; 856 }
849 // } 857 if (element.kind != kind) {
850 // if (element is PropertyAccessorElement) { 858 continue;
851 // element = (element as PropertyAccessorElement).variable; 859 }
852 // } 860 // add import
853 // if (element.kind != kind) { 861 _addFix_importLibrary(FixKind.IMPORT_LIBRARY_SDK, libraryUri);
854 // continue; 862 }
855 // } 863 }
856 // // add import 864 // check project libraries
857 // _addFix_importLibrary(FixKind.IMPORT_LIBRARY_SDK, libraryUri); 865 {
858 // } 866 List<Source> librarySources = context.librarySources;
859 // } 867 for (Source librarySource in librarySources) {
860 // // check project libraries 868 // we don't need SDK libraries here
861 // { 869 if (librarySource.isInSystemLibrary) {
862 // List<Source> librarySources = context.librarySources; 870 continue;
863 // for (Source librarySource in librarySources) { 871 }
864 // // we don't need SDK libraries here 872 // prepare LibraryElement
865 // if (librarySource.isInSystemLibrary) { 873 LibraryElement libraryElement =
866 // continue; 874 context.getLibraryElement(librarySource);
867 // } 875 if (libraryElement == null) {
868 // // prepare LibraryElement 876 continue;
869 // LibraryElement libraryElement = 877 }
870 // context.getLibraryElement(librarySource); 878 // prepare exported Element
871 // if (libraryElement == null) { 879 Element element = getExportedElement(libraryElement, name);
872 // continue; 880 if (element == null) {
873 // } 881 continue;
874 // // prepare exported Element 882 }
875 // Element element = 883 if (element is PropertyAccessorElement) {
876 // CorrectionUtils.getExportedElement(libraryElement, name); 884 element = (element as PropertyAccessorElement).variable;
877 // if (element == null) { 885 }
878 // continue; 886 if (element.kind != kind) {
879 // } 887 continue;
880 // if (element.kind != kind) { 888 }
881 // continue; 889 // prepare "library" file
882 // } 890 String libraryFile = librarySource.fullName;
883 // // prepare "library" file 891 // may be "package:" URI
884 // JavaFile libraryFile = getSourceFile(librarySource); 892 // TODO(scheglov) this code does not have a test
885 // if (libraryFile == null) { 893 {
886 // continue; 894 String libraryPackageUri = _findPackageUri(context, libraryFile);
887 // } 895 if (libraryPackageUri != null) {
888 // // may be "package:" URI 896 _addFix_importLibrary(
889 // { 897 FixKind.IMPORT_LIBRARY_PROJECT,
890 // Uri libraryPackageUri = _findPackageUri(context, libraryFile); 898 libraryPackageUri);
891 // if (libraryPackageUri != null) { 899 continue;
892 // _addFix_importLibrary( 900 }
893 // FixKind.IMPORT_LIBRARY_PROJECT, 901 }
894 // libraryPackageUri.toString()); 902 // relative URI
895 // continue; 903 String relateFile = relative(libraryFile, from: unitLibraryFolder);
896 // } 904 _addFix_importLibrary(FixKind.IMPORT_LIBRARY_PROJECT, relateFile);
897 // } 905 }
898 // // relative URI 906 }
899 // String relative =
900 // URIUtils.computeRelativePath(
901 // _unitLibraryFolder.getAbsolutePath(),
902 // libraryFile.getAbsolutePath());
903 // _addFix_importLibrary(
904 // FixKind.IMPORT_LIBRARY_PROJECT,
905 // relative);
906 // }
907 // }
908 } 907 }
909 908
910 void _addFix_importLibrary_withFunction() { 909 void _addFix_importLibrary_withFunction() {
911 // TODO(scheglov) implement 910 if (node is SimpleIdentifier && node.parent is MethodInvocation) {
912 // if (node is SimpleIdentifier && node.parent is MethodInvocation) { 911 MethodInvocation invocation = node.parent as MethodInvocation;
913 // MethodInvocation invocation = node.parent as MethodInvocation; 912 if (invocation.realTarget == null && invocation.methodName == node) {
914 // if (invocation.realTarget == null && 913 String name = (node as SimpleIdentifier).name;
915 // identical(invocation.methodName, node)) { 914 _addFix_importLibrary_withElement(name, ElementKind.FUNCTION);
916 // String name = (node as SimpleIdentifier).name; 915 }
917 // _addFix_importLibrary_withElement(name, ElementKind.FUNCTION); 916 }
918 // }
919 // }
920 } 917 }
921 918
922 void _addFix_importLibrary_withTopLevelVariable() { 919 void _addFix_importLibrary_withTopLevelVariable() {
923 // TODO(scheglov) implement 920 if (node is SimpleIdentifier) {
924 // if (node is SimpleIdentifier) { 921 String name = (node as SimpleIdentifier).name;
925 // String name = (node as SimpleIdentifier).name; 922 _addFix_importLibrary_withElement(name, ElementKind.TOP_LEVEL_VARIABLE);
926 // _addFix_importLibrary_withElement(name, ElementKind.TOP_LEVEL_VARIABLE); 923 }
927 // }
928 } 924 }
929 925
930 void _addFix_importLibrary_withType() { 926 void _addFix_importLibrary_withType() {
931 // TODO(scheglov) implement 927 if (_mayBeTypeIdentifier(node)) {
932 // if (_mayBeTypeIdentifier(node)) { 928 String typeName = (node as SimpleIdentifier).name;
933 // String typeName = (node as SimpleIdentifier).name; 929 _addFix_importLibrary_withElement(typeName, ElementKind.CLASS);
934 // _addFix_importLibrary_withElement(typeName, ElementKind.CLASS); 930 }
935 // }
936 } 931 }
937 932
938 void _addFix_insertSemicolon() { 933 void _addFix_insertSemicolon() {
939 if (error.message.contains("';'")) { 934 if (error.message.contains("';'")) {
940 int insertOffset = error.offset + error.length; 935 int insertOffset = error.offset + error.length;
941 _addInsertEdit(insertOffset, ";"); 936 _addInsertEdit(insertOffset, ";");
942 _addFix(FixKind.INSERT_SEMICOLON, []); 937 _addFix(FixKind.INSERT_SEMICOLON, []);
943 } 938 }
944 } 939 }
945 940
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 if (operatorType == TokenType.AMPERSAND_AMPERSAND || 1764 if (operatorType == TokenType.AMPERSAND_AMPERSAND ||
1770 operatorType == TokenType.BAR_BAR) { 1765 operatorType == TokenType.BAR_BAR) {
1771 return coreTypeBool; 1766 return coreTypeBool;
1772 } 1767 }
1773 } 1768 }
1774 } 1769 }
1775 // we don't know 1770 // we don't know
1776 return null; 1771 return null;
1777 } 1772 }
1778 1773
1774 /**
1775 * Inserts the given [SourceBuilder] at its offset.
1776 */
1777 void _insertBuilder(SourceBuilder builder) {
1778 String text = builder.toString();
1779 _addInsertEdit(builder.offset, text);
1780 // add linked positions
1781 builder.linkedPositionGroups.forEach((LinkedPositionGroup group) {
1782 LinkedPositionGroup fixGroup = _getLinkedPosition(group.id);
1783 group.positions.forEach((Position position) {
1784 fixGroup.addPosition(position);
1785 });
1786 group.proposals.forEach((String proposal) {
1787 fixGroup.addProposal(proposal);
1788 });
1789 });
1790 }
1791
1779 // void _addLinkedPositionProposal(String group, 1792 // void _addLinkedPositionProposal(String group,
1780 // LinkedPositionProposal proposal) { 1793 // LinkedPositionProposal proposal) {
1781 // List<LinkedPositionProposal> nodeProposals = linkedPositionProposals[group ]; 1794 // List<LinkedPositionProposal> nodeProposals = linkedPositionProposals[group ];
1782 // if (nodeProposals == null) { 1795 // if (nodeProposals == null) {
1783 // nodeProposals = <LinkedPositionProposal>[]; 1796 // nodeProposals = <LinkedPositionProposal>[];
1784 // linkedPositionProposals[group] = nodeProposals; 1797 // linkedPositionProposals[group] = nodeProposals;
1785 // } 1798 // }
1786 // nodeProposals.add(proposal); 1799 // nodeProposals.add(proposal);
1787 // } 1800 // }
1788 1801
1789 // /** 1802 // /**
1790 // * Returns `true` if the given [ClassMember] is a part of a static method or 1803 // * Returns `true` if the given [ClassMember] is a part of a static method or
1791 // * a field initializer. 1804 // * a field initializer.
1792 // */ 1805 // */
1793 // bool _inStaticMemberContext2(ClassMember member) { 1806 // bool _inStaticMemberContext2(ClassMember member) {
1794 // if (member is MethodDeclaration) { 1807 // if (member is MethodDeclaration) {
1795 // return member.isStatic; 1808 // return member.isStatic;
1796 // } 1809 // }
1797 // // field initializer cannot reference "this" 1810 // // field initializer cannot reference "this"
1798 // if (member is FieldDeclaration) { 1811 // if (member is FieldDeclaration) {
1799 // return true; 1812 // return true;
1800 // } 1813 // }
1801 // return false; 1814 // return false;
1802 // } 1815 // }
1803 1816
1804 /**
1805 * Inserts the given [SourceBuilder] at its offset.
1806 */
1807 void _insertBuilder(SourceBuilder builder) {
1808 String text = builder.toString();
1809 _addInsertEdit(builder.offset, text);
1810 // add linked positions
1811 builder.linkedPositionGroups.forEach((LinkedPositionGroup group) {
1812 LinkedPositionGroup fixGroup = _getLinkedPosition(group.id);
1813 group.positions.forEach((Position position) {
1814 fixGroup.addPosition(position);
1815 });
1816 group.proposals.forEach((String proposal) {
1817 fixGroup.addProposal(proposal);
1818 });
1819 });
1820 }
1821
1822 _ConstructorLocation 1817 _ConstructorLocation
1823 _prepareNewConstructorLocation(ClassDeclaration classDeclaration) { 1818 _prepareNewConstructorLocation(ClassDeclaration classDeclaration) {
1824 List<ClassMember> members = classDeclaration.members; 1819 List<ClassMember> members = classDeclaration.members;
1825 // find the last field/constructor 1820 // find the last field/constructor
1826 ClassMember lastFieldOrConstructor = null; 1821 ClassMember lastFieldOrConstructor = null;
1827 for (ClassMember member in members) { 1822 for (ClassMember member in members) {
1828 if (member is FieldDeclaration || member is ConstructorDeclaration) { 1823 if (member is FieldDeclaration || member is ConstructorDeclaration) {
1829 lastFieldOrConstructor = member; 1824 lastFieldOrConstructor = member;
1830 } else { 1825 } else {
1831 break; 1826 break;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 ClassElement element = type.element as ClassElement; 1876 ClassElement element = type.element as ClassElement;
1882 sb.addProposal(element.name); 1877 sb.addProposal(element.name);
1883 _addSuperTypeProposals(sb, alreadyAdded, element.supertype); 1878 _addSuperTypeProposals(sb, alreadyAdded, element.supertype);
1884 for (InterfaceType interfaceType in element.interfaces) { 1879 for (InterfaceType interfaceType in element.interfaces) {
1885 _addSuperTypeProposals(sb, alreadyAdded, interfaceType); 1880 _addSuperTypeProposals(sb, alreadyAdded, interfaceType);
1886 } 1881 }
1887 } 1882 }
1888 } 1883 }
1889 1884
1890 /** 1885 /**
1886 * Attempts to convert the given absolute path into a "package" URI.
1887 *
1888 * [context] - the [AnalysisContext] to work in.
1889 * [path] - the absolute path, not `null`.
1890 *
1891 * Returns the "package" URI, may be `null`.
1892 */
1893 static String _findPackageUri(AnalysisContext context, String path) {
1894 // Source fileSource = new FileBasedSource.con1(path);
1895 Source fileSource = new NonExistingSource(path, UriKind.FILE_URI);
1896 Uri uri = context.sourceFactory.restoreUri(fileSource);
1897 if (uri == null) {
1898 return null;
1899 }
1900 return uri.toString();
1901 }
1902
1903 /**
1891 * @return the suggestions for given [Type] and [DartExpression], not empty. 1904 * @return the suggestions for given [Type] and [DartExpression], not empty.
1892 */ 1905 */
1893 static List<String> _getArgumentNameSuggestions(Set<String> excluded, 1906 static List<String> _getArgumentNameSuggestions(Set<String> excluded,
1894 DartType type, Expression expression, int index) { 1907 DartType type, Expression expression, int index) {
1895 List<String> suggestions = 1908 List<String> suggestions =
1896 getVariableNameSuggestionsForExpression(type, expression, excluded); 1909 getVariableNameSuggestionsForExpression(type, expression, excluded);
1897 if (suggestions.length != 0) { 1910 if (suggestions.length != 0) {
1898 return suggestions; 1911 return suggestions;
1899 } 1912 }
1900 return <String>["arg${index}"]; 1913 return <String>["arg${index}"];
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 /** 1965 /**
1953 * Describes the location for a newly created [ConstructorDeclaration]. 1966 * Describes the location for a newly created [ConstructorDeclaration].
1954 */ 1967 */
1955 class _ConstructorLocation { 1968 class _ConstructorLocation {
1956 final String _prefix; 1969 final String _prefix;
1957 final int _offset; 1970 final int _offset;
1958 final String _suffix; 1971 final String _suffix;
1959 1972
1960 _ConstructorLocation(this._prefix, this._offset, this._suffix); 1973 _ConstructorLocation(this._prefix, this._offset, this._suffix);
1961 } 1974 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698