| Index: pkg/analysis_server/lib/src/services/completion/dart/label_contributor.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/completion/dart/label_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/label_contributor.dart
|
| index 014d4eecd19e9fe85e5bb1d1c554f0ebccedd8cf..b5bae6c6631ba4027c4b908630201c81008be611 100644
|
| --- a/pkg/analysis_server/lib/src/services/completion/dart/label_contributor.dart
|
| +++ b/pkg/analysis_server/lib/src/services/completion/dart/label_contributor.dart
|
| @@ -14,8 +14,9 @@ import 'package:analysis_server/src/services/completion/dart/completion_manager.
|
| import 'package:analysis_server/src/services/completion/dart/local_declaration_visitor.dart'
|
| show LocalDeclarationVisitor;
|
| import 'package:analysis_server/src/services/completion/dart/optype.dart';
|
| +import 'package:analyzer/dart/ast/token.dart';
|
| +import 'package:analyzer/src/dart/ast/token.dart';
|
| import 'package:analyzer/src/generated/ast.dart';
|
| -import 'package:analyzer/src/generated/scanner.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
|
|
| import '../../../protocol_server.dart'
|
| @@ -27,6 +28,127 @@ final TypeName NO_RETURN_TYPE = new TypeName(
|
| new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null);
|
|
|
| /**
|
| +* Create a new protocol Element for inclusion in a completion suggestion.
|
| +*/
|
| +protocol.Element createLocalElement(
|
| + Source source, protocol.ElementKind kind, SimpleIdentifier id,
|
| + {String parameters,
|
| + TypeName returnType,
|
| + bool isAbstract: false,
|
| + bool isDeprecated: false}) {
|
| + String name;
|
| + Location location;
|
| + if (id != null) {
|
| + name = id.name;
|
| + // TODO(danrubel) use lineInfo to determine startLine and startColumn
|
| + location = new Location(source.fullName, id.offset, id.length, 0, 0);
|
| + } else {
|
| + name = '';
|
| + location = new Location(source.fullName, -1, 0, 1, 0);
|
| + }
|
| + int flags = protocol.Element.makeFlags(
|
| + isAbstract: isAbstract,
|
| + isDeprecated: isDeprecated,
|
| + isPrivate: Identifier.isPrivateName(name));
|
| + return new protocol.Element(kind, name, flags,
|
| + location: location,
|
| + parameters: parameters,
|
| + returnType: nameForType(returnType));
|
| +}
|
| +
|
| +/**
|
| +* Create a new suggestion for the given field.
|
| +* Return the new suggestion or `null` if it could not be created.
|
| +*/
|
| +CompletionSuggestion createLocalFieldSuggestion(
|
| + Source source, FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
|
| + bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl);
|
| + TypeName type = fieldDecl.fields.type;
|
| + return createLocalSuggestion(
|
| + varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type,
|
| + classDecl: fieldDecl.parent,
|
| + element: createLocalElement(
|
| + source, protocol.ElementKind.FIELD, varDecl.name,
|
| + returnType: type, isDeprecated: deprecated));
|
| +}
|
| +
|
| +/**
|
| +* Create a new suggestion based upon the given information.
|
| +* Return the new suggestion or `null` if it could not be created.
|
| +*/
|
| +CompletionSuggestion createLocalSuggestion(SimpleIdentifier id,
|
| + bool isDeprecated, int defaultRelevance, TypeName returnType,
|
| + {ClassDeclaration classDecl, protocol.Element element}) {
|
| + if (id == null) {
|
| + return null;
|
| + }
|
| + String completion = id.name;
|
| + if (completion == null || completion.length <= 0 || completion == '_') {
|
| + return null;
|
| + }
|
| + CompletionSuggestion suggestion = new CompletionSuggestion(
|
| + CompletionSuggestionKind.INVOCATION,
|
| + isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance,
|
| + completion,
|
| + completion.length,
|
| + 0,
|
| + isDeprecated,
|
| + false,
|
| + returnType: nameForType(returnType),
|
| + element: element);
|
| + if (classDecl != null) {
|
| + SimpleIdentifier classId = classDecl.name;
|
| + if (classId != null) {
|
| + String className = classId.name;
|
| + if (className != null && className.length > 0) {
|
| + suggestion.declaringType = className;
|
| + }
|
| + }
|
| + }
|
| + return suggestion;
|
| +}
|
| +
|
| +/**
|
| +* Return `true` if the @deprecated annotation is present
|
| +*/
|
| +bool isDeprecated(AnnotatedNode node) {
|
| + if (node != null) {
|
| + NodeList<Annotation> metadata = node.metadata;
|
| + if (metadata != null) {
|
| + return metadata.any((Annotation a) {
|
| + return a.name is SimpleIdentifier && a.name.name == 'deprecated';
|
| + });
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +/**
|
| +* Return the name for the given type.
|
| +*/
|
| +String nameForType(TypeName type) {
|
| + if (type == NO_RETURN_TYPE) {
|
| + return null;
|
| + }
|
| + if (type == null) {
|
| + return DYNAMIC;
|
| + }
|
| + Identifier id = type.name;
|
| + if (id == null) {
|
| + return DYNAMIC;
|
| + }
|
| + String name = id.name;
|
| + if (name == null || name.length <= 0) {
|
| + return DYNAMIC;
|
| + }
|
| + TypeArgumentList typeArgs = type.typeArguments;
|
| + if (typeArgs != null) {
|
| + //TODO (danrubel) include type arguments
|
| + }
|
| + return name;
|
| +}
|
| +
|
| +/**
|
| * A contributor for calculating label suggestions.
|
| */
|
| class LabelContributor extends DartCompletionContributor {
|
| @@ -163,124 +285,3 @@ class _LabelVisitor extends LocalDeclarationVisitor {
|
| return null;
|
| }
|
| }
|
| -
|
| -/**
|
| -* Create a new protocol Element for inclusion in a completion suggestion.
|
| -*/
|
| -protocol.Element createLocalElement(
|
| - Source source, protocol.ElementKind kind, SimpleIdentifier id,
|
| - {String parameters,
|
| - TypeName returnType,
|
| - bool isAbstract: false,
|
| - bool isDeprecated: false}) {
|
| - String name;
|
| - Location location;
|
| - if (id != null) {
|
| - name = id.name;
|
| - // TODO(danrubel) use lineInfo to determine startLine and startColumn
|
| - location = new Location(source.fullName, id.offset, id.length, 0, 0);
|
| - } else {
|
| - name = '';
|
| - location = new Location(source.fullName, -1, 0, 1, 0);
|
| - }
|
| - int flags = protocol.Element.makeFlags(
|
| - isAbstract: isAbstract,
|
| - isDeprecated: isDeprecated,
|
| - isPrivate: Identifier.isPrivateName(name));
|
| - return new protocol.Element(kind, name, flags,
|
| - location: location,
|
| - parameters: parameters,
|
| - returnType: nameForType(returnType));
|
| -}
|
| -
|
| -/**
|
| -* Create a new suggestion for the given field.
|
| -* Return the new suggestion or `null` if it could not be created.
|
| -*/
|
| -CompletionSuggestion createLocalFieldSuggestion(
|
| - Source source, FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
|
| - bool deprecated = isDeprecated(fieldDecl) || isDeprecated(varDecl);
|
| - TypeName type = fieldDecl.fields.type;
|
| - return createLocalSuggestion(
|
| - varDecl.name, deprecated, DART_RELEVANCE_LOCAL_FIELD, type,
|
| - classDecl: fieldDecl.parent,
|
| - element: createLocalElement(
|
| - source, protocol.ElementKind.FIELD, varDecl.name,
|
| - returnType: type, isDeprecated: deprecated));
|
| -}
|
| -
|
| -/**
|
| -* Create a new suggestion based upon the given information.
|
| -* Return the new suggestion or `null` if it could not be created.
|
| -*/
|
| -CompletionSuggestion createLocalSuggestion(SimpleIdentifier id,
|
| - bool isDeprecated, int defaultRelevance, TypeName returnType,
|
| - {ClassDeclaration classDecl, protocol.Element element}) {
|
| - if (id == null) {
|
| - return null;
|
| - }
|
| - String completion = id.name;
|
| - if (completion == null || completion.length <= 0 || completion == '_') {
|
| - return null;
|
| - }
|
| - CompletionSuggestion suggestion = new CompletionSuggestion(
|
| - CompletionSuggestionKind.INVOCATION,
|
| - isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance,
|
| - completion,
|
| - completion.length,
|
| - 0,
|
| - isDeprecated,
|
| - false,
|
| - returnType: nameForType(returnType),
|
| - element: element);
|
| - if (classDecl != null) {
|
| - SimpleIdentifier classId = classDecl.name;
|
| - if (classId != null) {
|
| - String className = classId.name;
|
| - if (className != null && className.length > 0) {
|
| - suggestion.declaringType = className;
|
| - }
|
| - }
|
| - }
|
| - return suggestion;
|
| -}
|
| -
|
| -/**
|
| -* Return `true` if the @deprecated annotation is present
|
| -*/
|
| -bool isDeprecated(AnnotatedNode node) {
|
| - if (node != null) {
|
| - NodeList<Annotation> metadata = node.metadata;
|
| - if (metadata != null) {
|
| - return metadata.any((Annotation a) {
|
| - return a.name is SimpleIdentifier && a.name.name == 'deprecated';
|
| - });
|
| - }
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -/**
|
| -* Return the name for the given type.
|
| -*/
|
| -String nameForType(TypeName type) {
|
| - if (type == NO_RETURN_TYPE) {
|
| - return null;
|
| - }
|
| - if (type == null) {
|
| - return DYNAMIC;
|
| - }
|
| - Identifier id = type.name;
|
| - if (id == null) {
|
| - return DYNAMIC;
|
| - }
|
| - String name = id.name;
|
| - if (name == null || name.length <= 0) {
|
| - return DYNAMIC;
|
| - }
|
| - TypeArgumentList typeArgs = type.typeArguments;
|
| - if (typeArgs != null) {
|
| - //TODO (danrubel) include type arguments
|
| - }
|
| - return name;
|
| -}
|
|
|