Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: pkg/analyzer/lib/src/dart/constant/value.dart

Issue 1917203002: Remove more type casts (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /** 5 /**
6 * The implementation of the class [DartObject]. 6 * The implementation of the class [DartObject].
7 */ 7 */
8 library analyzer.src.dart.constant.value; 8 library analyzer.src.dart.constant.value;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 bool get isUnknown => _state.isUnknown; 207 bool get isUnknown => _state.isUnknown;
208 208
209 /** 209 /**
210 * Return `true` if this object represents an instance of a user-defined 210 * Return `true` if this object represents an instance of a user-defined
211 * class. 211 * class.
212 */ 212 */
213 bool get isUserDefinedObject => _state is GenericState; 213 bool get isUserDefinedObject => _state is GenericState;
214 214
215 @override 215 @override
216 bool operator ==(Object object) { 216 bool operator ==(Object object) {
217 if (object is! DartObjectImpl) { 217 if (object is DartObjectImpl) {
218 return false; 218 return type == object.type && _state == object._state;
219 } 219 }
220 DartObjectImpl dartObject = object as DartObjectImpl; 220 return false;
221 return type == dartObject.type && _state == dartObject._state;
222 } 221 }
223 222
224 /** 223 /**
225 * Return the result of invoking the '+' operator on this object with the 224 * Return the result of invoking the '+' operator on this object with the
226 * given [rightOperand]. The [typeProvider] is the type provider used to find 225 * given [rightOperand]. The [typeProvider] is the type provider used to find
227 * known types. 226 * known types.
228 * 227 *
229 * Throws an [EvaluationException] if the operator is not appropriate for an 228 * Throws an [EvaluationException] if the operator is not appropriate for an
230 * object of this kind. 229 * object of this kind.
231 */ 230 */
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 } 1347 }
1349 1348
1350 @override 1349 @override
1351 bool get isUnknown => identical(this, UNKNOWN_VALUE); 1350 bool get isUnknown => identical(this, UNKNOWN_VALUE);
1352 1351
1353 @override 1352 @override
1354 String get typeName => "user defined type"; 1353 String get typeName => "user defined type";
1355 1354
1356 @override 1355 @override
1357 bool operator ==(Object object) { 1356 bool operator ==(Object object) {
1358 if (object is! GenericState) { 1357 if (object is GenericState) {
1359 return false; 1358 HashSet<String> otherFields =
1359 new HashSet<String>.from(object._fieldMap.keys.toSet());
1360 for (String fieldName in _fieldMap.keys.toSet()) {
1361 if (_fieldMap[fieldName] != object._fieldMap[fieldName]) {
1362 return false;
1363 }
1364 otherFields.remove(fieldName);
1365 }
1366 for (String fieldName in otherFields) {
1367 if (object._fieldMap[fieldName] != _fieldMap[fieldName]) {
1368 return false;
1369 }
1370 }
1371 return true;
1360 } 1372 }
1361 GenericState state = object as GenericState; 1373 return false;
1362 HashSet<String> otherFields =
1363 new HashSet<String>.from(state._fieldMap.keys.toSet());
1364 for (String fieldName in _fieldMap.keys.toSet()) {
1365 if (_fieldMap[fieldName] != state._fieldMap[fieldName]) {
1366 return false;
1367 }
1368 otherFields.remove(fieldName);
1369 }
1370 for (String fieldName in otherFields) {
1371 if (state._fieldMap[fieldName] != _fieldMap[fieldName]) {
1372 return false;
1373 }
1374 }
1375 return true;
1376 } 1374 }
1377 1375
1378 @override 1376 @override
1379 StringState convertToString() => StringState.UNKNOWN_VALUE; 1377 StringState convertToString() => StringState.UNKNOWN_VALUE;
1380 1378
1381 @override 1379 @override
1382 BoolState equalEqual(InstanceState rightOperand) { 1380 BoolState equalEqual(InstanceState rightOperand) {
1383 assertBoolNumStringOrNull(rightOperand); 1381 assertBoolNumStringOrNull(rightOperand);
1384 return isIdentical(rightOperand); 1382 return isIdentical(rightOperand);
1385 } 1383 }
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 value = (value << 3) ^ _elements[i].hashCode; 2299 value = (value << 3) ^ _elements[i].hashCode;
2302 } 2300 }
2303 return value; 2301 return value;
2304 } 2302 }
2305 2303
2306 @override 2304 @override
2307 String get typeName => "List"; 2305 String get typeName => "List";
2308 2306
2309 @override 2307 @override
2310 bool operator ==(Object object) { 2308 bool operator ==(Object object) {
2311 if (object is! ListState) { 2309 if (object is ListState) {
2312 return false; 2310 List<DartObjectImpl> otherElements = object._elements;
2313 } 2311 int count = _elements.length;
2314 List<DartObjectImpl> otherElements = (object as ListState)._elements; 2312 if (otherElements.length != count) {
2315 int count = _elements.length; 2313 return false;
2316 if (otherElements.length != count) { 2314 } else if (count == 0) {
2317 return false; 2315 return true;
2318 } else if (count == 0) { 2316 }
2317 for (int i = 0; i < count; i++) {
2318 if (_elements[i] != otherElements[i]) {
2319 return false;
2320 }
2321 }
2319 return true; 2322 return true;
2320 } 2323 }
2321 for (int i = 0; i < count; i++) { 2324 return false;
2322 if (_elements[i] != otherElements[i]) {
2323 return false;
2324 }
2325 }
2326 return true;
2327 } 2325 }
2328 2326
2329 @override 2327 @override
2330 StringState convertToString() => StringState.UNKNOWN_VALUE; 2328 StringState convertToString() => StringState.UNKNOWN_VALUE;
2331 2329
2332 @override 2330 @override
2333 BoolState equalEqual(InstanceState rightOperand) { 2331 BoolState equalEqual(InstanceState rightOperand) {
2334 assertBoolNumStringOrNull(rightOperand); 2332 assertBoolNumStringOrNull(rightOperand);
2335 return isIdentical(rightOperand); 2333 return isIdentical(rightOperand);
2336 } 2334 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 value = (value << 3) ^ key.hashCode; 2381 value = (value << 3) ^ key.hashCode;
2384 } 2382 }
2385 return value; 2383 return value;
2386 } 2384 }
2387 2385
2388 @override 2386 @override
2389 String get typeName => "Map"; 2387 String get typeName => "Map";
2390 2388
2391 @override 2389 @override
2392 bool operator ==(Object object) { 2390 bool operator ==(Object object) {
2393 if (object is! MapState) { 2391 if (object is MapState) {
2394 return false; 2392 HashMap<DartObjectImpl, DartObjectImpl> otherElements = object._entries;
2395 } 2393 int count = _entries.length;
2396 HashMap<DartObjectImpl, DartObjectImpl> otherElements = 2394 if (otherElements.length != count) {
2397 (object as MapState)._entries; 2395 return false;
2398 int count = _entries.length; 2396 } else if (count == 0) {
2399 if (otherElements.length != count) { 2397 return true;
2400 return false; 2398 }
2401 } else if (count == 0) { 2399 for (DartObjectImpl key in _entries.keys) {
2400 DartObjectImpl value = _entries[key];
2401 DartObjectImpl otherValue = otherElements[key];
2402 if (value != otherValue) {
2403 return false;
2404 }
2405 }
2402 return true; 2406 return true;
2403 } 2407 }
2404 for (DartObjectImpl key in _entries.keys) { 2408 return false;
2405 DartObjectImpl value = _entries[key];
2406 DartObjectImpl otherValue = otherElements[key];
2407 if (value != otherValue) {
2408 return false;
2409 }
2410 }
2411 return true;
2412 } 2409 }
2413 2410
2414 @override 2411 @override
2415 StringState convertToString() => StringState.UNKNOWN_VALUE; 2412 StringState convertToString() => StringState.UNKNOWN_VALUE;
2416 2413
2417 @override 2414 @override
2418 BoolState equalEqual(InstanceState rightOperand) { 2415 BoolState equalEqual(InstanceState rightOperand) {
2419 assertBoolNumStringOrNull(rightOperand); 2416 assertBoolNumStringOrNull(rightOperand);
2420 return isIdentical(rightOperand); 2417 return isIdentical(rightOperand);
2421 } 2418 }
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2818 return BoolState.from(_element == rightElement); 2815 return BoolState.from(_element == rightElement);
2819 } else if (rightOperand is DynamicState) { 2816 } else if (rightOperand is DynamicState) {
2820 return BoolState.UNKNOWN_VALUE; 2817 return BoolState.UNKNOWN_VALUE;
2821 } 2818 }
2822 return BoolState.FALSE_STATE; 2819 return BoolState.FALSE_STATE;
2823 } 2820 }
2824 2821
2825 @override 2822 @override
2826 String toString() => _element == null ? "-unknown-" : _element.name; 2823 String toString() => _element == null ? "-unknown-" : _element.name;
2827 } 2824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698