| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Defines static information collected by the type checker and used later by | 5 /// Defines static information collected by the type checker and used later by |
| 6 /// emitters to generate code. | 6 /// emitters to generate code. |
| 7 library dev_compiler.src.info; | 7 library dev_compiler.src.info; |
| 8 | 8 |
| 9 import 'dart:mirrors'; | |
| 10 | |
| 11 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 12 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| 13 import 'package:analyzer/src/generated/error.dart' as analyzer; | 11 import 'package:analyzer/src/generated/error.dart' as analyzer; |
| 14 import 'package:logging/logging.dart' show Level; | 12 import 'package:logging/logging.dart' show Level; |
| 15 | 13 |
| 16 import 'package:dev_compiler/src/checker/rules.dart'; | 14 import 'package:dev_compiler/src/checker/rules.dart'; |
| 17 import 'package:dev_compiler/src/utils.dart' as utils; | 15 import 'package:dev_compiler/src/utils.dart' as utils; |
| 18 | 16 |
| 19 import 'report.dart' show Message; | 17 import 'report.dart' show Message; |
| 20 | 18 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 401 } |
| 404 | 402 |
| 405 // Invalid override of an instance member of a class. | 403 // Invalid override of an instance member of a class. |
| 406 abstract class InvalidOverride extends StaticError { | 404 abstract class InvalidOverride extends StaticError { |
| 407 /// Member delaration with the invalid override. | 405 /// Member delaration with the invalid override. |
| 408 final ExecutableElement element; | 406 final ExecutableElement element; |
| 409 | 407 |
| 410 /// Type (class or interface) that provides the base declaration. | 408 /// Type (class or interface) that provides the base declaration. |
| 411 final InterfaceType base; | 409 final InterfaceType base; |
| 412 | 410 |
| 413 /// Actual type of the overriden member. | 411 /// Actual type of the overridden member. |
| 414 final DartType subType; | 412 final DartType subType; |
| 415 | 413 |
| 416 /// Actual type of the base member. | 414 /// Actual type of the base member. |
| 417 final DartType baseType; | 415 final DartType baseType; |
| 418 | 416 |
| 419 /// Whether the error comes from combining a base class and an interface | 417 /// Whether the error comes from combining a base class and an interface |
| 420 final bool fromBaseClass; | 418 final bool fromBaseClass; |
| 421 | 419 |
| 422 /// Whether the error comes from a mixin (either overriding a base class or an | 420 /// Whether the error comes from a mixin (either overriding a base class or an |
| 423 /// interface declaration). | 421 /// interface declaration). |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 /// <http://goo.gl/q1T4BB> | 505 /// <http://goo.gl/q1T4BB> |
| 508 /// | 506 /// |
| 509 /// For now this is the only pattern we support. | 507 /// For now this is the only pattern we support. |
| 510 class InvalidSuperInvocation extends StaticError { | 508 class InvalidSuperInvocation extends StaticError { |
| 511 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); | 509 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); |
| 512 | 510 |
| 513 String get message => "super call must be last in an initializer list " | 511 String get message => "super call must be last in an initializer list " |
| 514 "(see http://goo.gl/q1T4BB): $node"; | 512 "(see http://goo.gl/q1T4BB): $node"; |
| 515 } | 513 } |
| 516 | 514 |
| 517 /// Automatically infer list of types by scanning this library using mirrors. | |
| 518 final List<Type> infoTypes = () { | |
| 519 var allTypes = new Set(); | |
| 520 var baseTypes = new Set(); | |
| 521 var infoMirror = reflectClass(StaticInfo); | |
| 522 var libMirror = infoMirror.owner as LibraryMirror; | |
| 523 var declarations = libMirror.declarations.values; | |
| 524 for (ClassMirror cls in declarations.where((d) => d is ClassMirror)) { | |
| 525 if (cls.isSubtypeOf(infoMirror)) { | |
| 526 allTypes.add(cls); | |
| 527 baseTypes.add(cls.superclass); | |
| 528 } | |
| 529 } | |
| 530 allTypes.removeAll(baseTypes); | |
| 531 return new List<Type>.from(allTypes.map((mirror) => mirror.reflectedType)) | |
| 532 ..sort((t1, t2) => '$t1'.compareTo('$t2')); | |
| 533 }(); | |
| 534 | |
| 535 class AnalyzerError extends Message { | 515 class AnalyzerError extends Message { |
| 536 factory AnalyzerError.from(analyzer.AnalysisError error) { | 516 factory AnalyzerError.from(analyzer.AnalysisError error) { |
| 537 var severity = error.errorCode.type.severity; | 517 var severity = error.errorCode.type.severity; |
| 538 var isError = severity == analyzer.ErrorSeverity.WARNING; | 518 var isError = severity == analyzer.ErrorSeverity.WARNING; |
| 539 var level = isError ? Level.SEVERE : Level.WARNING; | 519 var level = isError ? Level.SEVERE : Level.WARNING; |
| 540 int begin = error.offset; | 520 int begin = error.offset; |
| 541 int end = begin + error.length; | 521 int end = begin + error.length; |
| 542 return new AnalyzerError(error.message, level, begin, end); | 522 return new AnalyzerError(error.message, level, begin, end); |
| 543 } | 523 } |
| 544 | 524 |
| 545 const AnalyzerError(String message, Level level, int begin, int end) | 525 const AnalyzerError(String message, Level level, int begin, int end) |
| 546 : super(message, level, begin, end); | 526 : super(message, level, begin, end); |
| 547 } | 527 } |
| OLD | NEW |