| 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 node != null && !isLibraryPrefix(node) && node.staticType.isDynamic; | 211 if (node == null) return false; |
| 212 |
| 213 if (isLibraryPrefix(node)) return false; |
| 214 |
| 215 // Null type happens when we have unknown identifiers, like a dart: import |
| 216 // that doesn't resolve. |
| 217 var type = node.staticType; |
| 218 return type == null || type.isDynamic; |
| 219 } |
| 212 | 220 |
| 213 bool isLibraryPrefix(Expression node) => | 221 bool isLibraryPrefix(Expression node) => |
| 214 node is SimpleIdentifier && node.staticElement is PrefixElement; | 222 node is SimpleIdentifier && node.staticElement is PrefixElement; |
| 215 | 223 |
| 216 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors | 224 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors |
| 217 /// are defined for: severe, error, warning, or info. Returns null if the level | 225 /// are defined for: severe, error, warning, or info. Returns null if the level |
| 218 /// name is not recognized. | 226 /// name is not recognized. |
| 219 String colorOf(String levelName) { | 227 String colorOf(String levelName) { |
| 220 levelName = levelName.toLowerCase(); | 228 levelName = levelName.toLowerCase(); |
| 221 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') { | 229 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 int lineEnd = endLoc.offset; | 461 int lineEnd = endLoc.offset; |
| 454 int unitEnd = unit.endToken.end; | 462 int unitEnd = unit.endToken.end; |
| 455 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; | 463 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; |
| 456 while (lineEnd < unitEnd && | 464 while (lineEnd < unitEnd && |
| 457 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); | 465 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); |
| 458 | 466 |
| 459 var text = content.substring(start, end); | 467 var text = content.substring(start, end); |
| 460 var lineText = content.substring(lineStart, lineEnd); | 468 var lineText = content.substring(lineStart, lineEnd); |
| 461 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); | 469 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); |
| 462 } | 470 } |
| OLD | NEW |