| 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 import 'package:analyzer/src/generated/source.dart'; |
| 14 | 14 |
| 15 const DYNAMIC = 'dynamic'; | 15 const DYNAMIC = 'dynamic'; |
| 16 | 16 |
| 17 final TypeName NO_RETURN_TYPE = new TypeName( | 17 final TypeName NO_RETURN_TYPE = new TypeName( |
| 18 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); | 18 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Create a new protocol Element for inclusion in a completion suggestion. | 21 * Create a new protocol Element for inclusion in a completion suggestion. |
| 22 */ | 22 */ |
| 23 protocol.Element createElement( | 23 protocol.Element createElement( |
| 24 Source source, protocol.ElementKind kind, SimpleIdentifier id, | 24 Source source, protocol.ElementKind kind, SimpleIdentifier id, |
| 25 {String parameters, TypeName returnType, bool isAbstract: false, | 25 {String parameters, |
| 26 TypeName returnType, |
| 27 bool isAbstract: false, |
| 26 bool isDeprecated: false}) { | 28 bool isDeprecated: false}) { |
| 27 String name; | 29 String name; |
| 28 Location location; | 30 Location location; |
| 29 if (id != null) { | 31 if (id != null) { |
| 30 name = id.name; | 32 name = id.name; |
| 31 // TODO(danrubel) use lineInfo to determine startLine and startColumn | 33 // TODO(danrubel) use lineInfo to determine startLine and startColumn |
| 32 location = new Location(source.fullName, id.offset, id.length, 0, 0); | 34 location = new Location(source.fullName, id.offset, id.length, 0, 0); |
| 33 } else { | 35 } else { |
| 34 name = ''; | 36 name = ''; |
| 35 location = new Location(source.fullName, -1, 0, 1, 0); | 37 location = new Location(source.fullName, -1, 0, 1, 0); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 {ClassDeclaration classDecl, protocol.Element element}) { | 70 {ClassDeclaration classDecl, protocol.Element element}) { |
| 69 if (id == null) { | 71 if (id == null) { |
| 70 return null; | 72 return null; |
| 71 } | 73 } |
| 72 String completion = id.name; | 74 String completion = id.name; |
| 73 if (completion == null || completion.length <= 0 || completion == '_') { | 75 if (completion == null || completion.length <= 0 || completion == '_') { |
| 74 return null; | 76 return null; |
| 75 } | 77 } |
| 76 CompletionSuggestion suggestion = new CompletionSuggestion( | 78 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 77 CompletionSuggestionKind.INVOCATION, | 79 CompletionSuggestionKind.INVOCATION, |
| 78 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, | 80 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, |
| 79 completion.length, 0, isDeprecated, false, | 81 completion, |
| 80 returnType: nameForType(returnType), element: element); | 82 completion.length, |
| 83 0, |
| 84 isDeprecated, |
| 85 false, |
| 86 returnType: nameForType(returnType), |
| 87 element: element); |
| 81 if (classDecl != null) { | 88 if (classDecl != null) { |
| 82 SimpleIdentifier classId = classDecl.name; | 89 SimpleIdentifier classId = classDecl.name; |
| 83 if (classId != null) { | 90 if (classId != null) { |
| 84 String className = classId.name; | 91 String className = classId.name; |
| 85 if (className != null && className.length > 0) { | 92 if (className != null && className.length > 0) { |
| 86 suggestion.declaringType = className; | 93 suggestion.declaringType = className; |
| 87 } | 94 } |
| 88 } | 95 } |
| 89 } | 96 } |
| 90 return suggestion; | 97 return suggestion; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 String name = id.name; | 129 String name = id.name; |
| 123 if (name == null || name.length <= 0) { | 130 if (name == null || name.length <= 0) { |
| 124 return DYNAMIC; | 131 return DYNAMIC; |
| 125 } | 132 } |
| 126 TypeArgumentList typeArgs = type.typeArguments; | 133 TypeArgumentList typeArgs = type.typeArguments; |
| 127 if (typeArgs != null) { | 134 if (typeArgs != null) { |
| 128 //TODO (danrubel) include type arguments | 135 //TODO (danrubel) include type arguments |
| 129 } | 136 } |
| 130 return name; | 137 return name; |
| 131 } | 138 } |
| OLD | NEW |