Version 1.9.0-dev.10.3
svn merge -c 44261 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44262 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44270 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44271 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44272 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44273 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44276 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
svn merge -c 44277 https://dart.googlecode.com/svn/branches/bleeding_edge trunk
git-svn-id: http://dart.googlecode.com/svn/trunk@44280 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 6cd2ef6..922f2ad 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -257,6 +257,7 @@
analysisServerOptions.enableIncrementalResolutionApi;
contextDirectoryManager.defaultOptions.incrementalValidation =
analysisServerOptions.enableIncrementalResolutionValidation;
+ contextDirectoryManager.defaultOptions.generateImplicitErrors = false;
_noErrorNotification = analysisServerOptions.noErrorNotification;
AnalysisEngine.instance.logger = new AnalysisLogger();
_onAnalysisStartedController = new StreamController.broadcast();
diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart
index 29de8df..8af64b3 100644
--- a/pkg/analysis_server/lib/src/context_manager.dart
+++ b/pkg/analysis_server/lib/src/context_manager.dart
@@ -259,7 +259,14 @@
if (info.excludesResource(folder)) {
return;
}
- List<Resource> children = folder.getChildren();
+ List<Resource> children;
+ try {
+ children = folder.getChildren();
+ } on FileSystemException catch (exception) {
+ // The folder no longer exists, or cannot be read, to there's nothing to
+ // do.
+ return;
+ }
for (Resource child in children) {
String path = child.path;
// add files, recurse into folders
diff --git a/pkg/analysis_server/lib/src/get_handler.dart b/pkg/analysis_server/lib/src/get_handler.dart
index e58e428..aa4c2a2 100644
--- a/pkg/analysis_server/lib/src/get_handler.dart
+++ b/pkg/analysis_server/lib/src/get_handler.dart
@@ -1010,7 +1010,10 @@
_writeOption(buffer, 'Cache size', options.cacheSize);
_writeOption(buffer, 'Generate hints', options.hint);
_writeOption(buffer, 'Generate dart2js hints', options.dart2jsHint);
- _writeOption(buffer, 'Generate SDK errors', options.generateSdkErrors);
+ _writeOption(buffer, 'Generate errors in implicit files',
+ options.generateImplicitErrors);
+ _writeOption(
+ buffer, 'Generate errors in SDK files', options.generateSdkErrors);
_writeOption(buffer, 'Incremental resolution', options.incremental);
_writeOption(buffer, 'Incremental resolution with API changes',
options.incrementalApi);
diff --git a/pkg/analysis_server/lib/src/services/completion/completion_target.dart b/pkg/analysis_server/lib/src/services/completion/completion_target.dart
index 3ae98ba..47b8863 100644
--- a/pkg/analysis_server/lib/src/services/completion/completion_target.dart
+++ b/pkg/analysis_server/lib/src/services/completion/completion_target.dart
@@ -1,5 +1,23 @@
import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/scanner.dart';
+import 'package:analyzer/src/generated/utilities_dart.dart';
+
+int _computeArgIndex(AstNode containingNode, Object entity) {
+ var argList = containingNode;
+ if (argList is ArgumentList) {
+ NodeList<Expression> args = argList.arguments;
+ for (int index = 0; index < args.length; ++index) {
+ if (entity == args[index]) {
+ return index;
+ }
+ }
+ if (args.isEmpty) {
+ return 0;
+ }
+ }
+ return null;
+}
/**
* A CompletionTarget represents an edge in the parse tree which connects an
@@ -79,6 +97,12 @@
final Object entity;
/**
+ * If the target is an argument in an [ArgumentList], then this is the index
+ * of the argument in the list, otherwise this is `null`.
+ */
+ final int argIndex;
+
+ /**
* Compute the appropriate [CompletionTarget] for the given [offset] within
* the [compilationUnit].
*/
@@ -164,7 +188,50 @@
* Create a [CompletionTarget] holding the given [containingNode] and
* [entity].
*/
- CompletionTarget._(this.containingNode, this.entity);
+ CompletionTarget._(AstNode containingNode, Object entity)
+ : this.containingNode = containingNode,
+ this.entity = entity,
+ this.argIndex = _computeArgIndex(containingNode, entity);
+
+ /**
+ * Return `true` if the target is a functional argument in an argument list.
+ * The target [AstNode] hierarchy *must* be resolved for this to work.
+ */
+ bool isFunctionalArgument() {
+ if (argIndex == null) {
+ return false;
+ }
+ AstNode argList = containingNode;
+ if (argList is! ArgumentList) {
+ return false;
+ }
+ AstNode parent = argList.parent;
+ if (parent is InstanceCreationExpression) {
+ DartType instType = parent.bestType;
+ if (instType != null) {
+ Element intTypeElem = instType.element;
+ if (intTypeElem is ClassElement) {
+ SimpleIdentifier constructorName = parent.constructorName.name;
+ ConstructorElement constructor = constructorName != null
+ ? intTypeElem.getNamedConstructor(constructorName.name)
+ : intTypeElem.unnamedConstructor;
+ return constructor != null &&
+ _isFunctionalParameter(constructor.parameters, argIndex);
+ }
+ }
+ } else if (parent is MethodInvocation) {
+ SimpleIdentifier methodName = parent.methodName;
+ if (methodName != null) {
+ Element methodElem = methodName.bestElement;
+ if (methodElem is MethodElement) {
+ return _isFunctionalParameter(methodElem.parameters, argIndex);
+ } else if (methodElem is FunctionElement) {
+ return _isFunctionalParameter(methodElem.parameters, argIndex);
+ }
+ }
+ }
+ return false;
+ }
/**
* Determine whether [node] could possibly be the [entity] for a
@@ -205,4 +272,22 @@
return false;
}
}
+
+ /**
+ * Return `true` if the parameter is a functional parameter.
+ */
+ static bool _isFunctionalParameter(
+ List<ParameterElement> parameters, int paramIndex) {
+ if (paramIndex < parameters.length) {
+ ParameterElement param = parameters[paramIndex];
+ DartType paramType = param.type;
+ if (param.parameterKind == ParameterKind.NAMED) {
+ // TODO(danrubel) handle named parameters
+ return false;
+ } else {
+ return paramType is FunctionType || paramType is FunctionTypeAlias;
+ }
+ }
+ return false;
+ }
}
diff --git a/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart b/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart
index 7b56c5f..ca9c75a 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart
@@ -305,6 +305,8 @@
} else {
otherImportedSuggestions.add(suggestion);
}
+ } else if (element is FunctionTypeAliasElement) {
+ importedTypeSuggestions.add(suggestion);
} else if (element is ClassElement) {
importedTypeSuggestions.add(suggestion);
_addConstructorSuggestions(element, relevance);
diff --git a/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
index f97b2a1..15f26b2 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
@@ -340,4 +340,31 @@
}
return _optype;
}
+
+ /**
+ * Convert all [CompletionSuggestionKind.INVOCATION] suggestions
+ * to [CompletionSuggestionKind.IDENTIFIER] suggestions.
+ */
+ void convertInvocationsToIdentifiers() {
+ for (int index = suggestions.length - 1; index >= 0; --index) {
+ CompletionSuggestion suggestion = suggestions[index];
+ if (suggestion.kind == CompletionSuggestionKind.INVOCATION) {
+ // Create a copy rather than just modifying the existing suggestion
+ // because [DartCompletionCache] may be caching that suggestion
+ // for future completion requests
+ suggestions[index] = new CompletionSuggestion(
+ CompletionSuggestionKind.IDENTIFIER, suggestion.relevance,
+ suggestion.completion, suggestion.selectionOffset,
+ suggestion.selectionLength, suggestion.isDeprecated,
+ suggestion.isPotential,
+ declaringType: suggestion.declaringType,
+ parameterNames: suggestion.parameterNames,
+ parameterTypes: suggestion.parameterTypes,
+ requiredParameterCount: suggestion.requiredParameterCount,
+ hasNamedParameters: suggestion.hasNamedParameters,
+ returnType: suggestion.returnType,
+ element: suggestion.element);
+ }
+ }
+ }
}
diff --git a/pkg/analysis_server/lib/src/services/completion/imported_computer.dart b/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
index 4e025f3..5a06b21 100644
--- a/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
@@ -22,6 +22,7 @@
*/
class ImportedComputer extends DartCompletionComputer {
bool shouldWaitForLowPrioritySuggestions;
+ bool suggestionsComputed;
_ImportedSuggestionBuilder builder;
ImportedComputer({this.shouldWaitForLowPrioritySuggestions: false});
@@ -29,15 +30,17 @@
@override
bool computeFast(DartCompletionRequest request) {
OpType optype = request.optype;
- if (optype.includeTopLevelSuggestions ||
+ if (optype.includeReturnValueSuggestions ||
+ optype.includeTypeNameSuggestions ||
+ optype.includeVoidReturnSuggestions ||
optype.includeConstructorSuggestions) {
- builder = new _ImportedSuggestionBuilder(request,
- typesOnly: optype.includeOnlyTypeNameSuggestions,
- excludeVoidReturn: !optype.includeVoidReturnSuggestions,
- constructorsOnly: optype.includeConstructorSuggestions);
+ builder = new _ImportedSuggestionBuilder(request, optype);
builder.shouldWaitForLowPrioritySuggestions =
shouldWaitForLowPrioritySuggestions;
- return builder.computeFast(request.node);
+ // If target is an argument in an argument list
+ // then suggestions may need to be adjusted
+ suggestionsComputed = builder.computeFast(request.node);
+ return suggestionsComputed && request.target.argIndex == null;
}
return true;
}
@@ -45,10 +48,26 @@
@override
Future<bool> computeFull(DartCompletionRequest request) {
if (builder != null) {
- return builder.computeFull(request.node);
+ if (!suggestionsComputed) {
+ return builder.computeFull(request.node).then((bool result) {
+ _updateSuggestions(request);
+ return result;
+ });
+ }
+ _updateSuggestions(request);
+ return new Future.value(true);
}
return new Future.value(false);
}
+
+ /**
+ * If target is a function argument, suggest identifiers not invocations
+ */
+ void _updateSuggestions(DartCompletionRequest request) {
+ if (request.target.isFunctionalArgument()) {
+ request.convertInvocationsToIdentifiers();
+ }
+ }
}
/**
@@ -59,13 +78,10 @@
implements SuggestionBuilder {
bool shouldWaitForLowPrioritySuggestions;
final DartCompletionRequest request;
- final bool typesOnly;
- final bool excludeVoidReturn;
- final bool constructorsOnly;
+ final OpType optype;
DartCompletionCache cache;
- _ImportedSuggestionBuilder(this.request, {this.typesOnly: false,
- this.excludeVoidReturn: false, this.constructorsOnly: false}) {
+ _ImportedSuggestionBuilder(this.request, this.optype) {
cache = request.cache;
}
@@ -129,13 +145,13 @@
{int relevance: DART_RELEVANCE_DEFAULT}) {
elements.forEach((Element elem) {
if (elem is! ClassElement) {
- if (typesOnly) {
+ if (optype.includeOnlyTypeNameSuggestions) {
return;
}
if (elem is ExecutableElement) {
DartType returnType = elem.returnType;
if (returnType != null && returnType.isVoid) {
- if (excludeVoidReturn) {
+ if (!optype.includeVoidReturnSuggestions) {
return;
}
}
@@ -208,9 +224,12 @@
* Add suggested based upon imported elements.
*/
void _addSuggestions(AstNode node) {
- if (constructorsOnly) {
+ if (optype.includeConstructorSuggestions) {
_addConstructorSuggestions();
- } else {
+ }
+ if (optype.includeReturnValueSuggestions ||
+ optype.includeTypeNameSuggestions ||
+ optype.includeVoidReturnSuggestions) {
_addInheritedSuggestions(node);
_addTopLevelSuggestions();
}
@@ -229,14 +248,15 @@
filterText = filterText.substring(0, 1);
}
DartCompletionCache cache = request.cache;
- _addFilteredSuggestions(filterText, cache.importedTypeSuggestions);
- _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions);
- if (!typesOnly) {
+ if (optype.includeTypeNameSuggestions) {
+ _addFilteredSuggestions(filterText, cache.importedTypeSuggestions);
+ _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions);
+ }
+ if (optype.includeReturnValueSuggestions) {
_addFilteredSuggestions(filterText, cache.otherImportedSuggestions);
- if (!excludeVoidReturn) {
- _addFilteredSuggestions(
- filterText, cache.importedVoidReturnSuggestions);
- }
+ }
+ if (optype.includeVoidReturnSuggestions) {
+ _addFilteredSuggestions(filterText, cache.importedVoidReturnSuggestions);
}
}
}
diff --git a/pkg/analysis_server/lib/src/services/completion/local_computer.dart b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
index fdbb38c..4f6b138 100644
--- a/pkg/analysis_server/lib/src/services/completion/local_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
@@ -87,10 +87,11 @@
// Collect suggestions from the specific child [AstNode] that contains
// the completion offset and all of its parents recursively.
- if (optype.includeTopLevelSuggestions) {
- _LocalVisitor localVisitor = new _LocalVisitor(request, request.offset,
- optype.includeOnlyTypeNameSuggestions,
- !optype.includeVoidReturnSuggestions);
+ if (optype.includeReturnValueSuggestions ||
+ optype.includeTypeNameSuggestions ||
+ optype.includeVoidReturnSuggestions) {
+ _LocalVisitor localVisitor =
+ new _LocalVisitor(request, request.offset, optype);
localVisitor.visit(request.node);
}
if (optype.includeStatementLabelSuggestions ||
@@ -104,18 +105,25 @@
new _ConstructorVisitor(request).visit(request.node);
}
- // If the unit is not a part and does not reference any parts
- // then work is complete
- return !request.unit.directives.any((Directive directive) =>
- directive is PartOfDirective || directive is PartDirective);
+ // If target is an argument in an argument list
+ // then suggestions may need to be adjusted
+ return request.target.argIndex == null;
}
@override
Future<bool> computeFull(DartCompletionRequest request) {
- // TODO: implement computeFull
- // include results from part files that are included in the library
+ _updateSuggestions(request);
return new Future.value(false);
}
+
+ /**
+ * If target is a function argument, suggest identifiers not invocations
+ */
+ void _updateSuggestions(DartCompletionRequest request) {
+ if (request.target.isFunctionalArgument()) {
+ request.convertInvocationsToIdentifiers();
+ }
+ }
}
/**
@@ -419,110 +427,114 @@
*/
class _LocalVisitor extends LocalDeclarationVisitor {
final DartCompletionRequest request;
- final bool typesOnly;
- final bool excludeVoidReturn;
+ final OpType optype;
- _LocalVisitor(
- this.request, int offset, this.typesOnly, this.excludeVoidReturn)
- : super(offset);
+ _LocalVisitor(this.request, int offset, this.optype) : super(offset);
@override
void declaredClass(ClassDeclaration declaration) {
- bool isDeprecated = _isDeprecated(declaration);
- CompletionSuggestion suggestion = _addSuggestion(declaration.name,
- _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
- if (suggestion != null) {
- suggestion.element = _createElement(
- protocol.ElementKind.CLASS, declaration.name,
- returnType: _NO_RETURN_TYPE,
- isAbstract: declaration.isAbstract,
- isDeprecated: isDeprecated);
+ if (optype.includeTypeNameSuggestions) {
+ bool isDeprecated = _isDeprecated(declaration);
+ CompletionSuggestion suggestion = _addSuggestion(declaration.name,
+ _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
+ if (suggestion != null) {
+ suggestion.element = _createElement(
+ protocol.ElementKind.CLASS, declaration.name,
+ returnType: _NO_RETURN_TYPE,
+ isAbstract: declaration.isAbstract,
+ isDeprecated: isDeprecated);
+ }
}
}
@override
void declaredClassTypeAlias(ClassTypeAlias declaration) {
- bool isDeprecated = _isDeprecated(declaration);
- CompletionSuggestion suggestion = _addSuggestion(declaration.name,
- _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
- if (suggestion != null) {
- suggestion.element = _createElement(
- protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name,
- returnType: _NO_RETURN_TYPE,
- isAbstract: true,
- isDeprecated: isDeprecated);
+ if (optype.includeTypeNameSuggestions) {
+ bool isDeprecated = _isDeprecated(declaration);
+ CompletionSuggestion suggestion = _addSuggestion(declaration.name,
+ _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
+ if (suggestion != null) {
+ suggestion.element = _createElement(
+ protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name,
+ returnType: _NO_RETURN_TYPE,
+ isAbstract: true,
+ isDeprecated: isDeprecated);
+ }
}
}
@override
void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
- if (typesOnly) {
- return;
- }
- bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl);
- TypeName type = fieldDecl.fields.type;
- CompletionSuggestion suggestion = _addSuggestion(
- varDecl.name, type, isDeprecated, DART_RELEVANCE_LOCAL_FIELD,
- classDecl: fieldDecl.parent);
- if (suggestion != null) {
- suggestion.element = _createElement(
- protocol.ElementKind.FIELD, varDecl.name,
- returnType: type, isDeprecated: isDeprecated);
+ if (optype.includeReturnValueSuggestions) {
+ bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl);
+ TypeName type = fieldDecl.fields.type;
+ CompletionSuggestion suggestion = _addSuggestion(
+ varDecl.name, type, isDeprecated, DART_RELEVANCE_LOCAL_FIELD,
+ classDecl: fieldDecl.parent);
+ if (suggestion != null) {
+ suggestion.element = _createElement(
+ protocol.ElementKind.FIELD, varDecl.name,
+ returnType: type, isDeprecated: isDeprecated);
+ }
}
}
@override
void declaredFunction(FunctionDeclaration declaration) {
- if (typesOnly) {
- return;
- }
- TypeName returnType = declaration.returnType;
- bool isDeprecated = _isDeprecated(declaration);
- protocol.ElementKind kind;
- int defaultRelevance = DART_RELEVANCE_DEFAULT;
- if (declaration.isGetter) {
- kind = protocol.ElementKind.GETTER;
- defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
- } else if (declaration.isSetter) {
- if (excludeVoidReturn) {
- return;
+ if (optype.includeReturnValueSuggestions ||
+ optype.includeVoidReturnSuggestions) {
+ TypeName returnType = declaration.returnType;
+ bool isDeprecated = _isDeprecated(declaration);
+ protocol.ElementKind kind;
+ int defaultRelevance = DART_RELEVANCE_DEFAULT;
+ if (declaration.isGetter) {
+ kind = protocol.ElementKind.GETTER;
+ defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
+ } else if (declaration.isSetter) {
+ if (!optype.includeVoidReturnSuggestions) {
+ return;
+ }
+ kind = protocol.ElementKind.SETTER;
+ returnType = _NO_RETURN_TYPE;
+ defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
+ } else {
+ if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) {
+ return;
+ }
+ kind = protocol.ElementKind.FUNCTION;
+ defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION;
}
- kind = protocol.ElementKind.SETTER;
- returnType = _NO_RETURN_TYPE;
- defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
- } else {
- if (excludeVoidReturn && _isVoid(returnType)) {
- return;
- }
- kind = protocol.ElementKind.FUNCTION;
- defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION;
- }
- CompletionSuggestion suggestion = _addSuggestion(
- declaration.name, returnType, isDeprecated, defaultRelevance);
- if (suggestion != null) {
- FormalParameterList param = declaration.functionExpression.parameters;
- suggestion.element = _createElement(kind, declaration.name,
- parameters: param != null ? param.toSource() : null,
- returnType: returnType,
- isDeprecated: isDeprecated);
- if (kind == protocol.ElementKind.FUNCTION) {
- _addParameterInfo(
- suggestion, declaration.functionExpression.parameters);
+ CompletionSuggestion suggestion = _addSuggestion(
+ declaration.name, returnType, isDeprecated, defaultRelevance);
+ if (suggestion != null) {
+ FormalParameterList param = declaration.functionExpression.parameters;
+ suggestion.element = _createElement(kind, declaration.name,
+ parameters: param != null ? param.toSource() : null,
+ returnType: returnType,
+ isDeprecated: isDeprecated);
+ if (kind == protocol.ElementKind.FUNCTION) {
+ _addParameterInfo(
+ suggestion, declaration.functionExpression.parameters);
+ }
}
}
}
@override
void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
- bool isDeprecated = _isDeprecated(declaration);
- TypeName returnType = declaration.returnType;
- CompletionSuggestion suggestion = _addSuggestion(
- declaration.name, returnType, isDeprecated, DART_RELEVANCE_DEFAULT);
- if (suggestion != null) {
- // TODO (danrubel) determine parameters and return type
- suggestion.element = _createElement(
- protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name,
- returnType: returnType, isAbstract: true, isDeprecated: isDeprecated);
+ if (optype.includeTypeNameSuggestions) {
+ bool isDeprecated = _isDeprecated(declaration);
+ TypeName returnType = declaration.returnType;
+ CompletionSuggestion suggestion = _addSuggestion(
+ declaration.name, returnType, isDeprecated, DART_RELEVANCE_DEFAULT);
+ if (suggestion != null) {
+ // TODO (danrubel) determine parameters and return type
+ suggestion.element = _createElement(
+ protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name,
+ returnType: returnType,
+ isAbstract: true,
+ isDeprecated: isDeprecated);
+ }
}
}
@@ -533,87 +545,84 @@
@override
void declaredLocalVar(SimpleIdentifier name, TypeName type) {
- if (typesOnly) {
- return;
- }
- CompletionSuggestion suggestion =
- _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE);
- if (suggestion != null) {
- suggestion.element = _createElement(
- protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type);
+ if (optype.includeReturnValueSuggestions) {
+ CompletionSuggestion suggestion =
+ _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE);
+ if (suggestion != null) {
+ suggestion.element = _createElement(
+ protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type);
+ }
}
}
@override
void declaredMethod(MethodDeclaration declaration) {
- if (typesOnly) {
- return;
- }
- protocol.ElementKind kind;
- String parameters;
- TypeName returnType = declaration.returnType;
- int defaultRelevance = DART_RELEVANCE_DEFAULT;
- if (declaration.isGetter) {
- kind = protocol.ElementKind.GETTER;
- parameters = null;
- defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
- } else if (declaration.isSetter) {
- if (excludeVoidReturn) {
- return;
+ if (optype.includeReturnValueSuggestions ||
+ optype.includeVoidReturnSuggestions) {
+ protocol.ElementKind kind;
+ String parameters;
+ TypeName returnType = declaration.returnType;
+ int defaultRelevance = DART_RELEVANCE_DEFAULT;
+ if (declaration.isGetter) {
+ kind = protocol.ElementKind.GETTER;
+ parameters = null;
+ defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
+ } else if (declaration.isSetter) {
+ if (!optype.includeVoidReturnSuggestions) {
+ return;
+ }
+ kind = protocol.ElementKind.SETTER;
+ returnType = _NO_RETURN_TYPE;
+ defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
+ } else {
+ if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) {
+ return;
+ }
+ kind = protocol.ElementKind.METHOD;
+ parameters = declaration.parameters.toSource();
+ defaultRelevance = DART_RELEVANCE_LOCAL_METHOD;
}
- kind = protocol.ElementKind.SETTER;
- returnType = _NO_RETURN_TYPE;
- defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
- } else {
- if (excludeVoidReturn && _isVoid(returnType)) {
- return;
- }
- kind = protocol.ElementKind.METHOD;
- parameters = declaration.parameters.toSource();
- defaultRelevance = DART_RELEVANCE_LOCAL_METHOD;
- }
- bool isDeprecated = _isDeprecated(declaration);
- CompletionSuggestion suggestion = _addSuggestion(
- declaration.name, returnType, isDeprecated, defaultRelevance,
- classDecl: declaration.parent);
- if (suggestion != null) {
- suggestion.element = _createElement(kind, declaration.name,
- parameters: parameters,
- returnType: returnType,
- isAbstract: declaration.isAbstract,
- isDeprecated: isDeprecated);
- if (kind == protocol.ElementKind.METHOD) {
- _addParameterInfo(suggestion, declaration.parameters);
+ bool isDeprecated = _isDeprecated(declaration);
+ CompletionSuggestion suggestion = _addSuggestion(
+ declaration.name, returnType, isDeprecated, defaultRelevance,
+ classDecl: declaration.parent);
+ if (suggestion != null) {
+ suggestion.element = _createElement(kind, declaration.name,
+ parameters: parameters,
+ returnType: returnType,
+ isAbstract: declaration.isAbstract,
+ isDeprecated: isDeprecated);
+ if (kind == protocol.ElementKind.METHOD) {
+ _addParameterInfo(suggestion, declaration.parameters);
+ }
}
}
}
@override
void declaredParam(SimpleIdentifier name, TypeName type) {
- if (typesOnly) {
- return;
- }
- CompletionSuggestion suggestion =
- _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER);
- if (suggestion != null) {
- suggestion.element = _createElement(protocol.ElementKind.PARAMETER, name,
- returnType: type);
+ if (optype.includeReturnValueSuggestions) {
+ CompletionSuggestion suggestion =
+ _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER);
+ if (suggestion != null) {
+ suggestion.element = _createElement(
+ protocol.ElementKind.PARAMETER, name, returnType: type);
+ }
}
}
@override
void declaredTopLevelVar(
VariableDeclarationList varList, VariableDeclaration varDecl) {
- if (typesOnly) {
- return;
- }
- bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl);
- CompletionSuggestion suggestion = _addSuggestion(varDecl.name, varList.type,
- isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
- if (suggestion != null) {
- suggestion.element = _createElement(
- protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name,
- returnType: varList.type, isDeprecated: isDeprecated);
+ if (optype.includeReturnValueSuggestions) {
+ bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl);
+ CompletionSuggestion suggestion = _addSuggestion(varDecl.name,
+ varList.type, isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
+ if (suggestion != null) {
+ suggestion.element = _createElement(
+ protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name,
+ returnType: varList.type, isDeprecated: isDeprecated);
+ }
}
}
diff --git a/pkg/analysis_server/lib/src/services/completion/optype.dart b/pkg/analysis_server/lib/src/services/completion/optype.dart
index 197ffba..a7c7053 100644
--- a/pkg/analysis_server/lib/src/services/completion/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/optype.dart
@@ -72,13 +72,6 @@
!includeReturnValueSuggestions &&
!includeVoidReturnSuggestions &&
!includeInvocationSuggestions;
-
- /**
- * Indicate whether top level elements should be suggested
- */
- bool get includeTopLevelSuggestions => includeReturnValueSuggestions ||
- includeTypeNameSuggestions ||
- includeVoidReturnSuggestions;
}
class _OpTypeAstVisitor extends GeneralizingAstVisitor {
@@ -359,7 +352,9 @@
void visitInterpolationExpression(InterpolationExpression node) {
if (identical(entity, node.expression)) {
optype.includeReturnValueSuggestions = true;
- optype.includeTypeNameSuggestions = true;
+ // Only include type names in a ${ } expression
+ optype.includeTypeNameSuggestions =
+ node.leftBracket != null && node.leftBracket.length > 1;
}
}
@@ -513,6 +508,14 @@
}
@override
+ void visitVariableDeclarationList(VariableDeclarationList node) {
+ if ((node.keyword == null || node.keyword.lexeme != 'var') &&
+ (node.type == null)) {
+ optype.includeTypeNameSuggestions = true;
+ }
+ }
+
+ @override
void visitVariableDeclarationStatement(VariableDeclarationStatement node) {}
@override
diff --git a/pkg/analysis_server/test/services/completion/combinator_computer_test.dart b/pkg/analysis_server/test/services/completion/combinator_computer_test.dart
index 8e70f1c..d924f81 100644
--- a/pkg/analysis_server/test/services/completion/combinator_computer_test.dart
+++ b/pkg/analysis_server/test/services/completion/combinator_computer_test.dart
@@ -70,8 +70,8 @@
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestTopLevelVar('T1', null,
DART_RELEVANCE_DEFAULT, CompletionSuggestionKind.IDENTIFIER);
- assertSuggestFunction('F1', 'PB', false,
- DART_RELEVANCE_DEFAULT, CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestFunction('F1', 'PB',
+ kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('C');
assertNotSuggested('D');
assertNotSuggested('X');
@@ -113,8 +113,8 @@
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestTopLevelVar('T1', null,
DART_RELEVANCE_DEFAULT, CompletionSuggestionKind.IDENTIFIER);
- assertSuggestFunction('F1', 'PB', false,
- DART_RELEVANCE_DEFAULT, CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestFunction('F1', 'PB',
+ kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestClass('Clz',
relevance: DART_RELEVANCE_DEFAULT,
kind: CompletionSuggestionKind.IDENTIFIER);
diff --git a/pkg/analysis_server/test/services/completion/completion_target_test.dart b/pkg/analysis_server/test/services/completion/completion_target_test.dart
index 8decbb7..bb258c4 100644
--- a/pkg/analysis_server/test/services/completion/completion_target_test.dart
+++ b/pkg/analysis_server/test/services/completion/completion_target_test.dart
@@ -19,6 +19,7 @@
@reflectiveTest
class CompletionTargetTest extends AbstractContextTest {
+ Source testSource;
int completionOffset;
CompletionTarget target;
@@ -30,78 +31,139 @@
expect(nextOffset, equals(-1), reason: 'too many ^');
content = content.substring(0, completionOffset) +
content.substring(completionOffset + 1);
- Source testSource = addSource('/test.dart', content);
+ testSource = addSource('/test.dart', content);
CompilationUnit unit = context.parseCompilationUnit(testSource);
target = new CompletionTarget.forOffset(unit, completionOffset);
}
+ void assertTarget(entityText, nodeText,
+ {int argIndex: null, bool isFunctionalArgument: false}) {
+ void assertCommon() {
+ expect(target.entity.toString(), entityText);
+ expect(target.containingNode.toString(), nodeText);
+ expect(target.argIndex, argIndex);
+ }
+ // Assert with parsed unit
+ assertCommon();
+ CompilationUnit unit =
+ context.resolveCompilationUnit2(testSource, testSource);
+ target = new CompletionTarget.forOffset(unit, completionOffset);
+ // Assert more with resolved unit
+ assertCommon();
+ expect(target.isFunctionalArgument(), isFunctionalArgument);
+ }
+
+ test_ArgumentList_InstanceCreationExpression() {
+ // ArgumentList InstanceCreationExpression Block
+ addTestSource('main() {new Foo(^)}');
+ assertTarget(')', '()', argIndex: 0);
+ }
+
+ test_ArgumentList_MethodInvocation() {
+ // ArgumentList MethodInvocation Block
+ addTestSource('main() {foo(^)}');
+ assertTarget(')', '()', argIndex: 0);
+ }
+
+ test_ArgumentList_MethodInvocation2() {
+ // ArgumentList MethodInvocation Block
+ addTestSource('main() {foo(^n)}');
+ assertTarget('n', '(n)', argIndex: 0);
+ }
+
+ test_ArgumentList_MethodInvocation3() {
+ // ArgumentList MethodInvocation Block
+ addTestSource('main() {foo(n^)}');
+ assertTarget('n', '(n)', argIndex: 0);
+ }
+
+ test_ArgumentList_MethodInvocation4() {
+ // ArgumentList MethodInvocation Block
+ addTestSource('main() {foo(n,^)}');
+ assertTarget('', '(n, )', argIndex: 1);
+ }
+
+ test_ArgumentList_MethodInvocation_functionArg() {
+ // ArgumentList MethodInvocation Block
+ addTestSource('main() {foo(^)} foo(f()) {}');
+ assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
+ }
+
+ test_ArgumentList_MethodInvocation_functionArg2() {
+ // ArgumentList MethodInvocation Block
+ addTestSource('main() {new B().boo(^)} class B{boo(f()){}}');
+ assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
+ }
+
+ test_ArgumentList_InstanceCreationExpression_functionArg2() {
+ // ArgumentList InstanceCreationExpression Block
+ addTestSource('main() {new B(^)} class B{B(f()){}}');
+ assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
+ }
+
test_AsExpression_identifier() {
// SimpleIdentifier TypeName AsExpression
addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}');
- expect(target.entity.toString(), 'a as String');
- expect(target.containingNode.toString(), '(a as String)');
+ assertTarget('a as String', '(a as String)');
}
test_AsExpression_keyword() {
// SimpleIdentifier TypeName AsExpression
addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}');
- expect(target.entity.toString(), 'as');
- expect(target.containingNode.toString(), 'a as String');
+ assertTarget('as', 'a as String');
}
test_AsExpression_keyword2() {
// SimpleIdentifier TypeName AsExpression
addTestSource('class A {var b; X _c; foo() {var a; (a a^s String).foo();}');
- expect(target.entity.toString(), 'as');
- expect(target.containingNode.toString(), 'a as String');
+ assertTarget('as', 'a as String');
}
test_AsExpression_keyword3() {
// SimpleIdentifier TypeName AsExpression
addTestSource('class A {var b; X _c; foo() {var a; (a as^ String).foo();}');
- expect(target.entity.toString(), 'as');
- expect(target.containingNode.toString(), 'a as String');
+ assertTarget('as', 'a as String');
}
test_AsExpression_type() {
// SimpleIdentifier TypeName AsExpression
addTestSource('class A {var b; X _c; foo() {var a; (a as ^String).foo();}');
- expect(target.entity.toString(), 'String');
- expect(target.containingNode.toString(), 'a as String');
+ assertTarget('String', 'a as String');
}
- test_InstanceCreationExpression_keyword() {
- // InstanceCreationExpression ExpressionStatement Block
- addTestSource('class C {foo(){var f; {var x;} new^ }}');
- expect(target.entity.toString(), 'new ();');
- expect(target.containingNode.toString(), '{var f; {var x;} new ();}');
- }
-
- test_InstanceCreationExpression_keyword2() {
- // InstanceCreationExpression ExpressionStatement Block
- addTestSource('class C {foo(){var f; {var x;} new^ C();}}');
- expect(target.entity.toString(), 'new C();');
- expect(target.containingNode.toString(), '{var f; {var x;} new C();}');
+ test_Block() {
+ // Block
+ addTestSource('main() {^}');
+ assertTarget('}', '{}');
}
test_InstanceCreationExpression_identifier() {
// InstanceCreationExpression ExpressionStatement Block
addTestSource('class C {foo(){var f; {var x;} new ^C();}}');
- expect(target.entity.toString(), 'C');
- expect(target.containingNode.toString(), 'new C()');
+ assertTarget('C', 'new C()');
+ }
+
+ test_InstanceCreationExpression_keyword() {
+ // InstanceCreationExpression ExpressionStatement Block
+ addTestSource('class C {foo(){var f; {var x;} new^ }}');
+ assertTarget('new ();', '{var f; {var x;} new ();}');
+ }
+
+ test_InstanceCreationExpression_keyword2() {
+ // InstanceCreationExpression ExpressionStatement Block
+ addTestSource('class C {foo(){var f; {var x;} new^ C();}}');
+ assertTarget('new C();', '{var f; {var x;} new C();}');
}
test_VariableDeclaration_lhs_identifier_after() {
// VariableDeclaration VariableDeclarationList
addTestSource('main() {int b^ = 1;}');
- expect(target.entity.toString(), 'b = 1');
- expect(target.containingNode.toString(), 'int b = 1');
+ assertTarget('b = 1', 'int b = 1');
}
test_VariableDeclaration_lhs_identifier_before() {
// VariableDeclaration VariableDeclarationList
addTestSource('main() {int ^b = 1;}');
- expect(target.entity.toString(), 'b = 1');
- expect(target.containingNode.toString(), 'int b = 1');
+ assertTarget('b = 1', 'int b = 1');
}
}
diff --git a/pkg/analysis_server/test/services/completion/completion_test_util.dart b/pkg/analysis_server/test/services/completion/completion_test_util.dart
index 862934d..d4504b6 100644
--- a/pkg/analysis_server/test/services/completion/completion_test_util.dart
+++ b/pkg/analysis_server/test/services/completion/completion_test_util.dart
@@ -234,16 +234,16 @@
}
CompletionSuggestion assertSuggestFunction(String name, String returnType,
- [bool isDeprecated = false, int relevance = DART_RELEVANCE_DEFAULT,
- CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) {
CompletionSuggestion cs = assertSuggest(name,
- csKind: kind, relevance: relevance, isDeprecated: isDeprecated);
+ csKind: kind, relevance: relevance, isDeprecated: deprecated);
expect(cs.returnType, returnType != null ? returnType : 'dynamic');
protocol.Element element = cs.element;
expect(element, isNotNull);
expect(element.kind, equals(protocol.ElementKind.FUNCTION));
expect(element.name, equals(name));
- expect(element.isDeprecated, equals(isDeprecated));
+ expect(element.isDeprecated, equals(deprecated));
String param = element.parameters;
expect(param, isNotNull);
expect(param[0], equals('('));
@@ -433,52 +433,7 @@
if (!_computeFastCalled) {
expect(computeFast(), isFalse);
}
-
- // Index SDK
- for (Source librarySource in context.librarySources) {
- CompilationUnit unit =
- context.getResolvedCompilationUnit2(librarySource, librarySource);
- if (unit != null) {
- index.indexUnit(context, unit);
- }
- }
-
- var result = context.performAnalysisTask();
- bool resolved = false;
- while (result.hasMoreWork) {
-
- // Update the index
- result.changeNotices.forEach((ChangeNotice notice) {
- CompilationUnit unit = notice.resolvedDartUnit;
- if (unit != null) {
- index.indexUnit(context, unit);
- }
- });
-
- // If the unit has been resolved, then finish the completion
- List<Source> libSourceList = context.getLibrariesContaining(testSource);
- if (libSourceList.length > 0) {
- LibraryElement library = context.getLibraryElement(libSourceList[0]);
- if (library != null) {
- CompilationUnit unit =
- context.getResolvedCompilationUnit(testSource, library);
- if (unit != null) {
- request.unit = unit;
- request.node =
- new NodeLocator.con1(completionOffset).searchWithin(unit);
- resolved = true;
- if (!fullAnalysis) {
- break;
- }
- }
- }
- }
-
- result = context.performAnalysisTask();
- }
- if (!resolved) {
- fail('expected unit to be resolved');
- }
+ resolve(fullAnalysis);
return computer.computeFull(request).then(assertFunction);
}
@@ -531,6 +486,55 @@
return cs;
}
+ void resolve(bool fullAnalysis) {
+
+ // Index SDK
+ for (Source librarySource in context.librarySources) {
+ CompilationUnit unit =
+ context.getResolvedCompilationUnit2(librarySource, librarySource);
+ if (unit != null) {
+ index.indexUnit(context, unit);
+ }
+ }
+
+ var result = context.performAnalysisTask();
+ bool resolved = false;
+ while (result.hasMoreWork) {
+
+ // Update the index
+ result.changeNotices.forEach((ChangeNotice notice) {
+ CompilationUnit unit = notice.resolvedDartUnit;
+ if (unit != null) {
+ index.indexUnit(context, unit);
+ }
+ });
+
+ // If the unit has been resolved, then finish the completion
+ List<Source> libSourceList = context.getLibrariesContaining(testSource);
+ if (libSourceList.length > 0) {
+ LibraryElement library = context.getLibraryElement(libSourceList[0]);
+ if (library != null) {
+ CompilationUnit unit =
+ context.getResolvedCompilationUnit(testSource, library);
+ if (unit != null) {
+ request.unit = unit;
+ request.node =
+ new NodeLocator.con1(completionOffset).searchWithin(unit);
+ resolved = true;
+ if (!fullAnalysis) {
+ break;
+ }
+ }
+ }
+ }
+
+ result = context.performAnalysisTask();
+ }
+ if (!resolved) {
+ fail('expected unit to be resolved');
+ }
+ }
+
@override
void setUp() {
super.setUp();
@@ -557,8 +561,8 @@
}
CompletionSuggestion assertSuggestImportedClass(String name,
- [int relevance = DART_RELEVANCE_DEFAULT,
- CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ int relevance: DART_RELEVANCE_DEFAULT}) {
if (computer is ImportedComputer) {
return assertSuggestClass(name, relevance: relevance, kind: kind);
} else {
@@ -576,15 +580,10 @@
}
CompletionSuggestion assertSuggestImportedFunction(
- String name, String returnType, [bool isDeprecated = false,
- int relevance = DART_RELEVANCE_DEFAULT,
- CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
- if (computer is ImportedComputer) {
- return assertSuggestFunction(
- name, returnType, isDeprecated, relevance, kind);
- } else {
- return assertNotSuggested(name);
- }
+ String name, String returnType,
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) {
+ return assertNotSuggested(name);
}
CompletionSuggestion assertSuggestImportedFunctionTypeAlias(
@@ -682,7 +681,8 @@
}
CompletionSuggestion assertSuggestLocalClass(String name,
- {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) {
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) {
return assertNotSuggested(name);
}
@@ -701,8 +701,9 @@
}
CompletionSuggestion assertSuggestLocalFunction(
- String name, String returnType,
- {bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) {
+ String name, String returnType, {bool deprecated: false,
+ int relevance: DART_RELEVANCE_LOCAL_FUNCTION,
+ CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) {
return assertNotSuggested(name);
}
@@ -743,7 +744,7 @@
CompletionSuggestion assertSuggestNonLocalClass(String name,
[int relevance = DART_RELEVANCE_DEFAULT,
CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
- return assertSuggestImportedClass(name, relevance, kind);
+ return assertSuggestImportedClass(name, relevance: relevance, kind: kind);
}
Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) {
@@ -807,6 +808,77 @@
});
}
+ test_ArgumentList_InstanceCreationExpression_functionalArg() {
+ // ArgumentList InstanceCreationExpression ExpressionStatement Block
+ addSource('/libA.dart', '''
+ library A;
+ class A { A(f()) { } }
+ bool hasLength(int expected) { }
+ void baz() { }''');
+ addTestSource('''
+ import 'dart:async';
+ import '/libA.dart';
+ class B { }
+ String bar() => true;
+ void main() {new A(^)}''');
+ computeFast();
+ return computeFull((bool result) {
+ expect(request.replacementOffset, completionOffset);
+ expect(request.replacementLength, 0);
+ assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
+ assertSuggestLocalFunction(
+ 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('hasLength', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('identical', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('A',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('Object',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertNotSuggested('main');
+ assertNotSuggested('baz');
+ assertNotSuggested('print');
+ });
+ }
+
+ test_ArgumentList_InstanceCreationExpression_typedefArg() {
+ // ArgumentList InstanceCreationExpression ExpressionStatement Block
+ addSource('/libA.dart', '''
+ library A;
+ typedef Funct();
+ class A { A(Funct f) { } }
+ bool hasLength(int expected) { }
+ void baz() { }''');
+ addTestSource('''
+ import 'dart:async';
+ import '/libA.dart';
+ class B { }
+ String bar() => true;
+ void main() {new A(^)}''');
+ computeFast();
+ return computeFull((bool result) {
+ expect(request.replacementOffset, completionOffset);
+ expect(request.replacementLength, 0);
+ assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
+ assertSuggestLocalFunction(
+ 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('hasLength', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('identical', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('A',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('Object',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertNotSuggested('main');
+ assertNotSuggested('baz');
+ assertNotSuggested('print');
+ });
+ }
+
test_ArgumentList_local_function() {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/libA.dart', '''
@@ -863,6 +935,73 @@
});
}
+ test_ArgumentList_MethodInvocation_functionalArg() {
+ // ArgumentList MethodInvocation ExpressionStatement Block
+ addSource('/libA.dart', '''
+ library A;
+ class A { A(f()) { } }
+ bool hasLength(int expected) { }
+ void baz() { }''');
+ addTestSource('''
+ import 'dart:async';
+ import '/libA.dart';
+ class B { }
+ String bar(f()) => true;
+ void main() {bar(^);}''');
+ computeFast();
+ return computeFull((bool result) {
+ expect(request.replacementOffset, completionOffset);
+ expect(request.replacementLength, 0);
+ assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
+ assertSuggestLocalFunction(
+ 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('hasLength', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('identical', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('A',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('Object',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertNotSuggested('main');
+ assertNotSuggested('baz');
+ assertNotSuggested('print');
+ });
+ }
+
+ test_ArgumentList_MethodInvocation_methodArg() {
+ // ArgumentList MethodInvocation ExpressionStatement Block
+ addSource('/libA.dart', '''
+ library A;
+ class A { A(f()) { } }
+ bool hasLength(int expected) { }
+ void baz() { }''');
+ addTestSource('''
+ import 'dart:async';
+ import '/libA.dart';
+ class B { String bar(f()) => true; }
+ void main() {new B().bar(^);}''');
+ computeFast();
+ return computeFull((bool result) {
+ expect(request.replacementOffset, completionOffset);
+ expect(request.replacementLength, 0);
+ assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
+ assertSuggestImportedFunction(
+ 'hasLength', 'bool', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedFunction('identical', 'bool',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('A',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertSuggestImportedClass('Object',
+ kind: CompletionSuggestionKind.IDENTIFIER);
+ assertNotSuggested('main');
+ assertNotSuggested('baz');
+ assertNotSuggested('print');
+ });
+ }
+
test_ArgumentList_namedParam() {
// SimpleIdentifier NamedExpression ArgumentList MethodInvocation
// ExpressionStatement
@@ -1135,7 +1274,7 @@
assertNotSuggested('G');
//assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
assertSuggestImportedClass('Object');
- assertSuggestImportedFunction('min', 'num', false);
+ assertSuggestImportedFunction('min', 'num');
//assertSuggestImportedFunction(
// 'max',
// 'num',
@@ -1205,8 +1344,9 @@
assertNotSuggested('_B');
//assertSuggestImportedClass('C');
// hidden element suggested as low relevance
- assertSuggestImportedClass('D', DART_RELEVANCE_LOW);
- assertSuggestImportedFunction('D1', null, true, DART_RELEVANCE_LOW);
+ assertSuggestImportedClass('D', relevance: DART_RELEVANCE_LOW);
+ assertSuggestImportedFunction(
+ 'D1', null, deprecated: true, relevance: DART_RELEVANCE_LOW);
assertSuggestLocalFunction('D2', 'Z');
//assertSuggestImportedClass('EE');
// hidden element suggested as low relevance
@@ -1762,7 +1902,7 @@
expect(request.replacementOffset, completionOffset);
expect(request.replacementLength, 0);
assertSuggestImportedClass('A');
- assertSuggestImportedFunction('F1', '_B', false);
+ assertSuggestImportedFunction('F1', '_B');
assertSuggestLocalClass('C');
assertSuggestLocalMethod('foo', 'C', null);
assertSuggestLocalMethod('bar', 'C', 'void');
@@ -2145,18 +2285,76 @@
test_InterpolationExpression() {
// SimpleIdentifier InterpolationExpression StringInterpolation
- addTestSource('main() {String name; print("hello \$^");}');
+ addSource('/testA.dart', '''
+ int T1;
+ F1() { }
+ typedef D1();
+ class C1 {C1(this.x) { } int x;}''');
+ addTestSource('''
+ import "/testA.dart";
+ int T2;
+ F2() { }
+ typedef D2();
+ class C2 { }
+ main() {String name; print("hello \$^");}''');
computeFast();
return computeFull((bool result) {
expect(request.replacementOffset, completionOffset);
expect(request.replacementLength, 0);
+ assertNotSuggested('Object');
+ // TODO(danrubel) should return top level var rather than getter
+ if (computer is ImportedComputer) {
+ //assertSuggestImportedTopLevelVar('T1', 'int');
+ assertSuggestGetter('T1', 'int');
+ }
+ assertSuggestImportedFunction('F1', null);
+ assertNotSuggested('D1');
+ assertNotSuggested('C1');
+ assertSuggestLocalTopLevelVar('T2', 'int');
+ assertSuggestLocalFunction('F2', null);
+ assertNotSuggested('D2');
+ assertNotSuggested('C2');
assertSuggestLocalVariable('name', 'String');
- assertSuggestImportedClass('Object');
});
}
test_InterpolationExpression_block() {
// SimpleIdentifier InterpolationExpression StringInterpolation
+ addSource('/testA.dart', '''
+ int T1;
+ F1() { }
+ typedef D1();
+ class C1 {C1(this.x) { } int x;}''');
+ addTestSource('''
+ import "/testA.dart";
+ int T2;
+ F2() { }
+ typedef D2();
+ class C2 { }
+ main() {String name; print("hello \${^}");}''');
+ computeFast();
+ return computeFull((bool result) {
+ expect(request.replacementOffset, completionOffset);
+ expect(request.replacementLength, 0);
+ assertSuggestImportedClass('Object');
+ // TODO(danrubel) should return top level var rather than getter
+ if (computer is ImportedComputer) {
+ //assertSuggestImportedTopLevelVar('T1', 'int');
+ assertSuggestGetter('T1', 'int');
+ }
+ assertSuggestImportedFunction('F1', null);
+ assertSuggestImportedFunctionTypeAlias('D1', null);
+ assertSuggestImportedClass('C1');
+ assertSuggestLocalTopLevelVar('T2', 'int');
+ assertSuggestLocalFunction('F2', null);
+ assertSuggestLocalFunctionTypeAlias('D2', null);
+ assertSuggestLocalClass('C2');
+ assertSuggestLocalVariable('name', 'String');
+ });
+ }
+
+ test_InterpolationExpression_block2() {
+ // SimpleIdentifier InterpolationExpression StringInterpolation
addTestSource('main() {String name; print("hello \${n^}");}');
computeFast();
return computeFull((bool result) {
@@ -3004,6 +3202,17 @@
});
}
+ test_VariableDeclarationList_final() {
+ // VariableDeclarationList VariableDeclarationStatement Block
+ addTestSource('main() {final ^} class C { }');
+ computeFast();
+ return computeFull((bool result) {
+ assertSuggestImportedClass('Object');
+ assertSuggestLocalClass('C');
+ assertNotSuggested('==');
+ });
+ }
+
test_VariableDeclarationStatement_RHS() {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement
diff --git a/pkg/analysis_server/test/services/completion/imported_computer_test.dart b/pkg/analysis_server/test/services/completion/imported_computer_test.dart
index 98a10b5..51870d0 100644
--- a/pkg/analysis_server/test/services/completion/imported_computer_test.dart
+++ b/pkg/analysis_server/test/services/completion/imported_computer_test.dart
@@ -43,9 +43,9 @@
* suggestions to the original set of suggestions.
*/
@override
- void assertCachedCompute(_) {
+ assertCachedCompute(_) {
if (!(computer as ImportedComputer).shouldWaitForLowPrioritySuggestions) {
- return;
+ return null;
}
expect(request.unit.element, isNotNull);
List<CompletionSuggestion> oldSuggestions = request.suggestions;
@@ -65,30 +65,45 @@
completionOffset, cache, new CompletionPerformance());
request.replacementOffset = replacementOffset;
request.replacementLength = replacementLength;
- expect(computeFast(), isTrue);
- expect(request.unit.element, isNull);
- List<CompletionSuggestion> newSuggestions = request.suggestions;
- if (newSuggestions.length == oldSuggestions.length) {
- if (!oldSuggestions
- .any((CompletionSuggestion s) => !newSuggestions.contains(s))) {
- return;
+
+ void assertResultsFromCache(List<CompletionSuggestion> oldSuggestions) {
+ List<CompletionSuggestion> newSuggestions = request.suggestions;
+ if (newSuggestions.length == oldSuggestions.length) {
+ if (!oldSuggestions
+ .any((CompletionSuggestion s) => !newSuggestions.contains(s))) {
+ return;
+ }
}
+ StringBuffer sb = new StringBuffer(
+ 'suggestions based upon cached results do not match expectations');
+ sb.write('\n Expected:');
+ oldSuggestions.toList()
+ ..sort(suggestionComparator)
+ ..forEach((CompletionSuggestion suggestion) {
+ sb.write('\n ${suggestion.completion} -> $suggestion');
+ });
+ sb.write('\n Actual:');
+ newSuggestions.toList()
+ ..sort(suggestionComparator)
+ ..forEach((CompletionSuggestion suggestion) {
+ sb.write('\n ${suggestion.completion} -> $suggestion');
+ });
+ fail(sb.toString());
}
- StringBuffer sb = new StringBuffer(
- 'suggestions based upon cached results do not match expectations');
- sb.write('\n Expected:');
- oldSuggestions.toList()
- ..sort(suggestionComparator)
- ..forEach((CompletionSuggestion suggestion) {
- sb.write('\n ${suggestion.completion} -> $suggestion');
+
+ if (computeFast()) {
+ expect(request.unit.element, isNull);
+ assertResultsFromCache(oldSuggestions);
+ } else {
+ // Results from cache might need to be adjusted
+ // if target is a function argument in an argument list
+ resolve(false);
+ return computer.computeFull(request).then((bool result) {
+ expect(result, isTrue);
+ expect(request.unit.element, isNotNull);
+ assertResultsFromCache(oldSuggestions);
});
- sb.write('\n Actual:');
- newSuggestions.toList()
- ..sort(suggestionComparator)
- ..forEach((CompletionSuggestion suggestion) {
- sb.write('\n ${suggestion.completion} -> $suggestion');
- });
- fail(sb.toString());
+ }
}
void assertNotCached(String completion) {
@@ -112,6 +127,15 @@
return assertSuggestField(name, type, relevance: relevance);
}
+ @override
+ CompletionSuggestion assertSuggestImportedFunction(
+ String name, String returnType,
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) {
+ return assertSuggestFunction(name, returnType,
+ kind: kind, deprecated: deprecated, relevance: relevance);
+ }
+
CompletionSuggestion assertSuggestImportedGetter(
String name, String returnType,
{int relevance: DART_RELEVANCE_INHERITED_ACCESSOR}) {
diff --git a/pkg/analysis_server/test/services/completion/local_computer_test.dart b/pkg/analysis_server/test/services/completion/local_computer_test.dart
index 2fa452e..05182d3 100644
--- a/pkg/analysis_server/test/services/completion/local_computer_test.dart
+++ b/pkg/analysis_server/test/services/completion/local_computer_test.dart
@@ -21,9 +21,10 @@
class LocalComputerTest extends AbstractSelectorSuggestionTest {
@override
CompletionSuggestion assertSuggestLocalClass(String name,
- {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) {
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) {
return assertSuggestClass(name,
- relevance: relevance, isDeprecated: isDeprecated);
+ kind: kind, relevance: relevance, isDeprecated: isDeprecated);
}
@override
@@ -47,8 +48,10 @@
@override
CompletionSuggestion assertSuggestLocalFunction(
String name, String returnType,
- {bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) {
- return assertSuggestFunction(name, returnType, deprecated, relevance);
+ {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
+ bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) {
+ return assertSuggestFunction(name, returnType,
+ kind: kind, deprecated: deprecated, relevance: relevance);
}
@override
diff --git a/pkg/analysis_server/test/services/completion/optype_test.dart b/pkg/analysis_server/test/services/completion/optype_test.dart
index e5f0fbc..067c14e 100644
--- a/pkg/analysis_server/test/services/completion/optype_test.dart
+++ b/pkg/analysis_server/test/services/completion/optype_test.dart
@@ -583,7 +583,7 @@
test_InterpolationExpression() {
// SimpleIdentifier InterpolationExpression StringInterpolation
addTestSource('main() {String name; print("hello \$^");}');
- assertOpType(returnValue: true, typeNames: true);
+ assertOpType(returnValue: true);
}
test_InterpolationExpression_block() {
@@ -769,6 +769,12 @@
assertOpType();
}
+ test_VariableDeclarationList_final() {
+ // VariableDeclarationList VariableDeclarationStatement Block
+ addTestSource('main() {final ^}');
+ assertOpType(typeNames: true);
+ }
+
test_VariableDeclarationStatement_afterSemicolon() {
// VariableDeclarationStatement Block BlockFunctionBody
addTestSource('class A {var a; x() {var b;^}}');
diff --git a/pkg/analyzer/lib/src/analyzer_impl.dart b/pkg/analyzer/lib/src/analyzer_impl.dart
index 222aad7..849356f 100644
--- a/pkg/analyzer/lib/src/analyzer_impl.dart
+++ b/pkg/analyzer/lib/src/analyzer_impl.dart
@@ -150,7 +150,7 @@
new DartUriResolver(sdk),
new FileUriResolver()
];
- // may be add package resolver
+ // maybe add package resolver
{
JavaFile packageDirectory;
if (options.packageRootPath != null) {
@@ -187,6 +187,8 @@
contextOptions.hint = !options.disableHints;
contextOptions.analyzeFunctionBodiesPredicate =
_analyzeFunctionBodiesPredicate;
+ contextOptions.generateImplicitErrors = options.showPackageWarnings;
+ contextOptions.generateSdkErrors = options.showSdkWarnings;
context.analysisOptions = contextOptions;
// Create and add a ChangeSet
diff --git a/pkg/analyzer/lib/src/generated/engine.dart b/pkg/analyzer/lib/src/generated/engine.dart
index c5e99c1..4625d2c 100644
--- a/pkg/analyzer/lib/src/generated/engine.dart
+++ b/pkg/analyzer/lib/src/generated/engine.dart
@@ -959,8 +959,14 @@
AnalysisOptionsImpl _options = new AnalysisOptionsImpl();
/**
- * A flag indicating whether errors related to sources in the SDK should be generated and
- * reported.
+ * A flag indicating whether errors related to implicitly analyzed sources
+ * should be generated and reported.
+ */
+ bool _generateImplicitErrors = true;
+
+ /**
+ * A flag indicating whether errors related to sources in the SDK should be
+ * generated and reported.
*/
bool _generateSdkErrors = true;
@@ -1115,6 +1121,7 @@
void set analysisOptions(AnalysisOptions options) {
bool needsRecompute = this._options.analyzeFunctionBodiesPredicate !=
options.analyzeFunctionBodiesPredicate ||
+ this._options.generateImplicitErrors != options.generateImplicitErrors ||
this._options.generateSdkErrors != options.generateSdkErrors ||
this._options.dart2jsHint != options.dart2jsHint ||
(this._options.hint && !options.hint) ||
@@ -1140,6 +1147,7 @@
}
this._options.analyzeFunctionBodiesPredicate =
options.analyzeFunctionBodiesPredicate;
+ this._options.generateImplicitErrors = options.generateImplicitErrors;
this._options.generateSdkErrors = options.generateSdkErrors;
this._options.dart2jsHint = options.dart2jsHint;
this._options.hint = options.hint;
@@ -1148,6 +1156,7 @@
this._options.incrementalValidation = options.incrementalValidation;
this._options.lint = options.lint;
this._options.preserveComments = options.preserveComments;
+ _generateImplicitErrors = options.generateImplicitErrors;
_generateSdkErrors = options.generateSdkErrors;
if (needsRecompute) {
_invalidateAllLocalResolutionInformation(false);
@@ -2584,6 +2593,12 @@
// These values are not currently being computed, so their state
// is not interesting.
continue;
+ } else if (!sourceEntry.explicitlyAdded &&
+ !_generateImplicitErrors &&
+ (descriptor == DartEntry.VERIFICATION_ERRORS ||
+ descriptor == DartEntry.HINTS ||
+ descriptor == DartEntry.LINTS)) {
+ continue;
} else if (source.isInSystemLibrary &&
!_generateSdkErrors &&
(descriptor == DartEntry.VERIFICATION_ERRORS ||
@@ -2604,6 +2619,20 @@
}
/**
+ * Return `true` if errors should be produced for the given [source]. The
+ * [dartEntry] associated with the source is passed in for efficiency.
+ */
+ bool _shouldErrorsBeAnalyzed(Source source, DartEntry dartEntry) {
+ if (source.isInSystemLibrary) {
+ return _generateSdkErrors;
+ } else if (!dartEntry.explicitlyAdded) {
+ return _generateImplicitErrors;
+ } else {
+ return true;
+ }
+ }
+
+ /**
* Visit all entries of the content cache.
*/
void visitContentCache(ContentCacheVisitor visitor) {
@@ -3846,7 +3875,7 @@
return new AnalysisContextImpl_TaskData(
new ResolveDartLibraryTask(this, source, librarySource), false);
}
- if (_generateSdkErrors || !source.isInSystemLibrary) {
+ if (_shouldErrorsBeAnalyzed(source, dartEntry)) {
CacheState verificationErrorsState = dartEntry.getStateInLibrary(
DartEntry.VERIFICATION_ERRORS, librarySource);
if (verificationErrorsState == CacheState.INVALID ||
@@ -4062,7 +4091,7 @@
return;
}
}
- if (_generateSdkErrors || !source.isInSystemLibrary) {
+ if (_shouldErrorsBeAnalyzed(source, dartEntry)) {
CacheState verificationErrorsState = dartEntry.getStateInLibrary(
DartEntry.VERIFICATION_ERRORS, librarySource);
if (verificationErrorsState == CacheState.INVALID ||
@@ -6295,8 +6324,8 @@
class AnalysisNotScheduledError implements Exception {}
/**
- * The interface `AnalysisOptions` defines the behavior of objects that provide access to a
- * set of analysis options used to control the behavior of an analysis context.
+ * A set of analysis options used to control the behavior of an analysis
+ * context.
*/
abstract class AnalysisOptions {
/**
@@ -6308,7 +6337,7 @@
* This getter is deprecated; consider using [analyzeFunctionBodiesPredicate]
* instead.
*/
- @deprecated
+ @deprecated // Use this.analyzeFunctionBodiesPredicate
bool get analyzeFunctionBodies;
/**
@@ -6318,61 +6347,54 @@
AnalyzeFunctionBodiesPredicate get analyzeFunctionBodiesPredicate;
/**
- * Return the maximum number of sources for which AST structures should be kept in the cache.
- *
- * @return the maximum number of sources for which AST structures should be kept in the cache
+ * Return the maximum number of sources for which AST structures should be
+ * kept in the cache.
*/
int get cacheSize;
/**
* Return `true` if analysis is to generate dart2js related hint results.
- *
- * @return `true` if analysis is to generate dart2js related hint results
*/
bool get dart2jsHint;
/**
* Return `true` if analysis is to include the new async support.
*/
- @deprecated
+ @deprecated // Always true
bool get enableAsync;
/**
* Return `true` if analysis is to include the new deferred loading support.
- *
- * @return `true` if analysis is to include the new deferred loading support
*/
- @deprecated
+ @deprecated // Always true
bool get enableDeferredLoading;
/**
* Return `true` if analysis is to include the new enum support.
- *
- * @return `true` if analysis is to include the new enum support
*/
- @deprecated
+ @deprecated // Always true
bool get enableEnum;
/**
- * Return `true` if errors, warnings and hints should be generated for sources in the SDK.
- * The default value is `false`.
- *
- * @return `true` if errors, warnings and hints should be generated for the SDK
+ * Return `true` if errors, warnings and hints should be generated for sources
+ * that are implicitly being analyzed. The default value is `true`.
+ */
+ bool get generateImplicitErrors;
+
+ /**
+ * Return `true` if errors, warnings and hints should be generated for sources
+ * in the SDK. The default value is `false`.
*/
bool get generateSdkErrors;
/**
- * Return `true` if analysis is to generate hint results (e.g. type inference based
- * information and pub best practices).
- *
- * @return `true` if analysis is to generate hint results
+ * Return `true` if analysis is to generate hint results (e.g. type inference
+ * based information and pub best practices).
*/
bool get hint;
/**
* Return `true` if incremental analysis should be used.
- *
- * @return `true` if incremental analysis should be used
*/
bool get incremental;
@@ -6390,22 +6412,18 @@
/**
* Return `true` if analysis is to generate lint warnings.
- *
- * @return `true` if analysis is to generate lint warnings
*/
bool get lint;
/**
* Return `true` if analysis is to parse comments.
- *
- * @return `true` if analysis is to parse comments
*/
bool get preserveComments;
}
/**
- * Instances of the class `AnalysisOptions` represent a set of analysis options used to
- * control the behavior of an analysis context.
+ * A set of analysis options used to control the behavior of an analysis
+ * context.
*/
class AnalysisOptionsImpl implements AnalysisOptions {
/**
@@ -6433,24 +6451,32 @@
_analyzeAllFunctionBodies;
/**
- * The maximum number of sources for which AST structures should be kept in the cache.
+ * The maximum number of sources for which AST structures should be kept in
+ * the cache.
*/
int cacheSize = DEFAULT_CACHE_SIZE;
/**
- * A flag indicating whether analysis is to generate dart2js related hint results.
+ * A flag indicating whether analysis is to generate dart2js related hint
+ * results.
*/
bool dart2jsHint = true;
/**
- * A flag indicating whether errors, warnings and hints should be generated for sources in the
- * SDK.
+ * A flag indicating whether errors, warnings and hints should be generated
+ * for sources that are implicitly being analyzed.
*/
- bool _generateSdkErrors = false;
+ bool generateImplicitErrors = true;
/**
- * A flag indicating whether analysis is to generate hint results (e.g. type inference based
- * information and pub best practices).
+ * A flag indicating whether errors, warnings and hints should be generated
+ * for sources in the SDK.
+ */
+ bool generateSdkErrors = false;
+
+ /**
+ * A flag indicating whether analysis is to generate hint results (e.g. type
+ * inference based information and pub best practices).
*/
bool hint = true;
@@ -6482,21 +6508,21 @@
bool preserveComments = true;
/**
- * Initialize a newly created set of analysis options to have their default values.
+ * Initialize a newly created set of analysis options to have their default
+ * values.
*/
AnalysisOptionsImpl();
/**
- * Initialize a newly created set of analysis options to have the same values as those in the
- * given set of analysis options.
- *
- * @param options the analysis options whose values are being copied
+ * Initialize a newly created set of analysis options to have the same values
+ * as those in the given set of analysis [options].
*/
AnalysisOptionsImpl.con1(AnalysisOptions options) {
analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate;
cacheSize = options.cacheSize;
dart2jsHint = options.dart2jsHint;
- _generateSdkErrors = options.generateSdkErrors;
+ generateImplicitErrors = options.generateImplicitErrors;
+ generateSdkErrors = options.generateSdkErrors;
hint = options.hint;
incremental = options.incremental;
incrementalApi = options.incrementalApi;
@@ -6562,20 +6588,6 @@
// Enum support cannot be disabled
}
- @override
- bool get generateSdkErrors => _generateSdkErrors;
-
- /**
- * Set whether errors, warnings and hints should be generated for sources in the SDK to match the
- * given value.
- *
- * @param generate `true` if errors, warnings and hints should be generated for sources in
- * the SDK
- */
- void set generateSdkErrors(bool generate) {
- _generateSdkErrors = generate;
- }
-
/**
* Predicate used for [analyzeFunctionBodiesPredicate] when
* [analyzeFunctionBodies] is set to `true`.
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index 2ecf17e..e491d91 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -2692,8 +2692,8 @@
!_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
Directive directive = _parseDirective(commentAndMetadata);
if (declarations.length > 0 && !directiveFoundAfterDeclaration) {
- _reportErrorForCurrentToken(
- ParserErrorCode.DIRECTIVE_AFTER_DECLARATION);
+ _reportErrorForToken(
+ ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, directive.beginToken);
directiveFoundAfterDeclaration = true;
}
if (directive is LibraryDirective) {
diff --git a/pkg/analyzer/test/generated/engine_test.dart b/pkg/analyzer/test/generated/engine_test.dart
index 57ee31a..35e9660 100644
--- a/pkg/analyzer/test/generated/engine_test.dart
+++ b/pkg/analyzer/test/generated/engine_test.dart
@@ -2198,6 +2198,7 @@
options.analyzeFunctionBodies = booleanValue;
options.cacheSize = i;
options.dart2jsHint = booleanValue;
+ options.generateImplicitErrors = booleanValue;
options.generateSdkErrors = booleanValue;
options.hint = booleanValue;
options.incremental = booleanValue;
@@ -2206,6 +2207,7 @@
expect(copy.analyzeFunctionBodies, options.analyzeFunctionBodies);
expect(copy.cacheSize, options.cacheSize);
expect(copy.dart2jsHint, options.dart2jsHint);
+ expect(copy.generateImplicitErrors, options.generateImplicitErrors);
expect(copy.generateSdkErrors, options.generateSdkErrors);
expect(copy.hint, options.hint);
expect(copy.incremental, options.incremental);
@@ -2213,14 +2215,14 @@
}
}
- void test_getAnalyzeFunctionBodies() {
+ void test_analyzeFunctionBodies() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
bool value = !options.analyzeFunctionBodies;
options.analyzeFunctionBodies = value;
expect(options.analyzeFunctionBodies, value);
}
- void test_getCacheSize() {
+ void test_cacheSize() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
expect(options.cacheSize, AnalysisOptionsImpl.DEFAULT_CACHE_SIZE);
int value = options.cacheSize + 1;
@@ -2228,35 +2230,42 @@
expect(options.cacheSize, value);
}
- void test_getDart2jsHint() {
+ void test_dart2jsHint() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
bool value = !options.dart2jsHint;
options.dart2jsHint = value;
expect(options.dart2jsHint, value);
}
- void test_getGenerateSdkErrors() {
+ void test_generateImplicitErrors() {
+ AnalysisOptionsImpl options = new AnalysisOptionsImpl();
+ bool value = !options.generateImplicitErrors;
+ options.generateImplicitErrors = value;
+ expect(options.generateImplicitErrors, value);
+ }
+
+ void test_generateSdkErrors() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
bool value = !options.generateSdkErrors;
options.generateSdkErrors = value;
expect(options.generateSdkErrors, value);
}
- void test_getHint() {
+ void test_hint() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
bool value = !options.hint;
options.hint = value;
expect(options.hint, value);
}
- void test_getIncremental() {
+ void test_incremental() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
bool value = !options.incremental;
options.incremental = value;
expect(options.incremental, value);
}
- void test_getPreserveComments() {
+ void test_preserveComments() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
bool value = !options.preserveComments;
options.preserveComments = value;
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 89f83f1..ca1eb93 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -362,6 +362,8 @@
AnalysisOptions currentOptions = analysisOptions;
bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate !=
options.analyzeFunctionBodiesPredicate ||
+ currentOptions.generateImplicitErrors !=
+ options.generateImplicitErrors ||
currentOptions.generateSdkErrors != options.generateSdkErrors ||
currentOptions.dart2jsHint != options.dart2jsHint ||
(currentOptions.hint && !options.hint) ||
diff --git a/tools/VERSION b/tools/VERSION
index 2e90988..8c63f7d 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -28,4 +28,4 @@
MINOR 9
PATCH 0
PRERELEASE 10
-PRERELEASE_PATCH 2
+PRERELEASE_PATCH 3