Fix several tests when the new task model is enabled
R=scheglov@google.com
Review URL: https://codereview.chromium.org//1164223002
diff --git a/pkg/analyzer/lib/src/context/context.dart b/pkg/analyzer/lib/src/context/context.dart
index 7fb0d1c..4dcc143 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -350,6 +350,9 @@
List<AnalysisTarget> get priorityTargets => prioritySources;
@override
+ CachePartition get privateAnalysisCachePartition => _privatePartition;
+
+ @override
SourceFactory get sourceFactory => _sourceFactory;
@override
@@ -767,38 +770,39 @@
@override
List<Source> getHtmlFilesReferencing(Source source) {
+ // TODO(brianwilkerson) Implement this.
SourceKind sourceKind = getKindOf(source);
if (sourceKind == null) {
return Source.EMPTY_LIST;
}
List<Source> htmlSources = <Source>[];
- while (true) {
- if (sourceKind == SourceKind.PART) {
- List<Source> librarySources = getLibrariesContaining(source);
- for (Source source in _cache.sources) {
- CacheEntry entry = _cache.get(source);
- if (entry.getValue(SOURCE_KIND) == SourceKind.HTML) {
- List<Source> referencedLibraries =
- (entry as HtmlEntry).getValue(HtmlEntry.REFERENCED_LIBRARIES);
- if (_containsAny(referencedLibraries, librarySources)) {
- htmlSources.add(source);
- }
- }
- }
- } else {
- for (Source source in _cache.sources) {
- CacheEntry entry = _cache.get(source);
- if (entry.getValue(SOURCE_KIND) == SourceKind.HTML) {
- List<Source> referencedLibraries =
- (entry as HtmlEntry).getValue(HtmlEntry.REFERENCED_LIBRARIES);
- if (_contains(referencedLibraries, source)) {
- htmlSources.add(source);
- }
- }
- }
- }
- break;
- }
+// while (true) {
+// if (sourceKind == SourceKind.PART) {
+// List<Source> librarySources = getLibrariesContaining(source);
+// for (Source source in _cache.sources) {
+// CacheEntry entry = _cache.get(source);
+// if (entry.getValue(SOURCE_KIND) == SourceKind.HTML) {
+// List<Source> referencedLibraries =
+// (entry as HtmlEntry).getValue(HtmlEntry.REFERENCED_LIBRARIES);
+// if (_containsAny(referencedLibraries, librarySources)) {
+// htmlSources.add(source);
+// }
+// }
+// }
+// } else {
+// for (Source source in _cache.sources) {
+// CacheEntry entry = _cache.get(source);
+// if (entry.getValue(SOURCE_KIND) == SourceKind.HTML) {
+// List<Source> referencedLibraries =
+// (entry as HtmlEntry).getValue(HtmlEntry.REFERENCED_LIBRARIES);
+// if (_contains(referencedLibraries, source)) {
+// htmlSources.add(source);
+// }
+// }
+// }
+// }
+// break;
+// }
if (htmlSources.isEmpty) {
return Source.EMPTY_LIST;
}
@@ -1174,8 +1178,8 @@
@override
void visitCacheItems(void callback(Source source, SourceEntry dartEntry,
DataDescriptor rowDesc, CacheState state)) {
- // TODO(brianwilkerson) Figure out where this is used and adjust the call
- // sites to use CacheEntry's.
+ // TODO(brianwilkerson) Figure out where this is used and either remove it
+ // or adjust the call sites to use CacheEntry's.
// bool hintsEnabled = _options.hint;
// bool lintsEnabled = _options.lint;
// MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator();
@@ -1561,9 +1565,6 @@
}
}
- @override
- CachePartition get privateAnalysisCachePartition => _privatePartition;
-
/**
* Remove the given [source] from the priority order if it is in the list.
*/
diff --git a/pkg/analyzer/lib/src/generated/testing/element_factory.dart b/pkg/analyzer/lib/src/generated/testing/element_factory.dart
index 164a666..c648e03 100644
--- a/pkg/analyzer/lib/src/generated/testing/element_factory.dart
+++ b/pkg/analyzer/lib/src/generated/testing/element_factory.dart
@@ -15,7 +15,9 @@
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/resolver.dart';
+import 'package:analyzer/src/generated/scanner.dart';
import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
import 'package:path/path.dart';
@@ -516,8 +518,16 @@
static TopLevelVariableElementImpl topLevelVariableElement3(
String name, bool isConst, bool isFinal, DartType type) {
- TopLevelVariableElementImpl variable =
- new TopLevelVariableElementImpl(name, -1);
+ TopLevelVariableElementImpl variable;
+ if (isConst) {
+ ConstTopLevelVariableElementImpl constant =
+ new ConstTopLevelVariableElementImpl(AstFactory.identifier3(name));
+ constant.constantInitializer = AstFactory.instanceCreationExpression2(
+ Keyword.CONST, AstFactory.typeName(type.element));
+ variable = constant;
+ } else {
+ variable = new TopLevelVariableElementImpl(name, -1);
+ }
variable.const3 = isConst;
variable.final2 = isFinal;
variable.synthetic = true;
diff --git a/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart b/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
index fe0c24b..f24b96b 100644
--- a/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
+++ b/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
@@ -7,10 +7,14 @@
library engine.testing.test_type_provider;
+import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/resolver.dart';
+import 'package:analyzer/src/generated/scanner.dart';
+import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/testing/element_factory.dart';
+import 'package:analyzer/src/generated/testing/token_factory.dart';
/**
* A type provider that can be used by tests without creating the element model
@@ -178,10 +182,13 @@
if (_deprecatedType == null) {
ClassElementImpl deprecatedElement =
ElementFactory.classElement2("Deprecated");
- deprecatedElement.constructors = <ConstructorElement>[
- ElementFactory.constructorElement(
- deprecatedElement, null, true, [stringType])
+ ConstructorElementImpl constructor = ElementFactory.constructorElement(
+ deprecatedElement, null, true, [stringType]);
+ constructor.constantInitializers = <ConstructorInitializer>[
+ AstFactory.constructorFieldInitializer(
+ true, 'expires', AstFactory.identifier3('expires'))
];
+ deprecatedElement.constructors = <ConstructorElement>[constructor];
_deprecatedType = deprecatedElement.type;
}
return _deprecatedType;
@@ -369,9 +376,10 @@
if (_objectType == null) {
ClassElementImpl objectElement = ElementFactory.object;
_objectType = objectElement.type;
- objectElement.constructors = <ConstructorElement>[
- ElementFactory.constructorElement2(objectElement, null)
- ];
+ ConstructorElementImpl constructor =
+ ElementFactory.constructorElement(objectElement, null, true);
+ constructor.constantInitializers = <ConstructorInitializer>[];
+ objectElement.constructors = <ConstructorElement>[constructor];
objectElement.methods = <MethodElement>[
ElementFactory.methodElement("toString", stringType),
ElementFactory.methodElement("==", boolType, [_objectType]),
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 22faa57..5929e06 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -127,6 +127,7 @@
coreContext.setContents(coreSource, "");
coreUnit.librarySource = coreUnit.source = coreSource;
ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy");
+ ClassElement objectClassElement = provider.objectType.element;
coreUnit.types = <ClassElement>[
provider.boolType.element,
provider.deprecatedType.element,
@@ -139,7 +140,7 @@
provider.mapType.element,
provider.nullType.element,
provider.numType.element,
- provider.objectType.element,
+ objectClassElement,
proxyClassElement,
provider.stackTraceType.element,
provider.stringType.element,
@@ -148,18 +149,19 @@
];
coreUnit.functions = <FunctionElement>[
ElementFactory.functionElement3("identical", provider.boolType.element,
- <ClassElement>[
- provider.objectType.element,
- provider.objectType.element
- ], null),
+ <ClassElement>[objectClassElement, objectClassElement], null),
ElementFactory.functionElement3("print", VoidTypeImpl.instance.element,
- <ClassElement>[provider.objectType.element], null)
+ <ClassElement>[objectClassElement], null)
];
TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory
.topLevelVariableElement3("proxy", true, false, proxyClassElement.type);
- TopLevelVariableElement deprecatedTopLevelVariableElt = ElementFactory
- .topLevelVariableElement3(
+ ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt =
+ ElementFactory.topLevelVariableElement3(
"deprecated", true, false, provider.deprecatedType);
+ deprecatedTopLevelVariableElt.constantInitializer = AstFactory
+ .instanceCreationExpression2(Keyword.CONST,
+ AstFactory.typeName(provider.deprecatedType.element),
+ [AstFactory.string2('next release')]);
coreUnit.accessors = <PropertyAccessorElement>[
proxyTopLevelVariableElt.getter,
deprecatedTopLevelVariableElt.getter
@@ -7998,27 +8000,25 @@
}
/**
- * Verify that all of the identifiers in the compilation units associated with the given sources
- * have been resolved.
- *
- * @param resolvedElementMap a table mapping the AST nodes that have been resolved to the element
- * to which they were resolved
- * @param sources the sources identifying the compilation units to be verified
- * @throws Exception if the contents of the compilation unit cannot be accessed
+ * Verify that all of the identifiers in the compilation units associated with
+ * the given [sources] have been resolved.
*/
void verify(List<Source> sources) {
ResolutionVerifier verifier = new ResolutionVerifier();
for (Source source in sources) {
- analysisContext2.parseCompilationUnit(source).accept(verifier);
+ List<Source> libraries = analysisContext2.getLibrariesContaining(source);
+ for (Source library in libraries) {
+ analysisContext2
+ .resolveCompilationUnit2(source, library)
+ .accept(verifier);
+ }
}
verifier.assertResolved();
}
/**
- * Create a source object representing a file with the given name and give it an empty content.
- *
- * @param fileName the name of the file for which a source is to be created
- * @return the source that was created
+ * Create a source object representing a file with the given [fileName] and
+ * give it an empty content. Return the source that was created.
*/
FileBasedSource _createNamedSource(String fileName) {
FileBasedSource source =