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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/local_suggestion_builder.dart

Issue 1082233003: suggest "this." local fields in constructor param (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library services.completion.suggestion.builder.local;
6
7 import 'package:analysis_server/src/protocol.dart' as protocol
8 show 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';
11 import 'package:analyzer/src/generated/ast.dart';
12 import 'package:analyzer/src/generated/scanner.dart';
13
14 const DYNAMIC = 'dynamic';
15
16 final TypeName NO_RETURN_TYPE = new TypeName(
17 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null);
18
19 /**
20 * Create a new protocol Element for inclusion in a completion suggestion.
21 */
22 protocol.Element createElement(protocol.ElementKind kind, SimpleIdentifier id,
23 {String parameters, TypeName returnType, bool isAbstract: false,
24 bool isDeprecated: false}) {
25 String name = id != null ? id.name : '';
26 int flags = protocol.Element.makeFlags(
27 isAbstract: isAbstract,
28 isDeprecated: isDeprecated,
29 isPrivate: Identifier.isPrivateName(name));
30 return new protocol.Element(kind, name, flags,
31 parameters: parameters, returnType: nameForType(returnType));
32 }
33
34 /**
35 * Create a new suggestion for the given field.
36 * Return the new suggestion or `null` if it could not be created.
37 */
38 CompletionSuggestion createFieldSuggestion(
39 FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
40 bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl);
41 TypeName type = fieldDecl.fields.type;
42 return createSuggestion(
43 varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type,
44 classDecl: fieldDecl.parent,
45 element: createElement(protocol.ElementKind.FIELD, varDecl.name,
46 returnType: type, isDeprecated: deprecated));
47 }
48
49 /**
50 * Create a new suggestion based upon the given information.
51 * Return the new suggestion or `null` if it could not be created.
52 */
53 CompletionSuggestion createSuggestion(SimpleIdentifier id, bool isDeprecated,
54 int defaultRelevance, TypeName returnType,
55 {ClassDeclaration classDecl, protocol.Element element}) {
56 if (id == null) {
57 return null;
58 }
59 String completion = id.name;
60 if (completion == null || completion.length <= 0 || completion == '_') {
61 return null;
62 }
63 CompletionSuggestion suggestion = new CompletionSuggestion(
64 CompletionSuggestionKind.INVOCATION,
65 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion,
66 completion.length, 0, isDeprecated, false,
67 returnType: nameForType(returnType), element: element);
68 if (classDecl != null) {
69 SimpleIdentifier classId = classDecl.name;
70 if (classId != null) {
71 String className = classId.name;
72 if (className != null && className.length > 0) {
73 suggestion.declaringType = className;
74 }
75 }
76 }
77 return suggestion;
78 }
79
80 /**
81 * Return `true` if the @deprecated annotation is present
82 */
83 bool isDeprecated(AnnotatedNode node) {
84 if (node != null) {
85 NodeList<Annotation> metadata = node.metadata;
86 if (metadata != null) {
87 return metadata.any((Annotation a) {
88 return a.name is SimpleIdentifier && a.name.name == 'deprecated';
89 });
90 }
91 }
92 return false;
93 }
94
95 /**
96 * Return the name for the given type.
97 */
98 String nameForType(TypeName type) {
99 if (type == NO_RETURN_TYPE) {
100 return null;
101 }
102 if (type == null) {
103 return DYNAMIC;
104 }
105 Identifier id = type.name;
106 if (id == null) {
107 return DYNAMIC;
108 }
109 String name = id.name;
110 if (name == null || name.length <= 0) {
111 return DYNAMIC;
112 }
113 TypeArgumentList typeArgs = type.typeArguments;
114 if (typeArgs != null) {
115 //TODO (danrubel) include type arguments
116 }
117 return name;
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698