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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart/utilities.dart

Issue 2622303006: Reapply "Add support for generic function type syntax, part 1" (Closed)
Patch Set: Created 3 years, 11 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 /** 5 /**
6 * A collection of utility methods used by completion contributors. 6 * A collection of utility methods used by completion contributors.
7 */ 7 */
8 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol 8 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol
9 show Element, ElementKind; 9 show Element, ElementKind;
10 import 'package:analysis_server/src/protocol_server.dart' 10 import 'package:analysis_server/src/protocol_server.dart'
(...skipping 16 matching lines...) Expand all
27 final TypeName NO_RETURN_TYPE = astFactory.typeName( 27 final TypeName NO_RETURN_TYPE = astFactory.typeName(
28 astFactory.simpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), 28 astFactory.simpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)),
29 null); 29 null);
30 30
31 /** 31 /**
32 * Create a new protocol Element for inclusion in a completion suggestion. 32 * Create a new protocol Element for inclusion in a completion suggestion.
33 */ 33 */
34 protocol.Element createLocalElement( 34 protocol.Element createLocalElement(
35 Source source, protocol.ElementKind kind, SimpleIdentifier id, 35 Source source, protocol.ElementKind kind, SimpleIdentifier id,
36 {String parameters, 36 {String parameters,
37 TypeName returnType, 37 TypeAnnotation returnType,
38 bool isAbstract: false, 38 bool isAbstract: false,
39 bool isDeprecated: false}) { 39 bool isDeprecated: false}) {
40 String name; 40 String name;
41 Location location; 41 Location location;
42 if (id != null) { 42 if (id != null) {
43 name = id.name; 43 name = id.name;
44 // TODO(danrubel) use lineInfo to determine startLine and startColumn 44 // TODO(danrubel) use lineInfo to determine startLine and startColumn
45 location = new Location(source.fullName, id.offset, id.length, 0, 0); 45 location = new Location(source.fullName, id.offset, id.length, 0, 0);
46 } else { 46 } else {
47 name = ''; 47 name = '';
48 location = new Location(source.fullName, -1, 0, 1, 0); 48 location = new Location(source.fullName, -1, 0, 1, 0);
49 } 49 }
50 int flags = protocol.Element.makeFlags( 50 int flags = protocol.Element.makeFlags(
51 isAbstract: isAbstract, 51 isAbstract: isAbstract,
52 isDeprecated: isDeprecated, 52 isDeprecated: isDeprecated,
53 isPrivate: Identifier.isPrivateName(name)); 53 isPrivate: Identifier.isPrivateName(name));
54 return new protocol.Element(kind, name, flags, 54 return new protocol.Element(kind, name, flags,
55 location: location, 55 location: location,
56 parameters: parameters, 56 parameters: parameters,
57 returnType: nameForType(returnType)); 57 returnType: nameForType(returnType));
58 } 58 }
59 59
60 /** 60 /**
61 * Create a new suggestion for the given [fieldDecl]. Return the new suggestion 61 * Create a new suggestion for the given [fieldDecl]. Return the new suggestion
62 * or `null` if it could not be created. 62 * or `null` if it could not be created.
63 */ 63 */
64 CompletionSuggestion createLocalFieldSuggestion( 64 CompletionSuggestion createLocalFieldSuggestion(
65 Source source, FieldDeclaration fieldDecl, VariableDeclaration varDecl) { 65 Source source, FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
66 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl); 66 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl);
67 TypeName type = fieldDecl.fields.type; 67 TypeAnnotation type = fieldDecl.fields.type;
68 return createLocalSuggestion( 68 return createLocalSuggestion(
69 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type, 69 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type,
70 classDecl: fieldDecl.parent, 70 classDecl: fieldDecl.parent,
71 element: createLocalElement( 71 element: createLocalElement(
72 source, protocol.ElementKind.FIELD, varDecl.name, 72 source, protocol.ElementKind.FIELD, varDecl.name,
73 returnType: type, isDeprecated: deprecated)); 73 returnType: type, isDeprecated: deprecated));
74 } 74 }
75 75
76 /** 76 /**
77 * Create a new suggestion based upon the given information. Return the new 77 * Create a new suggestion based upon the given information. Return the new
78 * suggestion or `null` if it could not be created. 78 * suggestion or `null` if it could not be created.
79 */ 79 */
80 CompletionSuggestion createLocalSuggestion(SimpleIdentifier id, 80 CompletionSuggestion createLocalSuggestion(SimpleIdentifier id,
81 bool isDeprecated, int defaultRelevance, TypeName returnType, 81 bool isDeprecated, int defaultRelevance, TypeAnnotation returnType,
82 {ClassDeclaration classDecl, 82 {ClassDeclaration classDecl,
83 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION, 83 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION,
84 protocol.Element element}) { 84 protocol.Element element}) {
85 if (id == null) { 85 if (id == null) {
86 return null; 86 return null;
87 } 87 }
88 String completion = id.name; 88 String completion = id.name;
89 if (completion == null || completion.length <= 0 || completion == '_') { 89 if (completion == null || completion.length <= 0 || completion == '_') {
90 return null; 90 return null;
91 } 91 }
(...skipping 30 matching lines...) Expand all
122 return a.name is SimpleIdentifier && a.name.name == 'deprecated'; 122 return a.name is SimpleIdentifier && a.name.name == 'deprecated';
123 }); 123 });
124 } 124 }
125 } 125 }
126 return false; 126 return false;
127 } 127 }
128 128
129 /** 129 /**
130 * Return the name for the given [type]. 130 * Return the name for the given [type].
131 */ 131 */
132 String nameForType(TypeName type) { 132 String nameForType(TypeAnnotation type) {
133 if (type == NO_RETURN_TYPE) { 133 if (type == NO_RETURN_TYPE) {
134 return null; 134 return null;
135 } 135 }
136 if (type == null) { 136 if (type == null) {
137 return DYNAMIC; 137 return DYNAMIC;
138 } 138 }
139 Identifier id = type.name; 139 if (type is TypeName) {
140 if (id == null) { 140 Identifier id = type.name;
141 return DYNAMIC; 141 if (id == null) {
142 return DYNAMIC;
143 }
144 String name = id.name;
145 if (name == null || name.length <= 0) {
146 return DYNAMIC;
147 }
148 TypeArgumentList typeArgs = type.typeArguments;
149 if (typeArgs != null) {
150 //TODO (danrubel) include type arguments
151 }
152 return name;
153 } else if (type is GenericFunctionType) {
154 // TODO(brianwilkerson) Implement this.
142 } 155 }
143 String name = id.name; 156 return DYNAMIC;
144 if (name == null || name.length <= 0) {
145 return DYNAMIC;
146 }
147 TypeArgumentList typeArgs = type.typeArguments;
148 if (typeArgs != null) {
149 //TODO (danrubel) include type arguments
150 }
151 return name;
152 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698