| 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 library analysis_server.src.status.validator; | 5 library analysis_server.src.status.validator; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/src/context/cache.dart'; | 11 import 'package:analyzer/src/context/cache.dart'; |
| 12 import 'package:analyzer/src/context/context.dart'; | 12 import 'package:analyzer/src/context/context.dart'; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/constant.dart'; | 14 import 'package:analyzer/src/generated/constant.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart' | 15 import 'package:analyzer/src/generated/engine.dart' |
| 16 show AnalysisEngine, AnalysisResult, CacheState, ChangeSet; | 16 show AnalysisEngine, AnalysisResult, CacheState, ChangeSet; |
| 17 import 'package:analyzer/src/generated/error.dart'; | 17 import 'package:analyzer/src/generated/error.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 18 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/scanner.dart'; | 19 import 'package:analyzer/src/generated/scanner.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:analyzer/src/generated/utilities_collection.dart'; | 21 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 22 import 'package:analyzer/src/task/dart.dart'; | 22 import 'package:analyzer/src/task/dart.dart'; |
| 23 import 'package:analyzer/src/task/html.dart'; | 23 import 'package:analyzer/src/task/html.dart'; |
| 24 import 'package:analyzer/task/dart.dart'; | 24 import 'package:analyzer/task/dart.dart'; |
| 25 import 'package:analyzer/task/model.dart'; | 25 import 'package:analyzer/task/model.dart'; |
| 26 import 'package:html/dom.dart' as html; | 26 import 'package:html/dom.dart' as html; |
| 27 import 'package:analyzer/src/dart/element/element.dart'; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * A class used to compare two element models for equality. | 30 * A class used to compare two element models for equality. |
| 30 */ | 31 */ |
| 31 class ElementComparator { | 32 class ElementComparator { |
| 32 /** | 33 /** |
| 33 * The buffer to which any discovered differences will be recorded. | 34 * The buffer to which any discovered differences will be recorded. |
| 34 */ | 35 */ |
| 35 final StringBuffer _buffer = new StringBuffer(); | 36 final StringBuffer _buffer = new StringBuffer(); |
| 36 | 37 |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 // Compare possible null values. | 1187 // Compare possible null values. |
| 1187 // | 1188 // |
| 1188 if (first == null) { | 1189 if (first == null) { |
| 1189 return second == null; | 1190 return second == null; |
| 1190 } else if (second == null) { | 1191 } else if (second == null) { |
| 1191 return false; | 1192 return false; |
| 1192 } | 1193 } |
| 1193 // | 1194 // |
| 1194 // Handle special cases. | 1195 // Handle special cases. |
| 1195 // | 1196 // |
| 1196 if (first is ConstantEvaluationTarget_Annotation && | 1197 if (first is ElementAnnotationImpl && |
| 1197 second is ConstantEvaluationTarget_Annotation) { | 1198 second is ElementAnnotationImpl) { |
| 1198 return _equal(first.source, second.source) && | 1199 return _equal(first.source, second.source) && |
| 1199 _equal(first.librarySource, second.librarySource) && | 1200 _equal(first.librarySource, second.librarySource) && |
| 1200 _equal(first.annotation, second.annotation); | 1201 _equal(first.annotationAst, second.annotationAst); |
| 1201 } else if (first is AstNode && second is AstNode) { | 1202 } else if (first is AstNode && second is AstNode) { |
| 1202 return first.runtimeType == second.runtimeType && | 1203 return first.runtimeType == second.runtimeType && |
| 1203 first.offset == second.offset && | 1204 first.offset == second.offset && |
| 1204 first.length == second.length; | 1205 first.length == second.length; |
| 1205 } | 1206 } |
| 1206 // | 1207 // |
| 1207 // Handle the general case. | 1208 // Handle the general case. |
| 1208 // | 1209 // |
| 1209 return first == second; | 1210 return first == second; |
| 1210 } | 1211 } |
| 1211 | 1212 |
| 1212 /** | 1213 /** |
| 1213 * Return a hash code for the given [object]. | 1214 * Return a hash code for the given [object]. |
| 1214 */ | 1215 */ |
| 1215 static int _hashCode(Object object) { | 1216 static int _hashCode(Object object) { |
| 1216 // | 1217 // |
| 1217 // Handle special cases. | 1218 // Handle special cases. |
| 1218 // | 1219 // |
| 1219 if (object is ConstantEvaluationTarget_Annotation) { | 1220 if (object is ElementAnnotation) { |
| 1220 return object.source.hashCode; | 1221 return object.source.hashCode; |
| 1221 } else if (object is AstNode) { | 1222 } else if (object is AstNode) { |
| 1222 return object.offset; | 1223 return object.offset; |
| 1223 } | 1224 } |
| 1224 // | 1225 // |
| 1225 // Handle the general case. | 1226 // Handle the general case. |
| 1226 // | 1227 // |
| 1227 return object.hashCode; | 1228 return object.hashCode; |
| 1228 } | 1229 } |
| 1229 } | 1230 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 if (buffer != null) { | 1302 if (buffer != null) { |
| 1302 // TODO(brianwilkerson) Compute where the difference is rather than just | 1303 // TODO(brianwilkerson) Compute where the difference is rather than just |
| 1303 // whether there is a difference. | 1304 // whether there is a difference. |
| 1304 buffer.write('Different AST nodes'); | 1305 buffer.write('Different AST nodes'); |
| 1305 } | 1306 } |
| 1306 return false; | 1307 return false; |
| 1307 } | 1308 } |
| 1308 | 1309 |
| 1309 bool _compareConstantEvaluationTargets(ConstantEvaluationTarget expected, | 1310 bool _compareConstantEvaluationTargets(ConstantEvaluationTarget expected, |
| 1310 ConstantEvaluationTarget actual, StringBuffer buffer) { | 1311 ConstantEvaluationTarget actual, StringBuffer buffer) { |
| 1311 if (actual is ConstantEvaluationTarget_Annotation) { | 1312 if (actual is ElementAnnotation) { |
| 1312 ConstantEvaluationTarget_Annotation expectedAnnotation = expected; | 1313 ElementAnnotationImpl expectedAnnotation = expected; |
| 1313 ConstantEvaluationTarget_Annotation actualAnnotation = actual; | 1314 ElementAnnotationImpl actualAnnotation = actual; |
| 1314 if (actualAnnotation.source == expectedAnnotation.source && | 1315 if (actualAnnotation.source == expectedAnnotation.source && |
| 1315 actualAnnotation.librarySource == expectedAnnotation.librarySource && | 1316 actualAnnotation.librarySource == expectedAnnotation.librarySource && |
| 1316 actualAnnotation.annotation == expectedAnnotation.annotation) { | 1317 actualAnnotation.annotationAst == expectedAnnotation.annotationAst) { |
| 1317 return true; | 1318 return true; |
| 1318 } | 1319 } |
| 1319 if (buffer != null) { | 1320 if (buffer != null) { |
| 1320 void write(ConstantEvaluationTarget_Annotation target) { | 1321 void write(ElementAnnotationImpl target) { |
| 1321 Annotation annotation = target.annotation; | 1322 Annotation annotation = target.annotationAst; |
| 1322 buffer.write(annotation); | 1323 buffer.write(annotation); |
| 1323 buffer.write(' at '); | 1324 buffer.write(' at '); |
| 1324 buffer.write(annotation.offset); | 1325 buffer.write(annotation.offset); |
| 1325 buffer.write(' in '); | 1326 buffer.write(' in '); |
| 1326 buffer.write(target.source); | 1327 buffer.write(target.source); |
| 1327 buffer.write(' in '); | 1328 buffer.write(' in '); |
| 1328 buffer.write(target.librarySource); | 1329 buffer.write(target.librarySource); |
| 1329 } | 1330 } |
| 1330 | 1331 |
| 1331 buffer.write('Expected '); | 1332 buffer.write('Expected '); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 * Determine whether or not there is any interesting difference between the | 1780 * Determine whether or not there is any interesting difference between the |
| 1780 * original and cloned values. | 1781 * original and cloned values. |
| 1781 */ | 1782 */ |
| 1782 void _performComparison() { | 1783 void _performComparison() { |
| 1783 StringBuffer buffer = new StringBuffer(); | 1784 StringBuffer buffer = new StringBuffer(); |
| 1784 if (!_compareObjects(cloneValue, originalValue, buffer)) { | 1785 if (!_compareObjects(cloneValue, originalValue, buffer)) { |
| 1785 description = buffer.toString(); | 1786 description = buffer.toString(); |
| 1786 } | 1787 } |
| 1787 } | 1788 } |
| 1788 } | 1789 } |
| OLD | NEW |