| 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.computer.dart.local; | 5 library services.completion.computer.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, | 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 final bool excludeVoidReturn; | 67 final bool excludeVoidReturn; |
| 68 | 68 |
| 69 _LocalVisitor(this.request, int offset, this.typesOnly, | 69 _LocalVisitor(this.request, int offset, this.typesOnly, |
| 70 this.excludeVoidReturn) | 70 this.excludeVoidReturn) |
| 71 : super(offset); | 71 : super(offset); |
| 72 | 72 |
| 73 @override | 73 @override |
| 74 void declaredClass(ClassDeclaration declaration) { | 74 void declaredClass(ClassDeclaration declaration) { |
| 75 bool isDeprecated = _isDeprecated(declaration); | 75 bool isDeprecated = _isDeprecated(declaration); |
| 76 CompletionSuggestion suggestion = | 76 CompletionSuggestion suggestion = |
| 77 _addSuggestion(declaration.name, null, null, isDeprecated); | 77 _addSuggestion(declaration.name, NO_RETURN_TYPE, null, isDeprecated); |
| 78 if (suggestion != null) { | 78 if (suggestion != null) { |
| 79 suggestion.element = _createElement( | 79 suggestion.element = _createElement( |
| 80 protocol.ElementKind.CLASS, | 80 protocol.ElementKind.CLASS, |
| 81 declaration.name, | 81 declaration.name, |
| 82 null, | 82 null, |
| 83 _LocalVisitor.NO_RETURN_TYPE, | 83 NO_RETURN_TYPE, |
| 84 declaration.isAbstract, | 84 declaration.isAbstract, |
| 85 isDeprecated); | 85 isDeprecated); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 @override | 89 @override |
| 90 void declaredClassTypeAlias(ClassTypeAlias declaration) { | 90 void declaredClassTypeAlias(ClassTypeAlias declaration) { |
| 91 bool isDeprecated = _isDeprecated(declaration); | 91 bool isDeprecated = _isDeprecated(declaration); |
| 92 CompletionSuggestion suggestion = | 92 CompletionSuggestion suggestion = |
| 93 _addSuggestion(declaration.name, null, null, isDeprecated); | 93 _addSuggestion(declaration.name, NO_RETURN_TYPE, null, isDeprecated); |
| 94 if (suggestion != null) { | 94 if (suggestion != null) { |
| 95 suggestion.element = _createElement( | 95 suggestion.element = _createElement( |
| 96 protocol.ElementKind.CLASS_TYPE_ALIAS, | 96 protocol.ElementKind.CLASS_TYPE_ALIAS, |
| 97 declaration.name, | 97 declaration.name, |
| 98 null, | 98 null, |
| 99 NO_RETURN_TYPE, | 99 NO_RETURN_TYPE, |
| 100 true, | 100 true, |
| 101 isDeprecated); | 101 isDeprecated); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 @override | 105 @override |
| 106 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 106 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
| 107 if (typesOnly) { | 107 if (typesOnly) { |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); | 110 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); |
| 111 TypeName type = fieldDecl.fields.type; |
| 111 CompletionSuggestion suggestion = | 112 CompletionSuggestion suggestion = |
| 112 _addSuggestion(varDecl.name, null, fieldDecl.parent, isDeprecated); | 113 _addSuggestion(varDecl.name, type, fieldDecl.parent, isDeprecated); |
| 113 if (suggestion != null) { | 114 if (suggestion != null) { |
| 114 suggestion.element = _createElement( | 115 suggestion.element = _createElement( |
| 115 protocol.ElementKind.FIELD, | 116 protocol.ElementKind.FIELD, |
| 116 varDecl.name, | 117 varDecl.name, |
| 117 null, | 118 null, |
| 118 null, | 119 type, |
| 119 false, | 120 false, |
| 120 isDeprecated); | 121 isDeprecated); |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 @override | 125 @override |
| 125 void declaredFunction(FunctionDeclaration declaration) { | 126 void declaredFunction(FunctionDeclaration declaration) { |
| 126 if (typesOnly) { | 127 if (typesOnly) { |
| 127 return; | 128 return; |
| 128 } | 129 } |
| 129 if (excludeVoidReturn && _isVoid(declaration.returnType)) { | 130 TypeName returnType = declaration.returnType; |
| 130 return; | 131 bool isDeprecated = _isDeprecated(declaration); |
| 132 protocol.ElementKind kind; |
| 133 if (declaration.isGetter) { |
| 134 kind = protocol.ElementKind.GETTER; |
| 135 } else if (declaration.isSetter) { |
| 136 if (excludeVoidReturn) { |
| 137 return; |
| 138 } |
| 139 kind = protocol.ElementKind.SETTER; |
| 140 returnType = NO_RETURN_TYPE; |
| 141 } else { |
| 142 if (excludeVoidReturn && _isVoid(returnType)) { |
| 143 return; |
| 144 } |
| 145 kind = protocol.ElementKind.FUNCTION; |
| 131 } | 146 } |
| 132 bool isDeprecated = _isDeprecated(declaration); | |
| 133 CompletionSuggestion suggestion = | 147 CompletionSuggestion suggestion = |
| 134 _addSuggestion(declaration.name, declaration.returnType, null, isDepreca
ted); | 148 _addSuggestion(declaration.name, returnType, null, isDeprecated); |
| 135 if (suggestion != null) { | 149 if (suggestion != null) { |
| 136 FormalParameterList param = declaration.functionExpression.parameters; | 150 FormalParameterList param = declaration.functionExpression.parameters; |
| 137 protocol.ElementKind kind; | |
| 138 if (declaration.isGetter) { | |
| 139 kind = protocol.ElementKind.GETTER; | |
| 140 } else if (declaration.isSetter) { | |
| 141 kind = protocol.ElementKind.SETTER; | |
| 142 } else { | |
| 143 kind = protocol.ElementKind.FUNCTION; | |
| 144 } | |
| 145 suggestion.element = _createElement( | 151 suggestion.element = _createElement( |
| 146 kind, | 152 kind, |
| 147 declaration.name, | 153 declaration.name, |
| 148 param != null ? param.toSource() : null, | 154 param != null ? param.toSource() : null, |
| 149 declaration.returnType, | 155 returnType, |
| 150 false, | 156 false, |
| 151 isDeprecated); | 157 isDeprecated); |
| 152 } | 158 } |
| 153 } | 159 } |
| 154 | 160 |
| 155 @override | 161 @override |
| 156 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | 162 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { |
| 157 bool isDeprecated = _isDeprecated(declaration); | 163 bool isDeprecated = _isDeprecated(declaration); |
| 164 TypeName returnType = declaration.returnType; |
| 158 CompletionSuggestion suggestion = | 165 CompletionSuggestion suggestion = |
| 159 _addSuggestion(declaration.name, declaration.returnType, null, isDepreca
ted); | 166 _addSuggestion(declaration.name, returnType, null, isDeprecated); |
| 160 if (suggestion != null) { | 167 if (suggestion != null) { |
| 161 // TODO (danrubel) determine parameters and return type | 168 // TODO (danrubel) determine parameters and return type |
| 162 suggestion.element = _createElement( | 169 suggestion.element = _createElement( |
| 163 protocol.ElementKind.FUNCTION_TYPE_ALIAS, | 170 protocol.ElementKind.FUNCTION_TYPE_ALIAS, |
| 164 declaration.name, | 171 declaration.name, |
| 165 null, | 172 null, |
| 166 NO_RETURN_TYPE, | 173 returnType, |
| 167 true, | 174 true, |
| 168 isDeprecated); | 175 isDeprecated); |
| 169 } | 176 } |
| 170 } | 177 } |
| 171 | 178 |
| 172 @override | 179 @override |
| 173 void declaredLabel(Label label) { | 180 void declaredLabel(Label label) { |
| 174 // ignored | 181 // ignored |
| 175 } | 182 } |
| 176 | 183 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 200 String parameters; | 207 String parameters; |
| 201 TypeName returnType = declaration.returnType; | 208 TypeName returnType = declaration.returnType; |
| 202 if (declaration.isGetter) { | 209 if (declaration.isGetter) { |
| 203 kind = protocol.ElementKind.GETTER; | 210 kind = protocol.ElementKind.GETTER; |
| 204 parameters = null; | 211 parameters = null; |
| 205 } else if (declaration.isSetter) { | 212 } else if (declaration.isSetter) { |
| 206 if (excludeVoidReturn) { | 213 if (excludeVoidReturn) { |
| 207 return; | 214 return; |
| 208 } | 215 } |
| 209 kind = protocol.ElementKind.SETTER; | 216 kind = protocol.ElementKind.SETTER; |
| 210 returnType = null; | 217 returnType = NO_RETURN_TYPE; |
| 211 } else { | 218 } else { |
| 212 if (excludeVoidReturn && _isVoid(returnType)) { | 219 if (excludeVoidReturn && _isVoid(returnType)) { |
| 213 return; | 220 return; |
| 214 } | 221 } |
| 215 kind = protocol.ElementKind.METHOD; | 222 kind = protocol.ElementKind.METHOD; |
| 216 parameters = declaration.parameters.toSource(); | 223 parameters = declaration.parameters.toSource(); |
| 217 } | 224 } |
| 218 bool isDeprecated = _isDeprecated(declaration); | 225 bool isDeprecated = _isDeprecated(declaration); |
| 219 CompletionSuggestion suggestion = | 226 CompletionSuggestion suggestion = |
| 220 _addSuggestion(declaration.name, returnType, declaration.parent, isDepre
cated); | 227 _addSuggestion(declaration.name, returnType, declaration.parent, isDepre
cated); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 if (id != null) { | 273 if (id != null) { |
| 267 String completion = id.name; | 274 String completion = id.name; |
| 268 if (completion != null && completion.length > 0 && completion != '_') { | 275 if (completion != null && completion.length > 0 && completion != '_') { |
| 269 CompletionSuggestion suggestion = new CompletionSuggestion( | 276 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 270 CompletionSuggestionKind.INVOCATION, | 277 CompletionSuggestionKind.INVOCATION, |
| 271 isDeprecated ? COMPLETION_RELEVANCE_LOW : COMPLETION_RELEVANCE_DEFAU
LT, | 278 isDeprecated ? COMPLETION_RELEVANCE_LOW : COMPLETION_RELEVANCE_DEFAU
LT, |
| 272 completion, | 279 completion, |
| 273 completion.length, | 280 completion.length, |
| 274 0, | 281 0, |
| 275 false, | 282 false, |
| 276 false); | 283 false, |
| 284 returnType: _nameForType(returnType)); |
| 277 if (classDecl != null) { | 285 if (classDecl != null) { |
| 278 SimpleIdentifier identifier = classDecl.name; | 286 SimpleIdentifier identifier = classDecl.name; |
| 279 if (identifier != null) { | 287 if (identifier != null) { |
| 280 String name = identifier.name; | 288 String name = identifier.name; |
| 281 if (name != null && name.length > 0) { | 289 if (name != null && name.length > 0) { |
| 282 suggestion.declaringType = name; | 290 suggestion.declaringType = name; |
| 283 } | 291 } |
| 284 } | 292 } |
| 285 } | 293 } |
| 286 if (returnType != null) { | |
| 287 Identifier identifier = returnType.name; | |
| 288 if (identifier != null) { | |
| 289 String name = identifier.name; | |
| 290 if (name != null && name.length > 0) { | |
| 291 suggestion.returnType = name; | |
| 292 } | |
| 293 } | |
| 294 } | |
| 295 request.suggestions.add(suggestion); | 294 request.suggestions.add(suggestion); |
| 296 return suggestion; | 295 return suggestion; |
| 297 } | 296 } |
| 298 } | 297 } |
| 299 return null; | 298 return null; |
| 300 } | 299 } |
| 301 | 300 |
| 302 | 301 |
| 303 /** | 302 /** |
| 304 * Create a new protocol Element for inclusion in a completion suggestion. | 303 * Create a new protocol Element for inclusion in a completion suggestion. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (name == null || name.length <= 0) { | 361 if (name == null || name.length <= 0) { |
| 363 return DYNAMIC; | 362 return DYNAMIC; |
| 364 } | 363 } |
| 365 TypeArgumentList typeArgs = type.typeArguments; | 364 TypeArgumentList typeArgs = type.typeArguments; |
| 366 if (typeArgs != null) { | 365 if (typeArgs != null) { |
| 367 //TODO (danrubel) include type arguments | 366 //TODO (danrubel) include type arguments |
| 368 } | 367 } |
| 369 return name; | 368 return name; |
| 370 } | 369 } |
| 371 } | 370 } |
| OLD | NEW |