Index: pkg/analysis_server/lib/src/services/completion/local_reference_contributor.dart |
diff --git a/pkg/analysis_server/lib/src/services/completion/local_reference_contributor.dart b/pkg/analysis_server/lib/src/services/completion/local_reference_contributor.dart |
index 23282d04bc9c3618cfa390b95a6aad850a90e350..60d7b46bdb02e4ad165442d9e3859a1a27f31ba5 100644 |
--- a/pkg/analysis_server/lib/src/services/completion/local_reference_contributor.dart |
+++ b/pkg/analysis_server/lib/src/services/completion/local_reference_contributor.dart |
@@ -41,9 +41,6 @@ class LocalReferenceContributor extends DartCompletionContributor { |
new _LocalVisitor(request, request.offset, optype); |
localVisitor.visit(request.target.containingNode); |
} |
- if (optype.includeConstructorSuggestions) { |
- new _ConstructorVisitor(request).visit(request.target.containingNode); |
- } |
} |
// If target is an argument in an argument list |
@@ -68,168 +65,6 @@ class LocalReferenceContributor extends DartCompletionContributor { |
} |
/** |
- * A visitor for collecting constructor suggestions. |
- */ |
-class _ConstructorVisitor extends LocalDeclarationVisitor { |
- final DartCompletionRequest request; |
- |
- _ConstructorVisitor(DartCompletionRequest request) |
- : super(request.offset), |
- request = request; |
- |
- @override |
- void declaredClass(ClassDeclaration declaration) { |
- bool found = false; |
- for (ClassMember member in declaration.members) { |
- if (member is ConstructorDeclaration) { |
- found = true; |
- _addSuggestion(declaration, member); |
- } |
- } |
- if (!found) { |
- _addSuggestion(declaration, null); |
- } |
- } |
- |
- @override |
- void declaredClassTypeAlias(ClassTypeAlias declaration) {} |
- |
- @override |
- void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {} |
- |
- @override |
- void declaredFunction(FunctionDeclaration declaration) {} |
- |
- @override |
- void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {} |
- |
- @override |
- void declaredLabel(Label label, bool isCaseLabel) {} |
- |
- @override |
- void declaredLocalVar(SimpleIdentifier name, TypeName type) {} |
- |
- @override |
- void declaredMethod(MethodDeclaration declaration) {} |
- |
- @override |
- void declaredParam(SimpleIdentifier name, TypeName type) {} |
- |
- @override |
- void declaredTopLevelVar( |
- VariableDeclarationList varList, VariableDeclaration varDecl) {} |
- |
- /** |
- * For the given class and constructor, |
- * add a suggestion of the form B(...) or B.name(...). |
- * If the given constructor is `null` |
- * then add a default constructor suggestion. |
- */ |
- CompletionSuggestion _addSuggestion( |
- ClassDeclaration classDecl, ConstructorDeclaration constructorDecl) { |
- SimpleIdentifier elemId; |
- String completion = classDecl.name.name; |
- if (constructorDecl != null) { |
- elemId = constructorDecl.name; |
- if (elemId != null) { |
- String name = elemId.name; |
- if (name != null && name.length > 0) { |
- completion = '$completion.$name'; |
- } |
- } |
- } |
- bool deprecated = constructorDecl != null && isDeprecated(constructorDecl); |
- List<String> parameterNames = new List<String>(); |
- List<String> parameterTypes = new List<String>(); |
- int requiredParameterCount = 0; |
- bool hasNamedParameters = false; |
- StringBuffer paramBuf = new StringBuffer(); |
- paramBuf.write('('); |
- int paramCount = 0; |
- if (constructorDecl != null) { |
- for (FormalParameter param in constructorDecl.parameters.parameters) { |
- if (paramCount > 0) { |
- paramBuf.write(', '); |
- } |
- String paramName; |
- String typeName; |
- if (param is NormalFormalParameter) { |
- paramName = param.identifier.name; |
- typeName = _nameForParamType(param); |
- ++requiredParameterCount; |
- } else if (param is DefaultFormalParameter) { |
- NormalFormalParameter childParam = param.parameter; |
- paramName = childParam.identifier.name; |
- typeName = _nameForParamType(childParam); |
- if (param.kind == ParameterKind.NAMED) { |
- hasNamedParameters = true; |
- } |
- if (paramCount == requiredParameterCount) { |
- paramBuf.write(hasNamedParameters ? '{' : '['); |
- } |
- } |
- parameterNames.add(paramName); |
- parameterTypes.add(typeName); |
- paramBuf.write(typeName); |
- paramBuf.write(' '); |
- paramBuf.write(paramName); |
- ++paramCount; |
- } |
- } |
- if (paramCount > requiredParameterCount) { |
- paramBuf.write(hasNamedParameters ? '}' : ']'); |
- } |
- paramBuf.write(')'); |
- protocol.Element element = createElement( |
- request.source, protocol.ElementKind.CONSTRUCTOR, elemId, |
- parameters: paramBuf.toString()); |
- element.returnType = classDecl.name.name; |
- CompletionSuggestion suggestion = new CompletionSuggestion( |
- CompletionSuggestionKind.INVOCATION, |
- deprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, |
- completion, |
- completion.length, |
- 0, |
- deprecated, |
- false, |
- declaringType: classDecl.name.name, |
- element: element, |
- parameterNames: parameterNames, |
- parameterTypes: parameterTypes, |
- requiredParameterCount: requiredParameterCount, |
- hasNamedParameters: hasNamedParameters); |
- request.addSuggestion(suggestion); |
- return suggestion; |
- } |
- |
- /** |
- * Determine the name of the type for the given constructor parameter. |
- */ |
- String _nameForParamType(NormalFormalParameter param) { |
- if (param is SimpleFormalParameter) { |
- return nameForType(param.type); |
- } |
- SimpleIdentifier id = param.identifier; |
- if (param is FieldFormalParameter && id != null) { |
- String fieldName = id.name; |
- AstNode classDecl = param.getAncestor((p) => p is ClassDeclaration); |
- if (classDecl is ClassDeclaration) { |
- for (ClassMember member in classDecl.members) { |
- if (member is FieldDeclaration) { |
- for (VariableDeclaration field in member.fields.variables) { |
- if (field.name.name == fieldName) { |
- return nameForType(member.fields.type); |
- } |
- } |
- } |
- } |
- } |
- } |
- return DYNAMIC; |
- } |
-} |
- |
-/** |
* A visitor for collecting suggestions from the most specific child [AstNode] |
* that contains the completion offset to the [CompilationUnit]. |
*/ |