refactor(dart/analyzer plugin): update to latest version of plugins
Closes #3681
This commit is contained in:
parent
5725f71777
commit
a191c89193
|
@ -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'
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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<RenderDirectiveMetadata> DIRECTIVES =
|
||||
new ListResultDescriptor<RenderDirectiveMetadata>('ANGULAR2_DIRECTIVES', null);
|
||||
|
@ -29,6 +30,7 @@ class BuildUnitDirectivesTask extends SourceBasedAnalysisTask {
|
|||
@override
|
||||
void internalPerform() {
|
||||
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
|
||||
|
||||
List<RenderDirectiveMetadata> metaList = <RenderDirectiveMetadata>[];
|
||||
for (CompilationUnitMember unitMember in unit.declarations) {
|
||||
if (unitMember is ClassDeclaration) {
|
||||
|
|
|
@ -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<List<AnalysisError>> HTML_ERRORS =
|
||||
new CompositeResultDescriptor<List<AnalysisError>>('ANGULAR_HTML_ERRORS');
|
||||
final ListResultDescriptor<AnalysisError> HTML_ERRORS =
|
||||
new ListResultDescriptor<AnalysisError>(
|
||||
'ANGULAR_HTML_ERRORS', AnalysisError.NO_ERRORS);
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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(<CachePartition>[
|
||||
AnalysisEngine.instance.partitionManager_new.forSdk(sdk)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{};
|
||||
|
||||
TaskManager taskManager = new TaskManager();
|
||||
AnalysisDriver analysisDriver;
|
||||
|
||||
AnalysisTask task;
|
||||
Map<ResultDescriptor<dynamic>, 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(<UriResolver>[
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue