diff --git a/modules/angular2/pubspec.yaml b/modules/angular2/pubspec.yaml index 568a544c1b..12a5a68d60 100644 --- a/modules/angular2/pubspec.yaml +++ b/modules/angular2/pubspec.yaml @@ -9,7 +9,7 @@ homepage: <%= packageJson.homepage %> environment: sdk: '>=1.10.0 <2.0.0' dependencies: - analyzer: '>=0.24.4 <0.26.0' + analyzer: '>=0.24.4 <0.27.0' barback: '^0.15.2+2' code_transformers: '^0.2.8' dart_style: '>=0.1.8 <0.3.0' diff --git a/modules_dart/analyzer_plugin/lib/plugin.dart b/modules_dart/analyzer_plugin/lib/plugin.dart index 29f3118199..7509da3b57 100644 --- a/modules_dart/analyzer_plugin/lib/plugin.dart +++ b/modules_dart/analyzer_plugin/lib/plugin.dart @@ -1,13 +1,12 @@ library angular2.src.analysis.analyzer_plugin; -import 'package:analyzer/plugin/plugin.dart'; +import 'package:plugin/plugin.dart'; import 'package:analyzer/plugin/task.dart'; import 'src/tasks.dart'; /// Contribute a plugin to the dart analyzer for analysis of /// Angular 2 dart code. class AngularAnalyzerPlugin implements Plugin { - /// The unique identifier for this plugin. static const String UNIQUE_IDENTIFIER = 'angular2.analysis'; diff --git a/modules_dart/analyzer_plugin/lib/src/tasks.dart b/modules_dart/analyzer_plugin/lib/src/tasks.dart index a495b713ee..6267c1be5a 100644 --- a/modules_dart/analyzer_plugin/lib/src/tasks.dart +++ b/modules_dart/analyzer_plugin/lib/src/tasks.dart @@ -8,6 +8,7 @@ import 'package:analyzer/task/model.dart'; import 'package:angular2/src/render/api.dart'; import 'package:angular2/src/transform/common/directive_metadata_reader.dart'; + /// The [RenderDirectiveMetadata]s of a [LibrarySpecificUnit]. final ListResultDescriptor DIRECTIVES = new ListResultDescriptor('ANGULAR2_DIRECTIVES', null); @@ -29,6 +30,7 @@ class BuildUnitDirectivesTask extends SourceBasedAnalysisTask { @override void internalPerform() { CompilationUnit unit = getRequiredInput(UNIT_INPUT); + List metaList = []; for (CompilationUnitMember unitMember in unit.declarations) { if (unitMember is ClassDeclaration) { diff --git a/modules_dart/analyzer_plugin/lib/tasks.dart b/modules_dart/analyzer_plugin/lib/tasks.dart index a8447cb287..69a07a2bf4 100644 --- a/modules_dart/analyzer_plugin/lib/tasks.dart +++ b/modules_dart/analyzer_plugin/lib/tasks.dart @@ -5,5 +5,6 @@ import 'package:analyzer/task/model.dart'; /// The analysis errors associated with a target. /// The value combines errors represented by multiple other results. -final CompositeResultDescriptor> HTML_ERRORS = - new CompositeResultDescriptor>('ANGULAR_HTML_ERRORS'); +final ListResultDescriptor HTML_ERRORS = + new ListResultDescriptor( + 'ANGULAR_HTML_ERRORS', AnalysisError.NO_ERRORS); diff --git a/modules_dart/analyzer_plugin/pubspec.yaml b/modules_dart/analyzer_plugin/pubspec.yaml index a4e75941eb..87070d6308 100644 --- a/modules_dart/analyzer_plugin/pubspec.yaml +++ b/modules_dart/analyzer_plugin/pubspec.yaml @@ -5,7 +5,8 @@ environment: sdk: '>=1.9.0 <2.0.0' dependencies: angular2: '0.0.0' - analyzer: '^0.24.4' + analyzer: '>=0.25.1 <0.27.0' + plugin: "^0.1.0" dev_dependencies: test_reflective_loader: '^0.0.3' typed_mock: '^0.0.4' diff --git a/modules_dart/analyzer_plugin/test/mock_sdk.dart b/modules_dart/analyzer_plugin/test/mock_sdk.dart index b8c95c993b..71c01f1180 100644 --- a/modules_dart/analyzer_plugin/test/mock_sdk.dart +++ b/modules_dart/analyzer_plugin/test/mock_sdk.dart @@ -2,7 +2,10 @@ library test.src.mock_sdk; import 'package:analyzer/file_system/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/source.dart'; @@ -173,7 +176,7 @@ class HtmlElement {} /** * The [AnalysisContext] which is used for all of the sources. */ - InternalAnalysisContext _analysisContext; + AnalysisContextImpl _analysisContext; MockSdk() { LIBRARIES.forEach((_MockSdkLibrary library) { @@ -182,9 +185,9 @@ class HtmlElement {} } @override - AnalysisContext get context { + AnalysisContextImpl get context { if (_analysisContext == null) { - _analysisContext = new SdkAnalysisContext(); + _analysisContext = new _SdkAnalysisContext(this); SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); _analysisContext.sourceFactory = factory; ChangeSet changeSet = new ChangeSet(); @@ -309,3 +312,22 @@ class _MockSdkLibrary implements SdkLibrary { 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([ + AnalysisEngine.instance.partitionManager_new.forSdk(sdk) + ]); + } +} diff --git a/modules_dart/analyzer_plugin/test/tasks_test.server.spec.dart b/modules_dart/analyzer_plugin/test/tasks_test.server.spec.dart index 82393ca9aa..7833c992d8 100644 --- a/modules_dart/analyzer_plugin/test/tasks_test.server.spec.dart +++ b/modules_dart/analyzer_plugin/test/tasks_test.server.spec.dart @@ -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/memory_file_system.dart'; import 'package:analyzer/src/context/cache.dart'; +import 'package:analyzer/src/context/context.dart'; import 'package:analyzer/src/generated/engine.dart' - show AnalysisOptionsImpl, TimestampedData; -import 'package:analyzer/src/generated/resolver.dart'; + show AnalysisOptionsImpl, TimestampedData, AnalysisEngine; import 'package:analyzer/src/generated/sdk.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/general.dart'; -import 'package:analyzer/src/task/manager.dart'; import 'package:analyzer/task/dart.dart'; import 'package:analyzer/task/model.dart'; import 'package:angular2/src/render/api.dart'; import 'package:angular2_analyzer_plugin/src/tasks.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; -import 'package:typed_mock/typed_mock.dart'; import 'package:unittest/unittest.dart'; import 'mock_sdk.dart'; @@ -33,16 +29,17 @@ class BuildUnitDirectivesTaskTest extends _AbstractDartTaskTest { void test_Component() { _addAngularSources(); + Source source = _newSource('/test.dart', r''' -import '/angular2/metadata.dart'; + import '/angular2/metadata.dart'; -@Component(selector: 'comp-a') -class ComponentA { -} + @Component(selector: 'comp-a') + class ComponentA { + } -@Component(selector: 'comp-b') -class ComponentB { -} + @Component(selector: 'comp-b') + class ComponentB { + } '''); LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); _computeResult(target, DIRECTIVES); @@ -56,7 +53,9 @@ class ComponentB { void test_Directive() { _addAngularSources(); + Source source = _newSource('/test.dart', r''' + import '/angular2/metadata.dart'; @Directive(selector: 'deco-a') @@ -78,7 +77,10 @@ class ComponentB { } void _addAngularSources() { + + _newSource('/angular2/metadata.dart', r''' + library angular2.src.core.metadata; abstract class Directive { @@ -118,54 +120,31 @@ class _AbstractDartTaskTest { Source emptySource; DartSdk sdk = new MockSdk(); - _MockContext context = new _MockContext(); + AnalysisContextImpl context; Map entryMap = {}; - TaskManager taskManager = new TaskManager(); AnalysisDriver analysisDriver; AnalysisTask task; Map, dynamic> outputs; CacheEntry getCacheEntry(AnalysisTarget target) { - return entryMap.putIfAbsent(target, () => new CacheEntry()); + return entryMap.putIfAbsent(target, () => new CacheEntry(target)); } void setUp() { emptySource = _newSource('/test.dart'); - // prepare AnalysisContext + AnalysisEngine.instance.useTaskModel = true; + context = new AnalysisContextImpl(); + context.sourceFactory = new SourceFactory([ new DartUriResolver(sdk), new ResourceUriResolver(resourceProvider) ]); - // prepare TaskManager - taskManager.addTaskDescriptor(GetContentTask.DESCRIPTOR); - // TODO(scheglov) extract into API - taskManager.addTaskDescriptor(ScanDartTask.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); + + analysisDriver = context.driver; + analysisDriver.taskManager + .addTaskDescriptor(BuildUnitDirectivesTask.DESCRIPTOR); } void _computeResult(AnalysisTarget target, ResultDescriptor result) { @@ -179,27 +158,3 @@ class _AbstractDartTaskTest { return file.createSource(); } } - -class _MockContext extends TypedMock implements ExtendedAnalysisContext { - AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); - SourceFactory sourceFactory; - TypeProvider typeProvider; - - Map entryMap = {}; - - String get name => '_MockContext'; - - bool exists(Source source) => source.exists(); - - @override - CacheEntry getCacheEntry(AnalysisTarget target) { - return entryMap.putIfAbsent(target, () => new CacheEntry()); - } - - TimestampedData getContents(Source source) => source.contents; - - noSuchMethod(Invocation invocation) { - print('noSuchMethod: ${invocation.memberName}'); - return super.noSuchMethod(invocation); - } -}