Skip to content

Commit

Permalink
Fix several tests when the new task model is enabled
Browse files Browse the repository at this point in the history
R=scheglov@google.com

Review URL: https://codereview.chromium.org//1164223002
  • Loading branch information
bwilkerson committed Jun 8, 2015
1 parent cb86eb6 commit 7230007
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 60 deletions.
65 changes: 33 additions & 32 deletions pkg/analyzer/lib/src/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@override
List<AnalysisTarget> get priorityTargets => prioritySources;

@override
CachePartition get privateAnalysisCachePartition => _privatePartition;

@override
SourceFactory get sourceFactory => _sourceFactory;

Expand Down Expand Up @@ -767,38 +770,39 @@ class AnalysisContextImpl implements InternalAnalysisContext {

@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;
}
Expand Down Expand Up @@ -1174,8 +1178,8 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@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();
Expand Down Expand Up @@ -1561,9 +1565,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
}

@override
CachePartition get privateAnalysisCachePartition => _privatePartition;

/**
* Remove the given [source] from the priority order if it is in the list.
*/
Expand Down
14 changes: 12 additions & 2 deletions pkg/analyzer/lib/src/generated/testing/element_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import 'package:analyzer/src/generated/element.dart';
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';

Expand Down Expand Up @@ -516,8 +518,16 @@ class ElementFactory {

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;
Expand Down
20 changes: 14 additions & 6 deletions pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,10 +182,13 @@ class TestTypeProvider implements TypeProvider {
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;
Expand Down Expand Up @@ -369,9 +376,10 @@ class TestTypeProvider implements TypeProvider {
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]),
Expand Down
40 changes: 20 additions & 20 deletions pkg/analyzer/test/generated/resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class AnalysisContextFactory {
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,
Expand All @@ -139,7 +140,7 @@ class AnalysisContextFactory {
provider.mapType.element,
provider.nullType.element,
provider.numType.element,
provider.objectType.element,
objectClassElement,
proxyClassElement,
provider.stackTraceType.element,
provider.stringType.element,
Expand All @@ -148,18 +149,19 @@ class AnalysisContextFactory {
];
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
Expand Down Expand Up @@ -7998,27 +8000,25 @@ class ResolverTestCase extends EngineTestCase {
}

/**
* 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 =
Expand Down

0 comments on commit 7230007

Please sign in to comment.