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

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

Issue 1160343003: Revert "fixes #173, ability to use native JS indexers" (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
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | test/codegen/domtest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 /// For example if we had the ClassDeclaration node for `FontElement`: 342 /// For example if we had the ClassDeclaration node for `FontElement`:
343 /// 343 ///
344 /// @JsName('HTMLFontElement') 344 /// @JsName('HTMLFontElement')
345 /// @deprecated 345 /// @deprecated
346 /// class FontElement { ... } 346 /// class FontElement { ... }
347 /// 347 ///
348 /// We could match `@deprecated` with a test function like: 348 /// We could match `@deprecated` with a test function like:
349 /// 349 ///
350 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore 350 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore
351 /// 351 ///
352 DartObjectImpl findNodeAnnotation( 352 DartObjectImpl getAnnotationValue(
353 AnnotatedNode node, bool test(DartObjectImpl value)) { 353 AnnotatedNode node, bool test(DartObjectImpl value)) {
354 for (var metadata in node.metadata) { 354 for (var metadata in node.metadata) {
355 ElementAnnotationImpl element = metadata.elementAnnotation; 355 ElementAnnotationImpl element = metadata.elementAnnotation;
356 if (element == null) continue; 356 if (element == null) continue;
357 357
358 var evalResult = element.evaluationResult; 358 var evalResult = element.evaluationResult;
359 if (evalResult == null) continue; 359 if (evalResult == null) continue;
360 360
361 var value = evalResult.value; 361 var value = evalResult.value;
362 if (value != null && test(value)) return value; 362 if (value != null && test(value)) return value;
363 } 363 }
364 return null; 364 return null;
365 } 365 }
366 366
367 /// Similar to [findNodeAnnotation] but starts from any element.
368 DartObjectImpl findElementAnnotation(
369 Element element, bool test(DartObjectImpl value)) {
370 for (var metadata in element.metadata) {
371 var evalResult = metadata.evaluationResult;
372 if (evalResult == null) continue;
373
374 var value = evalResult.value;
375 if (value != null && test(value)) return value;
376 }
377 return null;
378 }
379
380 /// Given a constant [value], a [fieldName], and an [expectedType], returns the 367 /// Given a constant [value], a [fieldName], and an [expectedType], returns the
381 /// value of that field. 368 /// value of that field.
382 /// 369 ///
383 /// If the field is missing or is not [expectedType], returns null. 370 /// If the field is missing or is not [expectedType], returns null.
384 Object getConstantField( 371 Object getConstantField(
385 DartObjectImpl value, String fieldName, DartType expectedType) { 372 DartObjectImpl value, String fieldName, DartType expectedType) {
386 if (value == null) return null; 373 if (value == null) return null;
387 var f = value.fields[fieldName]; 374 var f = value.fields[fieldName];
388 return (f == null || f.type != expectedType) ? null : f.value; 375 return (f == null || f.type != expectedType) ? null : f.value;
389 } 376 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 int lineEnd = endLoc.offset; 453 int lineEnd = endLoc.offset;
467 int unitEnd = unit.endToken.end; 454 int unitEnd = unit.endToken.end;
468 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; 455 int lineNum = lineInfo.getLocation(lineEnd).lineNumber;
469 while (lineEnd < unitEnd && 456 while (lineEnd < unitEnd &&
470 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); 457 lineInfo.getLocation(++lineEnd).lineNumber == lineNum);
471 458
472 var text = content.substring(start, end); 459 var text = content.substring(start, end);
473 var lineText = content.substring(lineStart, lineEnd); 460 var lineText = content.substring(lineStart, lineEnd);
474 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); 461 return new SourceSpanWithContext(startLoc, endLoc, text, lineText);
475 } 462 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | test/codegen/domtest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698