style(dart): Format with dartfmt v0.2.0

Format all pure Dart code with package:dart_style v0.2.0

Command:
```
find -type f -name "*.dart" | xargs dartformat -w
```
This commit is contained in:
Tim Blasi
2015-08-04 12:05:30 -07:00
parent 450d3630cc
commit f11f4e0b45
145 changed files with 1627 additions and 1013 deletions
@@ -86,7 +86,8 @@ class AnnotationMatcher extends ClassMatcherBase {
ClassDescriptor descriptor = firstMatch(annotation.name, assetId);
if (descriptor == null) return false;
return implements(descriptor, interfaces,
missingSuperClassWarning: 'Missing `custom_annotation` entry for `${descriptor.superClass}`.');
missingSuperClassWarning:
'Missing `custom_annotation` entry for `${descriptor.superClass}`.');
}
/// Checks if an [Annotation] node implements [Injectable].
@@ -48,8 +48,8 @@ abstract class ClassMatcherBase {
if (descriptor == null) return false;
if (interfaces.contains(descriptor)) return true;
if (descriptor.superClass == null) return false;
var superClass = _classDescriptors.firstWhere(
(a) => a.name == descriptor.superClass, orElse: () => null);
var superClass = _classDescriptors
.firstWhere((a) => a.name == descriptor.superClass, orElse: () => null);
if (superClass == null) {
if (missingSuperClassWarning != null &&
missingSuperClassWarning.isNotEmpty) {
@@ -74,7 +74,8 @@ ImportDirective _getMatchingImport(
name = className.name;
}
if (name != descriptor.name) return null;
return (className.root as CompilationUnit).directives
return (className.root as CompilationUnit)
.directives
.where((d) => d is ImportDirective)
.firstWhere((ImportDirective i) {
var importMatch = false;
@@ -106,8 +107,10 @@ bool isMatch(
class ClassDescriptor {
/// The name of the class.
final String name;
/// A `package:` style import path to the file where the class is defined.
final String import;
/// The class that this class extends or implements. This is the only optional
/// field.
final String superClass;
@@ -108,7 +108,8 @@ class _DirectiveMetadataVisitor extends Object
var directiveType = _getDirectiveType('${node.name}', node.element);
if (directiveType >= 0) {
if (_hasMeta) {
throw new FormatException('Only one Directive is allowed per class. '
throw new FormatException(
'Only one Directive is allowed per class. '
'Found "$node" but already processed "$meta".',
'$node' /* source */);
}
@@ -125,7 +126,8 @@ class _DirectiveMetadataVisitor extends Object
'${node.constructorName.type.name}', node.staticElement);
if (directiveType >= 0) {
if (_hasMeta) {
throw new FormatException('Only one Directive is allowed per class. '
throw new FormatException(
'Only one Directive is allowed per class. '
'Found "$node" but already processed "$meta".',
'$node' /* source */);
}
@@ -177,8 +179,10 @@ class _DirectiveMetadataVisitor extends Object
String _expressionToString(Expression node, String nodeDescription) {
var value = node.accept(_evaluator);
if (value is! String) {
throw new FormatException('Angular 2 could not understand the value '
'in $nodeDescription.', '$node' /* source */);
throw new FormatException(
'Angular 2 could not understand the value '
'in $nodeDescription.',
'$node' /* source */);
}
return value;
}
@@ -203,7 +207,8 @@ class _DirectiveMetadataVisitor extends Object
if (evaluated is! bool) {
throw new FormatException(
'Angular 2 expects a bool but could not understand the value for '
'Directive#compileChildren.', '$compileChildrenValue' /* source */);
'Directive#compileChildren.',
'$compileChildrenValue' /* source */);
}
_compileChildren = evaluated;
}
@@ -216,7 +221,8 @@ class _DirectiveMetadataVisitor extends Object
if (evaluated is! Map) {
throw new FormatException(
'Angular 2 expects a Map but could not understand the value for '
'$propertyName.', '$expression' /* source */);
'$propertyName.',
'$expression' /* source */);
}
evaluated.forEach((key, value) {
if (value != null) {
@@ -233,7 +239,8 @@ class _DirectiveMetadataVisitor extends Object
if (evaluated is! List) {
throw new FormatException(
'Angular 2 expects a List but could not understand the value for '
'$propertyName.', '$expression' /* source */);
'$propertyName.',
'$expression' /* source */);
}
list.addAll(evaluated);
}
@@ -40,6 +40,7 @@ class PrintLogger implements BuildLogger {
void error(msg, {AssetId asset, SourceSpan span}) {
throw new PrintLoggerError(msg, asset, span);
}
Future writeOutput() => null;
Future addLogFilesFromAsset(AssetId id, [int nextNumber = 1]) => null;
}
@@ -51,25 +51,41 @@ class TransformerOptions {
/// The "correct" number of phases varies with the structure of the app.
final int optimizationPhases;
TransformerOptions._internal(this.entryPoints, this.reflectionEntryPoints,
this.modeName, this.mirrorMode, this.initReflector,
this.annotationMatcher, this.optimizationPhases,
this.generateChangeDetectors, this.inlineViews);
TransformerOptions._internal(
this.entryPoints,
this.reflectionEntryPoints,
this.modeName,
this.mirrorMode,
this.initReflector,
this.annotationMatcher,
this.optimizationPhases,
this.generateChangeDetectors,
this.inlineViews);
factory TransformerOptions(List<String> entryPoints,
{List<String> reflectionEntryPoints, String modeName: 'release',
MirrorMode mirrorMode: MirrorMode.none, bool initReflector: true,
{List<String> reflectionEntryPoints,
String modeName: 'release',
MirrorMode mirrorMode: MirrorMode.none,
bool initReflector: true,
List<ClassDescriptor> customAnnotationDescriptors: const [],
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES,
bool inlineViews: true, bool generateChangeDetectors: true}) {
bool inlineViews: true,
bool generateChangeDetectors: true}) {
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
reflectionEntryPoints = entryPoints;
}
var annotationMatcher = new AnnotationMatcher()
..addAll(customAnnotationDescriptors);
optimizationPhases = optimizationPhases.isNegative ? 0 : optimizationPhases;
return new TransformerOptions._internal(entryPoints, reflectionEntryPoints,
modeName, mirrorMode, initReflector, annotationMatcher,
optimizationPhases, generateChangeDetectors, inlineViews);
return new TransformerOptions._internal(
entryPoints,
reflectionEntryPoints,
modeName,
mirrorMode,
initReflector,
annotationMatcher,
optimizationPhases,
generateChangeDetectors,
inlineViews);
}
}
@@ -10,12 +10,16 @@ import 'package:angular2/src/transform/common/names.dart';
class RegisteredType {
/// The type registered by this call.
final Identifier typeName;
/// The actual call to `Reflector#registerType`.
final MethodInvocation registerMethod;
/// The factory method registered.
final Expression factoryFn;
/// The parameters registered.
final Expression parameters;
/// The annotations registered.
final Expression annotations;
@@ -44,8 +44,8 @@ class Rewriter {
visitor.loadLibraryInvocations.sort(compare);
var buf = new StringBuffer();
var idx = visitor.deferredImports.fold(0,
(int lastIdx, ImportDirective node) {
var idx =
visitor.deferredImports.fold(0, (int lastIdx, ImportDirective node) {
buf.write(code.substring(lastIdx, node.offset));
var import = code.substring(node.offset, node.end);
@@ -120,8 +120,7 @@ class _FindDeferredLibraries extends Object with RecursiveAstVisitor<Object> {
.map((asset) => _reader.hasInput(asset)));
// Filter out any deferred imports that do not have ng_deps.
deferredImports = it
.zip([deferredImports, hasInputs])
deferredImports = it.zip([deferredImports, hasInputs])
.where((importHasInput) => importHasInput[1])
.map((importHasInput) => importHasInput[0])
.toList();
@@ -116,5 +116,6 @@ Future<Map<UriBasedDirective, String>> _processNgImports(AssetReader reader,
retVal[directive] = ngDepsUri;
}
}, onError: (_) => null);
})).then((_) => retVal);
}))
.then((_) => retVal);
}
@@ -30,9 +30,14 @@ Future<String> createNgDeps(AssetReader reader, AssetId assetId,
// TODO(kegluneq): Shortcut if we can determine that there are no
// [Directive]s present, taking into account `export`s.
var writer = new AsyncStringWriter();
var visitor = new CreateNgDepsVisitor(writer, assetId,
new XhrImpl(reader, assetId), annotationMatcher, _interfaceMatcher,
ngMeta, inlineViews: inlineViews);
var visitor = new CreateNgDepsVisitor(
writer,
assetId,
new XhrImpl(reader, assetId),
annotationMatcher,
_interfaceMatcher,
ngMeta,
inlineViews: inlineViews);
var code = await reader.readAsString(assetId);
parseCompilationUnit(code, name: assetId.path).accept(visitor);
@@ -76,9 +81,14 @@ class CreateNgDepsVisitor extends Object with SimpleAstVisitor<Object> {
/// The assetId for the file which we are parsing.
final AssetId assetId;
CreateNgDepsVisitor(AsyncStringWriter writer, AssetId assetId, XHR xhr,
AnnotationMatcher annotationMatcher, InterfaceMatcher interfaceMatcher,
this.ngMeta, {bool inlineViews})
CreateNgDepsVisitor(
AsyncStringWriter writer,
AssetId assetId,
XHR xhr,
AnnotationMatcher annotationMatcher,
InterfaceMatcher interfaceMatcher,
this.ngMeta,
{bool inlineViews})
: writer = writer,
_copyVisitor = new ToSourceVisitor(writer),
_factoryVisitor = new FactoryTransformVisitor(writer),
@@ -124,6 +124,7 @@ class _CtorTransformVisitor extends ToSourceVisitor {
}
@override
/// Overridden to avoid outputting grouping operators for default parameters.
Object visitFormalParameterList(FormalParameterList node) {
writer.print('(');
@@ -9,6 +9,7 @@ class Codegen {
/// The prefix used to import our generated file.
final String prefix;
/// The import uris
final Iterable<String> importUris;
@@ -16,8 +16,10 @@ class Rewriter {
final MirrorMode _mirrorMode;
final bool _writeStaticInit;
Rewriter(this._code, this._codegen, {AstTester tester,
MirrorMode mirrorMode: MirrorMode.none, bool writeStaticInit: true})
Rewriter(this._code, this._codegen,
{AstTester tester,
MirrorMode mirrorMode: MirrorMode.none,
bool writeStaticInit: true})
: _mirrorMode = mirrorMode,
_writeStaticInit = writeStaticInit,
_tester = tester == null ? const AstTester() : tester;
@@ -132,9 +134,8 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
'Found bootstrap${node.argumentList}. Transform may not succeed.');
}
var reflectorInit = _setupAdded
? ''
: ', () { ${_getStaticReflectorInitBlock()} }';
var reflectorInit =
_setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock()} }';
// rewrite `bootstrap(...)` to `bootstrapStatic(...)`
buf.write('bootstrapStatic(${args[0]}');
@@ -18,8 +18,10 @@ import 'package:angular2/src/facade/lang.dart' show BaseException;
class Codegen {
/// Stores the generated class definitions.
final StringBuffer _buf = new StringBuffer();
/// Stores all generated initialization code.
final StringBuffer _initBuf = new StringBuffer();
/// The names of already generated classes.
final Set<String> _names = new Set<String>();
@@ -78,12 +80,18 @@ class _CodegenState {
final CodegenNameUtil _names;
final bool _generateCheckNoChanges;
_CodegenState._(this._changeDetectorDefId, this._contextTypeName,
this._changeDetectorTypeName, String changeDetectionStrategy,
this._records, this._directiveRecords, this._logic, this._names,
_CodegenState._(
this._changeDetectorDefId,
this._contextTypeName,
this._changeDetectorTypeName,
String changeDetectionStrategy,
this._records,
this._directiveRecords,
this._logic,
this._names,
this._generateCheckNoChanges)
: _changeDetectionMode = ChangeDetectionUtil
.changeDetectionMode(changeDetectionStrategy);
: _changeDetectionMode =
ChangeDetectionUtil.changeDetectionMode(changeDetectionStrategy);
factory _CodegenState(String typeName, String changeDetectorTypeName,
ChangeDetectorDefinition def) {
@@ -92,8 +100,15 @@ class _CodegenState {
var protoRecords = coalesce(recBuilder.records);
var names = new CodegenNameUtil(protoRecords, def.directiveRecords, _UTIL);
var logic = new CodegenLogicUtil(names, _UTIL);
return new _CodegenState._(def.id, typeName, changeDetectorTypeName,
def.strategy, protoRecords, def.directiveRecords, logic, names,
return new _CodegenState._(
def.id,
typeName,
changeDetectorTypeName,
def.strategy,
protoRecords,
def.directiveRecords,
logic,
names,
def.generateCheckNoChanges);
}
@@ -39,8 +39,8 @@ Future<String> processTemplates(AssetReader reader, AssetId entryPoint,
// Note: TemplateCloner(-1) never serializes Nodes into strings.
// we might want to change this to TemplateCloner(0) to force the serialization
// later when the transformer also stores the proto view template.
var extractor = new _TemplateExtractor(
new DomElementSchemaRegistry(), new TemplateCloner(-1), new XhrImpl(reader, entryPoint));
var extractor = new _TemplateExtractor(new DomElementSchemaRegistry(),
new TemplateCloner(-1), new XhrImpl(reader, entryPoint));
var registrations = new reg.Codegen();
var changeDetectorClasses = new change.Codegen();
@@ -93,7 +93,8 @@ class _TemplateExtractor {
ElementSchemaRegistry _schemaRegistry;
TemplateCloner _templateCloner;
_TemplateExtractor(ElementSchemaRegistry schemaRegistry, TemplateCloner templateCloner, XHR xhr)
_TemplateExtractor(ElementSchemaRegistry schemaRegistry,
TemplateCloner templateCloner, XHR xhr)
: _factory = new CompileStepFactory(new ng.Parser(new ng.Lexer())) {
var urlResolver = new UrlResolver();
var styleUrlResolver = new StyleUrlResolver(urlResolver);
@@ -120,10 +121,12 @@ class _TemplateExtractor {
var pipeline = new CompilePipeline(_factory.createSteps(viewDef));
var compileElements = pipeline.processElements(
DOM.createTemplate(templateAndStyles.template), ViewType.COMPONENT,
DOM.createTemplate(templateAndStyles.template),
ViewType.COMPONENT,
viewDef);
var protoViewDto =
compileElements[0].inheritedProtoView.build(_schemaRegistry, _templateCloner);
var protoViewDto = compileElements[0]
.inheritedProtoView
.build(_schemaRegistry, _templateCloner);
reflector.reflectionCapabilities = savedReflectionCapabilities;
@@ -39,8 +39,10 @@ _nullMethod(Object p, List a) => null;
class RecordingReflectionCapabilities extends NullReflectionCapabilities {
/// The names of all requested `getter`s.
final Set<String> getterNames = new Set<String>();
/// The names of all requested `setter`s.
final Set<String> setterNames = new Set<String>();
/// The names of all requested `method`s.
final Set<String> methodNames = new Set<String>();