diff --git a/modules_dart/analysis_server/lib/plugin.dart b/modules_dart/analysis_server/lib/plugin.dart deleted file mode 100644 index f19c81d6b8c..00000000000 --- a/modules_dart/analysis_server/lib/plugin.dart +++ /dev/null @@ -1,23 +0,0 @@ -library angular2.src.analysis.server_plugin; - -import 'package:analyzer/plugin/plugin.dart'; - -/// Contribute a plugin for services such as completions, indexing and refactoring -/// of Angular 2 dart code. -class AngularServerPlugin implements Plugin { - - /// the unique indetifier for this plugin - static const String UNIQUE_IDENTIFIER = 'angular2.analysis.services'; - - @override - String get uniqueIdentifier => UNIQUE_IDENTIFIER; - - @override - void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {} - - @override - void registerExtensions(RegisterExtension registerExtension) { - // TODO: register extension for code completions, indexing etc - - } -} diff --git a/modules_dart/analysis_server/pubspec.yaml b/modules_dart/analysis_server/pubspec.yaml deleted file mode 100644 index 185dfeaecb4..00000000000 --- a/modules_dart/analysis_server/pubspec.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: angular2_analysis_server -version: 0.0.0 -description: Dart analyzer server plugin for Angular 2 -environment: - sdk: '>=1.9.0-dev.8.0' -dependencies: - analyzer: '^0.24.4' diff --git a/modules_dart/analyzer_plugin/lib/plugin.dart b/modules_dart/analyzer_plugin/lib/plugin.dart deleted file mode 100644 index 7509da3b576..00000000000 --- a/modules_dart/analyzer_plugin/lib/plugin.dart +++ /dev/null @@ -1,24 +0,0 @@ -library angular2.src.analysis.analyzer_plugin; - -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'; - - @override - String get uniqueIdentifier => UNIQUE_IDENTIFIER; - - @override - void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {} - - @override - void registerExtensions(RegisterExtension registerExtension) { - String taskId = TASK_EXTENSION_POINT_ID; - registerExtension(taskId, BuildUnitDirectivesTask.DESCRIPTOR); - } -} diff --git a/modules_dart/analyzer_plugin/lib/src/tasks.dart b/modules_dart/analyzer_plugin/lib/src/tasks.dart deleted file mode 100644 index 56e99d90671..00000000000 --- a/modules_dart/analyzer_plugin/lib/src/tasks.dart +++ /dev/null @@ -1,55 +0,0 @@ -library angular2.src.analysis.analyzer_plugin.src.tasks; - -// import 'package:analyzer/src/generated/ast.dart' hide Directive; -import 'package:analyzer/src/generated/engine.dart'; -import 'package:analyzer/src/task/general.dart'; -import 'package:analyzer/task/dart.dart'; -import 'package:analyzer/task/model.dart'; -import 'package:angular2/src/compiler/directive_metadata.dart'; -// import 'package:angular2/src/transform/common/directive_metadata_reader.dart'; - - -/// The [CompileDirectiveMetadata]s of a [LibrarySpecificUnit]. -final ListResultDescriptor DIRECTIVES = - new ListResultDescriptor('ANGULAR2_DIRECTIVES', null); - -/// A task that builds [CompileDirectiveMetadata]s for directive classes. -class BuildUnitDirectivesTask extends SourceBasedAnalysisTask { - static const String UNIT_INPUT = 'UNIT_INPUT'; - - static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( - 'BuildUnitDirectivesTask', createTask, buildInputs, - [DIRECTIVES]); - - BuildUnitDirectivesTask(AnalysisContext context, AnalysisTarget target) - : super(context, target); - - @override - TaskDescriptor get descriptor => DESCRIPTOR; - - @override - void internalPerform() { - // CompilationUnit unit = getRequiredInput(UNIT_INPUT); - - List metaList = []; - // TODO(tbosch): figure our whether analyzer plugin is used at all... - // for (CompilationUnitMember unitMember in unit.declarations) { - // if (unitMember is ClassDeclaration) { - // CompileDirectiveMetadata meta = readDirectiveMetadata(unitMember); - // if (meta != null) { - // metaList.add(meta); - // } - // } - // } - outputs[DIRECTIVES] = metaList; - } - - static Map buildInputs(AnalysisTarget target) { - return {UNIT_INPUT: RESOLVED_UNIT.of(target)}; - } - - static BuildUnitDirectivesTask createTask( - AnalysisContext context, AnalysisTarget target) { - return new BuildUnitDirectivesTask(context, target); - } -} diff --git a/modules_dart/analyzer_plugin/lib/tasks.dart b/modules_dart/analyzer_plugin/lib/tasks.dart deleted file mode 100644 index 69a07a2bf43..00000000000 --- a/modules_dart/analyzer_plugin/lib/tasks.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.src.analysis.analyzer_plugin.tasks; - -import 'package:analyzer/src/generated/error.dart'; -import 'package:analyzer/task/model.dart'; - -/// The analysis errors associated with a target. -/// The value combines errors represented by multiple other results. -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 deleted file mode 100644 index 87070d63086..00000000000 --- a/modules_dart/analyzer_plugin/pubspec.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: angular2_analyzer_plugin -version: 0.0.0 -description: Dart analyzer plugin for Angular 2 -environment: - sdk: '>=1.9.0 <2.0.0' -dependencies: - angular2: '0.0.0' - analyzer: '>=0.25.1 <0.27.0' - plugin: "^0.1.0" -dev_dependencies: - test_reflective_loader: '^0.0.3' - typed_mock: '^0.0.4' - unittest: '^0.11.0' -dependency_overrides: - angular2: - path: ../../dist/dart/angular2 diff --git a/modules_dart/analyzer_plugin/test/mock_sdk.dart b/modules_dart/analyzer_plugin/test/mock_sdk.dart deleted file mode 100644 index 71c01f11800..00000000000 --- a/modules_dart/analyzer_plugin/test/mock_sdk.dart +++ /dev/null @@ -1,333 +0,0 @@ -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/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'; - -class MockSdk implements DartSdk { - static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core', - '/lib/core/core.dart', ''' -library dart.core; - -import 'dart:async'; - -class Object { - bool operator ==(other) => identical(this, other); - String toString() => 'a string'; - int get hashCode => 0; -} - -class Function {} -class StackTrace {} -class Symbol {} -class Type {} - -abstract class Comparable { - int compareTo(T other); -} - -abstract class String implements Comparable { - external factory String.fromCharCodes(Iterable charCodes, - [int start = 0, int end]); - bool get isEmpty => false; - bool get isNotEmpty => false; - int get length => 0; - String toUpperCase(); - List get codeUnits; -} - -class bool extends Object {} -abstract class num implements Comparable { - bool operator <(num other); - bool operator <=(num other); - bool operator >(num other); - bool operator >=(num other); - num operator +(num other); - num operator -(num other); - num operator *(num other); - num operator /(num other); - int toInt(); - num abs(); - int round(); -} -abstract class int extends num { - bool get isEven => false; - int operator -(); - external static int parse(String source, - { int radix, - int onError(String source) }); -} -class double extends num {} -class DateTime extends Object {} -class Null extends Object {} - -class Deprecated extends Object { - final String expires; - const Deprecated(this.expires); -} -const Object deprecated = const Deprecated("next release"); - -class Iterator { - bool moveNext(); - E get current; -} - -abstract class Iterable { - Iterator get iterator; - bool get isEmpty; -} - -abstract class List implements Iterable { - void add(E value); - E operator [](int index); - void operator []=(int index, E value); - Iterator get iterator => null; - void clear(); -} - -abstract class Map extends Object { - Iterable get keys; -} - -external bool identical(Object a, Object b); - -void print(Object object) {} - -class _Override { - const _Override(); -} -const Object override = const _Override(); -'''); - - static const _MockSdkLibrary LIB_ASYNC = const _MockSdkLibrary('dart:async', - '/lib/async/async.dart', ''' -library dart.async; - -import 'dart:math'; - -class Future { - factory Future.delayed(Duration duration, [T computation()]) => null; - factory Future.value([value]) => null; - static Future wait(List futures) => null; -} - -class Stream {} -abstract class StreamTransformer {} -'''); - - static const _MockSdkLibrary LIB_COLLECTION = const _MockSdkLibrary( - 'dart:collection', '/lib/collection/collection.dart', ''' -library dart.collection; - -abstract class HashMap implements Map {} -'''); - - static const _MockSdkLibrary LIB_CONVERT = const _MockSdkLibrary( - 'dart:convert', '/lib/convert/convert.dart', ''' -library dart.convert; - -import 'dart:async'; - -abstract class Converter implements StreamTransformer {} -class JsonDecoder extends Converter {} -'''); - - static const _MockSdkLibrary LIB_MATH = const _MockSdkLibrary('dart:math', - '/lib/math/math.dart', ''' -library dart.math; -const double E = 2.718281828459045; -const double PI = 3.1415926535897932; -const double LN10 = 2.302585092994046; -num min(num a, num b) => 0; -num max(num a, num b) => 0; -external double cos(num x); -external double sin(num x); -external double sqrt(num x); -class Random { - bool nextBool() => true; - double nextDouble() => 2.0; - int nextInt() => 1; -} -'''); - - static const _MockSdkLibrary LIB_HTML = const _MockSdkLibrary('dart:html', - '/lib/html/dartium/html_dartium.dart', ''' -library dart.html; -class HtmlElement {} -'''); - - static const List LIBRARIES = const [ - LIB_CORE, - LIB_ASYNC, - LIB_COLLECTION, - LIB_CONVERT, - LIB_MATH, - LIB_HTML, - ]; - - final resource.MemoryResourceProvider provider = - new resource.MemoryResourceProvider(); - - /** - * The [AnalysisContext] which is used for all of the sources. - */ - AnalysisContextImpl _analysisContext; - - MockSdk() { - LIBRARIES.forEach((_MockSdkLibrary library) { - provider.newFile(library.path, library.content); - }); - } - - @override - AnalysisContextImpl get context { - if (_analysisContext == null) { - _analysisContext = new _SdkAnalysisContext(this); - SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); - _analysisContext.sourceFactory = factory; - ChangeSet changeSet = new ChangeSet(); - for (String uri in uris) { - Source source = factory.forUri(uri); - changeSet.addedSource(source); - } - _analysisContext.applyChanges(changeSet); - } - return _analysisContext; - } - - @override - List get sdkLibraries => LIBRARIES; - - @override - String get sdkVersion => throw unimplemented; - - UnimplementedError get unimplemented => new UnimplementedError(); - - @override - List get uris { - List uris = []; - for (SdkLibrary library in LIBRARIES) { - uris.add(library.shortName); - } - return uris; - } - - @override - Source fromFileUri(Uri uri) { - String filePath = uri.path; - String libPath = '/lib'; - if (!filePath.startsWith("$libPath/")) { - return null; - } - for (SdkLibrary library in LIBRARIES) { - String libraryPath = library.path; - if (filePath.replaceAll('\\', '/') == libraryPath) { - try { - resource.File file = provider.getResource(uri.path); - Uri dartUri = Uri.parse(library.shortName); - return file.createSource(dartUri); - } catch (exception) { - return null; - } - } - if (filePath.startsWith("$libraryPath/")) { - String pathInLibrary = filePath.substring(libraryPath.length + 1); - String path = '${library.shortName}/${pathInLibrary}'; - try { - resource.File file = provider.getResource(uri.path); - Uri dartUri = new Uri(scheme: 'dart', path: path); - return file.createSource(dartUri); - } catch (exception) { - return null; - } - } - } - return null; - } - - @override - SdkLibrary getSdkLibrary(String dartUri) { - // getSdkLibrary() is only used to determine whether a library is internal - // to the SDK. The mock SDK doesn't have any internals, so it's safe to - // return null. - return null; - } - - @override - Source mapDartUri(String dartUri) { - const Map uriToPath = const { - "dart:core": "/lib/core/core.dart", - "dart:html": "/lib/html/dartium/html_dartium.dart", - "dart:async": "/lib/async/async.dart", - "dart:collection": "/lib/collection/collection.dart", - "dart:convert": "/lib/convert/convert.dart", - "dart:math": "/lib/math/math.dart" - }; - - String path = uriToPath[dartUri]; - if (path != null) { - resource.File file = provider.getResource(path); - Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); - return file.createSource(uri); - } - - // If we reach here then we tried to use a dartUri that's not in the - // table above. - return null; - } -} - -class _MockSdkLibrary implements SdkLibrary { - final String shortName; - final String path; - final String content; - - const _MockSdkLibrary(this.shortName, this.path, this.content); - - @override - String get category => throw unimplemented; - - @override - bool get isDart2JsLibrary => throw unimplemented; - - @override - bool get isDocumented => throw unimplemented; - - @override - bool get isImplementation => throw unimplemented; - - @override - bool get isInternal => throw unimplemented; - - @override - bool get isShared => throw unimplemented; - - @override - bool get isVmLibrary => throw unimplemented; - - 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 deleted file mode 100644 index 702bfb1444c..00000000000 --- a/modules_dart/analyzer_plugin/test/tasks_test.server.spec.dart +++ /dev/null @@ -1,160 +0,0 @@ -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, AnalysisEngine; -import 'package:analyzer/src/generated/sdk.dart'; -import 'package:analyzer/src/generated/source.dart'; -import 'package:analyzer/src/task/driver.dart'; -import 'package:analyzer/task/dart.dart'; -import 'package:analyzer/task/model.dart'; -import 'package:angular2/src/core/render/api.dart'; -import 'package:angular2_analyzer_plugin/src/tasks.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; -import 'package:unittest/unittest.dart'; - -import 'mock_sdk.dart'; - -main() { - groupSep = ' | '; - defineReflectiveTests(BuildUnitDirectivesTaskTest); -} - -@reflectiveTest -class BuildUnitDirectivesTaskTest extends _AbstractDartTaskTest { - MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); - - void test_Component() { - _addAngularSources(); - - Source source = _newSource('/test.dart', r''' - import '/angular2/src/core/metadata.dart'; - - @Component(selector: 'comp-a') - class ComponentA { - } - - @Component(selector: 'comp-b') - class ComponentB { - } -'''); - LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); - _computeResult(target, DIRECTIVES); - expect(task, new isInstanceOf()); - // validate - List directives = outputs[DIRECTIVES]; - expect(directives, hasLength(2)); - expect(directives[0].selector, 'comp-a'); - expect(directives[1].selector, 'comp-b'); - } - - void test_Directive() { - _addAngularSources(); - - Source source = _newSource('/test.dart', r''' - -import '/angular2/src/core/metadata.dart'; - -@Directive(selector: 'deco-a') -class ComponentA { -} - -@Directive(selector: 'deco-b') -class ComponentB { -} -'''); - LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); - _computeResult(target, DIRECTIVES); - expect(task, new isInstanceOf()); - // validate - List directives = outputs[DIRECTIVES]; - expect(directives, hasLength(2)); - expect(directives[0].selector, 'deco-a'); - expect(directives[1].selector, 'deco-b'); - } - - void _addAngularSources() { - - - _newSource('/angular2/src/core/metadata.dart', r''' - -library angular2.src.core.metadata; - -abstract class Directive { - final String selector; - final dynamic properties; - final dynamic hostListeners; - final List lifecycle; - const Directive({selector, properties, hostListeners, lifecycle}) - : selector = selector, - properties = properties, - hostListeners = hostListeners, - lifecycle = lifecycle, - super(); -} - -class Component extends Directive { - final String changeDetection; - final List injectables; - const Component({selector, properties, events, hostListeners, - injectables, lifecycle, changeDetection: 'DEFAULT'}) - : changeDetection = changeDetection, - injectables = injectables, - super( - selector: selector, - inputs: properties, - events: events, - hostListeners: hostListeners, - lifecycle: lifecycle); -} - -'''); - } -} - -class _AbstractDartTaskTest { - MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); - Source emptySource; - - DartSdk sdk = new MockSdk(); - AnalysisContextImpl context; - Map entryMap = {}; - - AnalysisDriver analysisDriver; - - AnalysisTask task; - Map, dynamic> outputs; - - CacheEntry getCacheEntry(AnalysisTarget target) { - return entryMap.putIfAbsent(target, () => new CacheEntry(target)); - } - - void setUp() { - emptySource = _newSource('/test.dart'); - AnalysisEngine.instance.useTaskModel = true; - context = new AnalysisContextImpl(); - - context.sourceFactory = new SourceFactory([ - new DartUriResolver(sdk), - new ResourceUriResolver(resourceProvider) - ]); - - analysisDriver = context.driver; - analysisDriver.taskManager - .addTaskDescriptor(BuildUnitDirectivesTask.DESCRIPTOR); - } - - void _computeResult(AnalysisTarget target, ResultDescriptor result) { - task = analysisDriver.computeResult(target, result); - expect(task.caughtException, isNull); - outputs = task.outputs; - } - - Source _newSource(String path, [String content = '']) { - File file = resourceProvider.newFile(path, content); - return file.createSource(); - } -}