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 services.completion.suggestion.builder.local; | 5 library services.completion.suggestion.builder.local; |
6 | 6 |
7 import 'package:analysis_server/src/protocol.dart' as protocol | 7 import 'package:analysis_server/src/protocol.dart' as protocol |
8 show Element, ElementKind; | 8 show Element, ElementKind; |
9 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 9 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; | 10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; |
11 import 'package:analyzer/src/generated/ast.dart'; | 11 import 'package:analyzer/src/generated/ast.dart'; |
12 import 'package:analyzer/src/generated/scanner.dart'; | 12 import 'package:analyzer/src/generated/scanner.dart'; |
13 | 13 |
14 const DYNAMIC = 'dynamic'; | 14 const DYNAMIC = 'dynamic'; |
15 | 15 |
16 final TypeName NO_RETURN_TYPE = new TypeName( | 16 final TypeName NO_RETURN_TYPE = new TypeName( |
17 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); | 17 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); |
18 | 18 |
19 /** | 19 /** |
20 * Create a new protocol Element for inclusion in a completion suggestion. | 20 * Create a new protocol Element for inclusion in a completion suggestion. |
21 */ | 21 */ |
22 protocol.Element createElement(protocol.ElementKind kind, SimpleIdentifier id, | 22 protocol.Element createElement(protocol.ElementKind kind, SimpleIdentifier id, |
23 {String parameters, TypeName returnType, bool isAbstract: false, | 23 {String parameters, TypeName returnType, SimpleIdentifier enumName, |
24 bool isDeprecated: false}) { | 24 bool isAbstract: false, bool isDeprecated: false}) { |
25 String name = id != null ? id.name : ''; | 25 String name = id != null ? id.name : ''; |
26 int flags = protocol.Element.makeFlags( | 26 int flags = protocol.Element.makeFlags( |
27 isAbstract: isAbstract, | 27 isAbstract: isAbstract, |
28 isDeprecated: isDeprecated, | 28 isDeprecated: isDeprecated, |
29 isPrivate: Identifier.isPrivateName(name)); | 29 isPrivate: Identifier.isPrivateName(name)); |
30 String typeName = enumName != null ? enumName.name : nameForType(returnType); | |
Paul Berry
2015/05/29 17:55:57
It's not clear to me why this is necessary. Won't
danrubel
2015/06/01 04:26:56
Oops. That's left over from an earlier refactoring
| |
30 return new protocol.Element(kind, name, flags, | 31 return new protocol.Element(kind, name, flags, |
31 parameters: parameters, returnType: nameForType(returnType)); | 32 parameters: parameters, returnType: typeName); |
32 } | 33 } |
33 | 34 |
34 /** | 35 /** |
35 * Create a new suggestion for the given field. | 36 * Create a new suggestion for the given field. |
36 * Return the new suggestion or `null` if it could not be created. | 37 * Return the new suggestion or `null` if it could not be created. |
37 */ | 38 */ |
38 CompletionSuggestion createFieldSuggestion( | 39 CompletionSuggestion createFieldSuggestion( |
39 FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 40 FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
40 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl); | 41 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl); |
41 TypeName type = fieldDecl.fields.type; | 42 TypeName type = fieldDecl.fields.type; |
42 return createSuggestion( | 43 return createSuggestion( |
43 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type, | 44 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type, |
44 classDecl: fieldDecl.parent, | 45 classDecl: fieldDecl.parent, |
45 element: createElement(protocol.ElementKind.FIELD, varDecl.name, | 46 element: createElement(protocol.ElementKind.FIELD, varDecl.name, |
46 returnType: type, isDeprecated: deprecated)); | 47 returnType: type, isDeprecated: deprecated)); |
47 } | 48 } |
48 | 49 |
49 /** | 50 /** |
50 * Create a new suggestion based upon the given information. | 51 * Create a new suggestion based upon the given information. |
51 * Return the new suggestion or `null` if it could not be created. | 52 * Return the new suggestion or `null` if it could not be created. |
52 */ | 53 */ |
53 CompletionSuggestion createSuggestion(SimpleIdentifier id, bool isDeprecated, | 54 CompletionSuggestion createSuggestion(SimpleIdentifier id, bool isDeprecated, |
54 int defaultRelevance, TypeName returnType, | 55 int defaultRelevance, TypeName returnType, {ClassDeclaration classDecl, |
55 {ClassDeclaration classDecl, protocol.Element element}) { | 56 SimpleIdentifier enumName, protocol.Element element}) { |
56 if (id == null) { | 57 if (id == null) { |
57 return null; | 58 return null; |
58 } | 59 } |
59 String completion = id.name; | 60 String completion = id.name; |
60 if (completion == null || completion.length <= 0 || completion == '_') { | 61 if (completion == null || completion.length <= 0 || completion == '_') { |
61 return null; | 62 return null; |
62 } | 63 } |
63 CompletionSuggestion suggestion = new CompletionSuggestion( | 64 CompletionSuggestion suggestion = new CompletionSuggestion( |
64 CompletionSuggestionKind.INVOCATION, | 65 CompletionSuggestionKind.INVOCATION, |
65 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, | 66 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, |
66 completion.length, 0, isDeprecated, false, | 67 completion.length, 0, isDeprecated, false, |
67 returnType: nameForType(returnType), element: element); | 68 returnType: enumName != null ? enumName.name : nameForType(returnType), |
Paul Berry
2015/05/29 17:55:57
Same question here.
danrubel
2015/06/01 04:26:56
As above, old unused code. Removed.
| |
69 element: element); | |
68 if (classDecl != null) { | 70 if (classDecl != null) { |
69 SimpleIdentifier classId = classDecl.name; | 71 SimpleIdentifier classId = classDecl.name; |
70 if (classId != null) { | 72 if (classId != null) { |
71 String className = classId.name; | 73 String className = classId.name; |
72 if (className != null && className.length > 0) { | 74 if (className != null && className.length > 0) { |
73 suggestion.declaringType = className; | 75 suggestion.declaringType = className; |
74 } | 76 } |
75 } | 77 } |
76 } | 78 } |
77 return suggestion; | 79 return suggestion; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 String name = id.name; | 111 String name = id.name; |
110 if (name == null || name.length <= 0) { | 112 if (name == null || name.length <= 0) { |
111 return DYNAMIC; | 113 return DYNAMIC; |
112 } | 114 } |
113 TypeArgumentList typeArgs = type.typeArguments; | 115 TypeArgumentList typeArgs = type.typeArguments; |
114 if (typeArgs != null) { | 116 if (typeArgs != null) { |
115 //TODO (danrubel) include type arguments | 117 //TODO (danrubel) include type arguments |
116 } | 118 } |
117 return name; | 119 return name; |
118 } | 120 } |
OLD | NEW |