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

Side by Side Diff: pkg/analysis_server/lib/src/provisional/completion/dart/completion_target.dart

Issue 1528633002: move LocalReferenceContributor to new API (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: make local functions private' Created 5 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analysis_server.src.provisional.completion.dart.completion_target; 5 library analysis_server.src.provisional.completion.dart.completion_target;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/scanner.dart'; 9 import 'package:analyzer/src/generated/scanner.dart';
10 import 'package:analyzer/src/generated/utilities_dart.dart'; 10 import 'package:analyzer/src/generated/utilities_dart.dart';
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return node.isCascaded && offset > node.operator.offset + 1; 259 return node.isCascaded && offset > node.operator.offset + 1;
260 } 260 }
261 return false; 261 return false;
262 } 262 }
263 263
264 /** 264 /**
265 * Return `true` if the target is a functional argument in an argument list. 265 * Return `true` if the target is a functional argument in an argument list.
266 * The target [AstNode] hierarchy *must* be resolved for this to work. 266 * The target [AstNode] hierarchy *must* be resolved for this to work.
267 */ 267 */
268 bool isFunctionalArgument() { 268 bool isFunctionalArgument() {
269 if (argIndex == null) { 269 if (!maybeFunctionalArgument()) {
270 return false; 270 return false;
271 } 271 }
272 AstNode argList = containingNode; 272 AstNode parent = containingNode.parent;
273 if (argList is! ArgumentList) {
274 return false;
275 }
276 AstNode parent = argList.parent;
277 if (parent is InstanceCreationExpression) { 273 if (parent is InstanceCreationExpression) {
278 DartType instType = parent.bestType; 274 DartType instType = parent.bestType;
279 if (instType != null) { 275 if (instType != null) {
280 Element intTypeElem = instType.element; 276 Element intTypeElem = instType.element;
281 if (intTypeElem is ClassElement) { 277 if (intTypeElem is ClassElement) {
282 SimpleIdentifier constructorName = parent.constructorName.name; 278 SimpleIdentifier constructorName = parent.constructorName.name;
283 ConstructorElement constructor = constructorName != null 279 ConstructorElement constructor = constructorName != null
284 ? intTypeElem.getNamedConstructor(constructorName.name) 280 ? intTypeElem.getNamedConstructor(constructorName.name)
285 : intTypeElem.unnamedConstructor; 281 : intTypeElem.unnamedConstructor;
286 return constructor != null && 282 return constructor != null &&
287 _isFunctionalParameter(constructor.parameters, argIndex); 283 _isFunctionalParameter(constructor.parameters, argIndex);
288 } 284 }
289 } 285 }
290 } else if (parent is MethodInvocation) { 286 } else if (parent is MethodInvocation) {
291 SimpleIdentifier methodName = parent.methodName; 287 SimpleIdentifier methodName = parent.methodName;
292 if (methodName != null) { 288 if (methodName != null) {
293 Element methodElem = methodName.bestElement; 289 Element methodElem = methodName.bestElement;
294 if (methodElem is MethodElement) { 290 if (methodElem is MethodElement) {
295 return _isFunctionalParameter(methodElem.parameters, argIndex); 291 return _isFunctionalParameter(methodElem.parameters, argIndex);
296 } else if (methodElem is FunctionElement) { 292 } else if (methodElem is FunctionElement) {
297 return _isFunctionalParameter(methodElem.parameters, argIndex); 293 return _isFunctionalParameter(methodElem.parameters, argIndex);
298 } 294 }
299 } 295 }
300 } 296 }
301 return false; 297 return false;
302 } 298 }
303 299
304 /** 300 /**
301 * Return `true` if the target is a functional argument in an argument list.
302 * The target [AstNode] hierarchy *must* be resolved for this to work.
303 */
304 bool maybeFunctionalArgument() {
305 if (argIndex == null) {
306 return false;
307 }
308 AstNode argList = containingNode;
309 if (argList is! ArgumentList) {
310 return false;
311 }
312 return true;
313 }
314
315 /**
305 * Determine if the offset is contained in a preceding comment token 316 * Determine if the offset is contained in a preceding comment token
306 * and return that token, otherwise return `null`. 317 * and return that token, otherwise return `null`.
307 */ 318 */
308 static Token _getContainingCommentToken(Token token, int offset) { 319 static Token _getContainingCommentToken(Token token, int offset) {
309 if (token == null) { 320 if (token == null) {
310 return null; 321 return null;
311 } 322 }
312 if (offset >= token.offset) { 323 if (offset >= token.offset) {
313 return null; 324 return null;
314 } 325 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (param.parameterKind == ParameterKind.NAMED) { 413 if (param.parameterKind == ParameterKind.NAMED) {
403 // TODO(danrubel) handle named parameters 414 // TODO(danrubel) handle named parameters
404 return false; 415 return false;
405 } else { 416 } else {
406 return paramType is FunctionType || paramType is FunctionTypeAlias; 417 return paramType is FunctionType || paramType is FunctionTypeAlias;
407 } 418 }
408 } 419 }
409 return false; 420 return false;
410 } 421 }
411 } 422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698