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

Unified Diff: pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart

Issue 752833002: refactor import caching to exclude suggestions for inherited members (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleanup unused imports Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
index c26078ba6b6f9a01abda3b77f3a2fc68f4c88ae6..dd313e132beccc38753ec5aa1ce2c09020ea8a9a 100644
--- a/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
@@ -14,6 +14,40 @@ import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
/**
+ * Create a suggestion based upon the given imported element.
+ */
+CompletionSuggestion createElementSuggestion(Element element,
+ {CompletionRelevance relevance: CompletionRelevance.DEFAULT}) {
+ String completion = element.displayName;
+ CompletionSuggestion suggestion = new CompletionSuggestion(
+ CompletionSuggestionKind.INVOCATION,
+ element.isDeprecated ? CompletionRelevance.LOW : relevance,
+ completion,
+ completion.length,
+ 0,
+ element.isDeprecated,
+ false);
+
+ suggestion.element = newElement_fromEngine(element);
+
+ DartType type;
+ if (element is FunctionElement) {
+ type = element.returnType;
+ } else if (element is PropertyAccessorElement && element.isGetter) {
+ type = element.returnType;
+ } else if (element is TopLevelVariableElement) {
+ type = element.type;
+ }
+ if (type != null) {
+ String name = type.displayName;
+ if (name != null && name.length > 0 && name != 'dynamic') {
+ suggestion.returnType = name;
+ }
+ }
+ return suggestion;
+}
+
+/**
* Call the given function with each non-null non-empty inherited type name
* that is defined in the given class.
*/
@@ -56,9 +90,11 @@ visitInheritedTypeNames(ClassDeclaration node, void inherited(String name)) {
}
/**
- * Call the given functions with each non-null non-empty inherited class
- * declaration, if the class is defined locally, or type name if it is not
- * defined locally.
+ * Starting with the given class node, traverse the inheritence hierarchy
+ * calling the given functions with each non-null non-empty inherited class
+ * declaration. For each locally defined class declaration, call [local].
+ * For each class identifier in the hierarchy that is not defined locally,
+ * call the [imported] function.
*/
void visitInheritedTypes(ClassDeclaration node, void
local(ClassDeclaration classNode), void imported(String typeName)) {

Powered by Google App Engine
This is Rietveld 408576698