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

Side by Side Diff: lib/src/utils.dart

Issue 1153003003: fixes #40, extension methods for primitive types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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) 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 for (var m in type.mixins.reversed) { 424 for (var m in type.mixins.reversed) {
425 if (match(m)) return m; 425 if (match(m)) return m;
426 } 426 }
427 var s = type.superclass; 427 var s = type.superclass;
428 if (s == null) return null; 428 if (s == null) return null;
429 429
430 if (match(s)) return type; 430 if (match(s)) return type;
431 return findSupertype(s, match); 431 return findSupertype(s, match);
432 } 432 }
433 433
434
434 SourceSpanWithContext createSpan( 435 SourceSpanWithContext createSpan(
435 AnalysisContext context, CompilationUnit unit, int start, int end, 436 AnalysisContext context, CompilationUnit unit, int start, int end,
436 [Source source]) { 437 [Source source]) {
437 if (source == null) source = unit.element.source; 438 if (source == null) source = unit.element.source;
438 var content = context.getContents(source).data; 439 var content = context.getContents(source).data;
439 return createSpanHelper(unit, start, end, source, content); 440 return createSpanHelper(unit, start, end, source, content);
440 } 441 }
441 442
442 SourceSpanWithContext createSpanHelper( 443 SourceSpanWithContext createSpanHelper(
443 CompilationUnit unit, int start, int end, Source source, String content) { 444 CompilationUnit unit, int start, int end, Source source, String content) {
444 var startLoc = locationForOffset(unit, source.uri, start); 445 var startLoc = locationForOffset(unit, source.uri, start);
445 var endLoc = locationForOffset(unit, source.uri, end); 446 var endLoc = locationForOffset(unit, source.uri, end);
446 447
447 var lineStart = startLoc.offset - startLoc.column; 448 var lineStart = startLoc.offset - startLoc.column;
448 // Find the end of the line. This is not exposed directly on LineInfo, but 449 // Find the end of the line. This is not exposed directly on LineInfo, but
449 // we can find it pretty easily. 450 // we can find it pretty easily.
450 // TODO(jmesserly): for now we do the simple linear scan. Ideally we can get 451 // TODO(jmesserly): for now we do the simple linear scan. Ideally we can get
451 // some help from the LineInfo API. 452 // some help from the LineInfo API.
452 var lineInfo = unit.lineInfo; 453 var lineInfo = unit.lineInfo;
453 int lineEnd = endLoc.offset; 454 int lineEnd = endLoc.offset;
454 int unitEnd = unit.endToken.end; 455 int unitEnd = unit.endToken.end;
455 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; 456 int lineNum = lineInfo.getLocation(lineEnd).lineNumber;
456 while (lineEnd < unitEnd && 457 while (lineEnd < unitEnd &&
457 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); 458 lineInfo.getLocation(++lineEnd).lineNumber == lineNum);
458 459
459 var text = content.substring(start, end); 460 var text = content.substring(start, end);
460 var lineText = content.substring(lineStart, lineEnd); 461 var lineText = content.substring(lineStart, lineEnd);
461 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); 462 return new SourceSpanWithContext(startLoc, endLoc, text, lineText);
462 } 463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698