| 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 import 'package:analyzer/src/generated/source.dart'; |
| 13 | 14 |
| 14 const DYNAMIC = 'dynamic'; | 15 const DYNAMIC = 'dynamic'; |
| 15 | 16 |
| 16 final TypeName NO_RETURN_TYPE = new TypeName( | 17 final TypeName NO_RETURN_TYPE = new TypeName( |
| 17 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); | 18 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * Create a new protocol Element for inclusion in a completion suggestion. | 21 * Create a new protocol Element for inclusion in a completion suggestion. |
| 21 */ | 22 */ |
| 22 protocol.Element createElement(protocol.ElementKind kind, SimpleIdentifier id, | 23 protocol.Element createElement( |
| 24 Source source, protocol.ElementKind kind, SimpleIdentifier id, |
| 23 {String parameters, TypeName returnType, bool isAbstract: false, | 25 {String parameters, TypeName returnType, bool isAbstract: false, |
| 24 bool isDeprecated: false}) { | 26 bool isDeprecated: false}) { |
| 25 String name = id != null ? id.name : ''; | 27 String name; |
| 28 Location location; |
| 29 if (id != null) { |
| 30 name = id.name; |
| 31 // TODO(danrubel) use lineInfo to determine startLine and startColumn |
| 32 location = new Location(source.fullName, id.offset, id.length, 0, 0); |
| 33 } else { |
| 34 name = ''; |
| 35 location = new Location(source.fullName, -1, 0, 1, 0); |
| 36 } |
| 26 int flags = protocol.Element.makeFlags( | 37 int flags = protocol.Element.makeFlags( |
| 27 isAbstract: isAbstract, | 38 isAbstract: isAbstract, |
| 28 isDeprecated: isDeprecated, | 39 isDeprecated: isDeprecated, |
| 29 isPrivate: Identifier.isPrivateName(name)); | 40 isPrivate: Identifier.isPrivateName(name)); |
| 30 return new protocol.Element(kind, name, flags, | 41 return new protocol.Element(kind, name, flags, |
| 31 parameters: parameters, returnType: nameForType(returnType)); | 42 location: location, |
| 43 parameters: parameters, |
| 44 returnType: nameForType(returnType)); |
| 32 } | 45 } |
| 33 | 46 |
| 34 /** | 47 /** |
| 35 * Create a new suggestion for the given field. | 48 * Create a new suggestion for the given field. |
| 36 * Return the new suggestion or `null` if it could not be created. | 49 * Return the new suggestion or `null` if it could not be created. |
| 37 */ | 50 */ |
| 38 CompletionSuggestion createFieldSuggestion( | 51 CompletionSuggestion createFieldSuggestion( |
| 39 FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 52 Source source, FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
| 40 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl); | 53 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl); |
| 41 TypeName type = fieldDecl.fields.type; | 54 TypeName type = fieldDecl.fields.type; |
| 42 return createSuggestion( | 55 return createSuggestion( |
| 43 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type, | 56 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type, |
| 44 classDecl: fieldDecl.parent, | 57 classDecl: fieldDecl.parent, |
| 45 element: createElement(protocol.ElementKind.FIELD, varDecl.name, | 58 element: createElement(source, protocol.ElementKind.FIELD, varDecl.name, |
| 46 returnType: type, isDeprecated: deprecated)); | 59 returnType: type, isDeprecated: deprecated)); |
| 47 } | 60 } |
| 48 | 61 |
| 49 /** | 62 /** |
| 50 * Create a new suggestion based upon the given information. | 63 * Create a new suggestion based upon the given information. |
| 51 * Return the new suggestion or `null` if it could not be created. | 64 * Return the new suggestion or `null` if it could not be created. |
| 52 */ | 65 */ |
| 53 CompletionSuggestion createSuggestion(SimpleIdentifier id, bool isDeprecated, | 66 CompletionSuggestion createSuggestion(SimpleIdentifier id, bool isDeprecated, |
| 54 int defaultRelevance, TypeName returnType, | 67 int defaultRelevance, TypeName returnType, |
| 55 {ClassDeclaration classDecl, protocol.Element element}) { | 68 {ClassDeclaration classDecl, protocol.Element element}) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 String name = id.name; | 122 String name = id.name; |
| 110 if (name == null || name.length <= 0) { | 123 if (name == null || name.length <= 0) { |
| 111 return DYNAMIC; | 124 return DYNAMIC; |
| 112 } | 125 } |
| 113 TypeArgumentList typeArgs = type.typeArguments; | 126 TypeArgumentList typeArgs = type.typeArguments; |
| 114 if (typeArgs != null) { | 127 if (typeArgs != null) { |
| 115 //TODO (danrubel) include type arguments | 128 //TODO (danrubel) include type arguments |
| 116 } | 129 } |
| 117 return name; | 130 return name; |
| 118 } | 131 } |
| OLD | NEW |