| 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 /// Holds a couple utility functions used at various places in the system. | 5 /// Holds a couple utility functions used at various places in the system. |
| 6 library dev_compiler.src.utils; | 6 library dev_compiler.src.utils; |
| 7 | 7 |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } catch (e) { | 200 } catch (e) { |
| 201 // TODO(sigmund): remove this try-catch block (see issue #48). | 201 // TODO(sigmund): remove this try-catch block (see issue #48). |
| 202 } | 202 } |
| 203 if (baseMethod == null || baseMethod.isStatic) return null; | 203 if (baseMethod == null || baseMethod.isStatic) return null; |
| 204 return baseMethod.type; | 204 return baseMethod.type; |
| 205 } | 205 } |
| 206 ; | 206 ; |
| 207 return f; | 207 return f; |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool isDynamicTarget(Expression node) { | 210 bool isDynamicTarget(Expression node) => |
| 211 if (node == null) return false; | 211 node != null && !isLibraryPrefix(node) && node.staticType.isDynamic; |
| 212 var type = node.staticType; | |
| 213 | |
| 214 // This is an unknown identifier, like an import that doesn't resolve. | |
| 215 if (type == null) return true; | |
| 216 | |
| 217 return type.isDynamic && !isLibraryPrefix(node); | |
| 218 } | |
| 219 | 212 |
| 220 bool isLibraryPrefix(Expression node) => | 213 bool isLibraryPrefix(Expression node) => |
| 221 node is SimpleIdentifier && node.staticElement is PrefixElement; | 214 node is SimpleIdentifier && node.staticElement is PrefixElement; |
| 222 | 215 |
| 223 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors | 216 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors |
| 224 /// are defined for: severe, error, warning, or info. Returns null if the level | 217 /// are defined for: severe, error, warning, or info. Returns null if the level |
| 225 /// name is not recognized. | 218 /// name is not recognized. |
| 226 String colorOf(String levelName) { | 219 String colorOf(String levelName) { |
| 227 levelName = levelName.toLowerCase(); | 220 levelName = levelName.toLowerCase(); |
| 228 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') { | 221 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 int lineEnd = endLoc.offset; | 453 int lineEnd = endLoc.offset; |
| 461 int unitEnd = unit.endToken.end; | 454 int unitEnd = unit.endToken.end; |
| 462 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; | 455 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; |
| 463 while (lineEnd < unitEnd && | 456 while (lineEnd < unitEnd && |
| 464 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); | 457 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); |
| 465 | 458 |
| 466 var text = content.substring(start, end); | 459 var text = content.substring(start, end); |
| 467 var lineText = content.substring(lineStart, lineEnd); | 460 var lineText = content.substring(lineStart, lineEnd); |
| 468 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); | 461 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); |
| 469 } | 462 } |
| OLD | NEW |