refactor(dart/analyzer plugin): update to latest version of plugins

Closes #3681
This commit is contained in:
keertip 2015-08-17 10:30:03 -07:00 committed by Keerti Parthasarathy
parent 5725f71777
commit a191c89193
7 changed files with 59 additions and 79 deletions

View File

@ -9,7 +9,7 @@ homepage: <%= packageJson.homepage %>
environment: environment:
sdk: '>=1.10.0 <2.0.0' sdk: '>=1.10.0 <2.0.0'
dependencies: dependencies:
analyzer: '>=0.24.4 <0.26.0' analyzer: '>=0.24.4 <0.27.0'
barback: '^0.15.2+2' barback: '^0.15.2+2'
code_transformers: '^0.2.8' code_transformers: '^0.2.8'
dart_style: '>=0.1.8 <0.3.0' dart_style: '>=0.1.8 <0.3.0'

View File

@ -1,13 +1,12 @@
library angular2.src.analysis.analyzer_plugin; library angular2.src.analysis.analyzer_plugin;
import 'package:analyzer/plugin/plugin.dart'; import 'package:plugin/plugin.dart';
import 'package:analyzer/plugin/task.dart'; import 'package:analyzer/plugin/task.dart';
import 'src/tasks.dart'; import 'src/tasks.dart';
/// Contribute a plugin to the dart analyzer for analysis of /// Contribute a plugin to the dart analyzer for analysis of
/// Angular 2 dart code. /// Angular 2 dart code.
class AngularAnalyzerPlugin implements Plugin { class AngularAnalyzerPlugin implements Plugin {
/// The unique identifier for this plugin. /// The unique identifier for this plugin.
static const String UNIQUE_IDENTIFIER = 'angular2.analysis'; static const String UNIQUE_IDENTIFIER = 'angular2.analysis';

View File

@ -8,6 +8,7 @@ import 'package:analyzer/task/model.dart';
import 'package:angular2/src/render/api.dart'; import 'package:angular2/src/render/api.dart';
import 'package:angular2/src/transform/common/directive_metadata_reader.dart'; import 'package:angular2/src/transform/common/directive_metadata_reader.dart';
/// The [RenderDirectiveMetadata]s of a [LibrarySpecificUnit]. /// The [RenderDirectiveMetadata]s of a [LibrarySpecificUnit].
final ListResultDescriptor<RenderDirectiveMetadata> DIRECTIVES = final ListResultDescriptor<RenderDirectiveMetadata> DIRECTIVES =
new ListResultDescriptor<RenderDirectiveMetadata>('ANGULAR2_DIRECTIVES', null); new ListResultDescriptor<RenderDirectiveMetadata>('ANGULAR2_DIRECTIVES', null);
@ -29,6 +30,7 @@ class BuildUnitDirectivesTask extends SourceBasedAnalysisTask {
@override @override
void internalPerform() { void internalPerform() {
CompilationUnit unit = getRequiredInput(UNIT_INPUT); CompilationUnit unit = getRequiredInput(UNIT_INPUT);
List<RenderDirectiveMetadata> metaList = <RenderDirectiveMetadata>[]; List<RenderDirectiveMetadata> metaList = <RenderDirectiveMetadata>[];
for (CompilationUnitMember unitMember in unit.declarations) { for (CompilationUnitMember unitMember in unit.declarations) {
if (unitMember is ClassDeclaration) { if (unitMember is ClassDeclaration) {

View File

@ -5,5 +5,6 @@ import 'package:analyzer/task/model.dart';
/// The analysis errors associated with a target. /// The analysis errors associated with a target.
/// The value combines errors represented by multiple other results. /// The value combines errors represented by multiple other results.
final CompositeResultDescriptor<List<AnalysisError>> HTML_ERRORS = final ListResultDescriptor<AnalysisError> HTML_ERRORS =
new CompositeResultDescriptor<List<AnalysisError>>('ANGULAR_HTML_ERRORS'); new ListResultDescriptor<AnalysisError>(
'ANGULAR_HTML_ERRORS', AnalysisError.NO_ERRORS);

View File

@ -5,7 +5,8 @@ environment:
sdk: '>=1.9.0 <2.0.0' sdk: '>=1.9.0 <2.0.0'
dependencies: dependencies:
angular2: '0.0.0' angular2: '0.0.0'
analyzer: '^0.24.4' analyzer: '>=0.25.1 <0.27.0'
plugin: "^0.1.0"
dev_dependencies: dev_dependencies:
test_reflective_loader: '^0.0.3' test_reflective_loader: '^0.0.3'
typed_mock: '^0.0.4' typed_mock: '^0.0.4'

View File

@ -2,7 +2,10 @@ library test.src.mock_sdk;
import 'package:analyzer/file_system/file_system.dart' as resource; import 'package:analyzer/file_system/file_system.dart' as resource;
import 'package:analyzer/file_system/memory_file_system.dart' as resource; import 'package:analyzer/file_system/memory_file_system.dart' as resource;
import 'package:analyzer/src/generated/engine.dart'; import 'package:analyzer/src/context/cache.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/generated/engine.dart'
show AnalysisEngine, ChangeSet;
import 'package:analyzer/src/generated/sdk.dart'; import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart'; import 'package:analyzer/src/generated/source.dart';
@ -173,7 +176,7 @@ class HtmlElement {}
/** /**
* The [AnalysisContext] which is used for all of the sources. * The [AnalysisContext] which is used for all of the sources.
*/ */
InternalAnalysisContext _analysisContext; AnalysisContextImpl _analysisContext;
MockSdk() { MockSdk() {
LIBRARIES.forEach((_MockSdkLibrary library) { LIBRARIES.forEach((_MockSdkLibrary library) {
@ -182,9 +185,9 @@ class HtmlElement {}
} }
@override @override
AnalysisContext get context { AnalysisContextImpl get context {
if (_analysisContext == null) { if (_analysisContext == null) {
_analysisContext = new SdkAnalysisContext(); _analysisContext = new _SdkAnalysisContext(this);
SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); SourceFactory factory = new SourceFactory([new DartUriResolver(this)]);
_analysisContext.sourceFactory = factory; _analysisContext.sourceFactory = factory;
ChangeSet changeSet = new ChangeSet(); ChangeSet changeSet = new ChangeSet();
@ -309,3 +312,22 @@ class _MockSdkLibrary implements SdkLibrary {
UnimplementedError get unimplemented => new UnimplementedError(); UnimplementedError get unimplemented => new UnimplementedError();
} }
/**
* An [AnalysisContextImpl] that only contains sources for a Dart SDK.
*/
class _SdkAnalysisContext extends AnalysisContextImpl {
final DartSdk sdk;
_SdkAnalysisContext(this.sdk);
@override
AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
if (factory == null) {
return super.createCacheFromSourceFactory(factory);
}
return new AnalysisCache(<CachePartition>[
AnalysisEngine.instance.partitionManager_new.forSdk(sdk)
]);
}
}

View File

@ -3,21 +3,17 @@ library angular2.src.analysis.analyzer_plugin.src.tasks_test;
import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart'; import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/context/cache.dart'; import 'package:analyzer/src/context/cache.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/generated/engine.dart' import 'package:analyzer/src/generated/engine.dart'
show AnalysisOptionsImpl, TimestampedData; show AnalysisOptionsImpl, TimestampedData, AnalysisEngine;
import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/sdk.dart'; import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart'; import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/task/dart.dart';
import 'package:analyzer/src/task/driver.dart'; import 'package:analyzer/src/task/driver.dart';
import 'package:analyzer/src/task/general.dart';
import 'package:analyzer/src/task/manager.dart';
import 'package:analyzer/task/dart.dart'; import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/model.dart'; import 'package:analyzer/task/model.dart';
import 'package:angular2/src/render/api.dart'; import 'package:angular2/src/render/api.dart';
import 'package:angular2_analyzer_plugin/src/tasks.dart'; import 'package:angular2_analyzer_plugin/src/tasks.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:typed_mock/typed_mock.dart';
import 'package:unittest/unittest.dart'; import 'package:unittest/unittest.dart';
import 'mock_sdk.dart'; import 'mock_sdk.dart';
@ -33,16 +29,17 @@ class BuildUnitDirectivesTaskTest extends _AbstractDartTaskTest {
void test_Component() { void test_Component() {
_addAngularSources(); _addAngularSources();
Source source = _newSource('/test.dart', r''' Source source = _newSource('/test.dart', r'''
import '/angular2/metadata.dart'; import '/angular2/metadata.dart';
@Component(selector: 'comp-a') @Component(selector: 'comp-a')
class ComponentA { class ComponentA {
} }
@Component(selector: 'comp-b') @Component(selector: 'comp-b')
class ComponentB { class ComponentB {
} }
'''); ''');
LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
_computeResult(target, DIRECTIVES); _computeResult(target, DIRECTIVES);
@ -56,7 +53,9 @@ class ComponentB {
void test_Directive() { void test_Directive() {
_addAngularSources(); _addAngularSources();
Source source = _newSource('/test.dart', r''' Source source = _newSource('/test.dart', r'''
import '/angular2/metadata.dart'; import '/angular2/metadata.dart';
@Directive(selector: 'deco-a') @Directive(selector: 'deco-a')
@ -78,7 +77,10 @@ class ComponentB {
} }
void _addAngularSources() { void _addAngularSources() {
_newSource('/angular2/metadata.dart', r''' _newSource('/angular2/metadata.dart', r'''
library angular2.src.core.metadata; library angular2.src.core.metadata;
abstract class Directive { abstract class Directive {
@ -118,54 +120,31 @@ class _AbstractDartTaskTest {
Source emptySource; Source emptySource;
DartSdk sdk = new MockSdk(); DartSdk sdk = new MockSdk();
_MockContext context = new _MockContext(); AnalysisContextImpl context;
Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{};
TaskManager taskManager = new TaskManager();
AnalysisDriver analysisDriver; AnalysisDriver analysisDriver;
AnalysisTask task; AnalysisTask task;
Map<ResultDescriptor<dynamic>, dynamic> outputs; Map<ResultDescriptor<dynamic>, dynamic> outputs;
CacheEntry getCacheEntry(AnalysisTarget target) { CacheEntry getCacheEntry(AnalysisTarget target) {
return entryMap.putIfAbsent(target, () => new CacheEntry()); return entryMap.putIfAbsent(target, () => new CacheEntry(target));
} }
void setUp() { void setUp() {
emptySource = _newSource('/test.dart'); emptySource = _newSource('/test.dart');
// prepare AnalysisContext AnalysisEngine.instance.useTaskModel = true;
context = new AnalysisContextImpl();
context.sourceFactory = new SourceFactory(<UriResolver>[ context.sourceFactory = new SourceFactory(<UriResolver>[
new DartUriResolver(sdk), new DartUriResolver(sdk),
new ResourceUriResolver(resourceProvider) new ResourceUriResolver(resourceProvider)
]); ]);
// prepare TaskManager
taskManager.addTaskDescriptor(GetContentTask.DESCRIPTOR); analysisDriver = context.driver;
// TODO(scheglov) extract into API analysisDriver.taskManager
taskManager.addTaskDescriptor(ScanDartTask.DESCRIPTOR); .addTaskDescriptor(BuildUnitDirectivesTask.DESCRIPTOR);
taskManager.addTaskDescriptor(ParseDartTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildClassConstructorsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildLibraryConstructorsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildSourceClosuresTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR);
taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR);
taskManager.addTaskDescriptor(GatherUsedImportedElementsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(GatherUsedLocalElementsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(GenerateHintsTask.DESCRIPTOR);
taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR);
taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR);
taskManager.addTaskDescriptor(ResolveReferencesTask.DESCRIPTOR);
taskManager.addTaskDescriptor(ResolveVariableReferencesTask.DESCRIPTOR);
taskManager.addTaskDescriptor(VerifyUnitTask.DESCRIPTOR);
// Angular specific tasks
taskManager.addTaskDescriptor(BuildUnitDirectivesTask.DESCRIPTOR);
// prepare AnalysisDriver
analysisDriver = new AnalysisDriver(taskManager, context);
} }
void _computeResult(AnalysisTarget target, ResultDescriptor result) { void _computeResult(AnalysisTarget target, ResultDescriptor result) {
@ -179,27 +158,3 @@ class _AbstractDartTaskTest {
return file.createSource(); return file.createSource();
} }
} }
class _MockContext extends TypedMock implements ExtendedAnalysisContext {
AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
SourceFactory sourceFactory;
TypeProvider typeProvider;
Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{};
String get name => '_MockContext';
bool exists(Source source) => source.exists();
@override
CacheEntry getCacheEntry(AnalysisTarget target) {
return entryMap.putIfAbsent(target, () => new CacheEntry());
}
TimestampedData<String> getContents(Source source) => source.contents;
noSuchMethod(Invocation invocation) {
print('noSuchMethod: ${invocation.memberName}');
return super.noSuchMethod(invocation);
}
}