| OLD | NEW |
| 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 checkNames( | 103 checkNames( |
| 104 Uri targetUri, Uri mapUri, SingleMapping sourceMap, CompilerImpl compiler) { | 104 Uri targetUri, Uri mapUri, SingleMapping sourceMap, CompilerImpl compiler) { |
| 105 Map<Uri, CompilationUnitElement> compilationUnitMap = {}; | 105 Map<Uri, CompilationUnitElement> compilationUnitMap = {}; |
| 106 | 106 |
| 107 void mapCompilationUnits(LibraryElement library) { | 107 void mapCompilationUnits(LibraryElement library) { |
| 108 library.compilationUnits.forEach((CompilationUnitElement compilationUnit) { | 108 library.compilationUnits.forEach((CompilationUnitElement compilationUnit) { |
| 109 compilationUnitMap[compilationUnit.script.readableUri] = compilationUnit; | 109 compilationUnitMap[compilationUnit.script.readableUri] = compilationUnit; |
| 110 }); | 110 }); |
| 111 } | 111 } |
| 112 | 112 |
| 113 compiler.libraryLoader.libraries.forEach((LibraryElement library) { | 113 compiler.libraryLoader.libraries.forEach((_library) { |
| 114 LibraryElement library = _library; |
| 114 mapCompilationUnits(library); | 115 mapCompilationUnits(library); |
| 115 if (library.patch != null) { | 116 if (library.patch != null) { |
| 116 mapCompilationUnits(library.patch); | 117 mapCompilationUnits(library.patch); |
| 117 } | 118 } |
| 118 }); | 119 }); |
| 119 | 120 |
| 120 sourceMap.lines.forEach((TargetLineEntry line) { | 121 sourceMap.lines.forEach((TargetLineEntry line) { |
| 121 for (TargetEntry entry in line.entries) { | 122 for (TargetEntry entry in line.entries) { |
| 122 if (entry.sourceNameId != null) { | 123 if (entry.sourceNameId != null) { |
| 123 Uri uri = mapUri.resolve(sourceMap.urls[entry.sourceUrlId]); | 124 Uri uri = mapUri.resolve(sourceMap.urls[entry.sourceUrlId]); |
| 124 Position targetPosition = new Position(line.line, entry.column); | |
| 125 Position sourcePosition = | 125 Position sourcePosition = |
| 126 new Position(entry.sourceLine, entry.sourceColumn); | 126 new Position(entry.sourceLine, entry.sourceColumn); |
| 127 String name = sourceMap.names[entry.sourceNameId]; | 127 String name = sourceMap.names[entry.sourceNameId]; |
| 128 | 128 |
| 129 CompilationUnitElement compilationUnit = compilationUnitMap[uri]; | 129 CompilationUnitElement compilationUnit = compilationUnitMap[uri]; |
| 130 Expect.isNotNull( | 130 Expect.isNotNull( |
| 131 compilationUnit, "No compilation unit found for $uri."); | 131 compilationUnit, "No compilation unit found for $uri."); |
| 132 | 132 |
| 133 SourceFile sourceFile = compilationUnit.script.file; | 133 SourceFile sourceFile = compilationUnit.script.file; |
| 134 | 134 |
| 135 Position positionFromOffset(int offset) { | 135 Position positionFromOffset(int offset) { |
| 136 Location location = sourceFile.getLocation(offset); | 136 Location location = sourceFile.getLocation(offset); |
| 137 int line = location.line - 1; | 137 int line = location.line - 1; |
| 138 int column = location.column - 1; | 138 int column = location.column - 1; |
| 139 return new Position(line, column); | 139 return new Position(line, column); |
| 140 } | 140 } |
| 141 | 141 |
| 142 Interval intervalFromElement(AstElement element) { | 142 Interval intervalFromElement(AstElement element) { |
| 143 if (!element.hasNode) return null; | 143 if (!element.hasNode) return null; |
| 144 | 144 |
| 145 var begin = element.node.getBeginToken().charOffset; | 145 var begin = element.node.getBeginToken().charOffset; |
| 146 var end = element.node.getEndToken(); | 146 var endToken = element.node.getEndToken(); |
| 147 end = end.charOffset + end.charCount; | 147 int end = endToken.charOffset + endToken.charCount; |
| 148 return new Interval( | 148 return new Interval( |
| 149 positionFromOffset(begin), positionFromOffset(end)); | 149 positionFromOffset(begin), positionFromOffset(end)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 AstElement findInnermost(AstElement element) { | 152 AstElement findInnermost(AstElement element) { |
| 153 bool isInsideElement(FunctionElement closure) { | 153 bool isInsideElement(FunctionElement closure) { |
| 154 Element enclosing = closure; | 154 Element enclosing = closure; |
| 155 while (enclosing != null) { | 155 while (enclosing != null) { |
| 156 if (enclosing == element) return true; | 156 if (enclosing == element) return true; |
| 157 enclosing = enclosing.enclosingElement; | 157 enclosing = enclosing.enclosingElement; |
| 158 } | 158 } |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 if (element is MemberElement) { | 162 if (element is MemberElement) { |
| 163 MemberElement member = element; | 163 MemberElement member = element; |
| 164 member.nestedClosures.forEach((closure) { | 164 member.nestedClosures.forEach((dynamic closure) { |
| 165 var localFunction = closure.expression; | 165 var localFunction = closure.expression; |
| 166 Interval interval = intervalFromElement(localFunction); | 166 Interval interval = intervalFromElement(localFunction); |
| 167 if (interval != null && | 167 if (interval != null && |
| 168 interval.contains(sourcePosition) && | 168 interval.contains(sourcePosition) && |
| 169 isInsideElement(localFunction)) { | 169 isInsideElement(localFunction)) { |
| 170 element = localFunction; | 170 element = localFunction; |
| 171 } | 171 } |
| 172 }); | 172 }); |
| 173 } | 173 } |
| 174 return element; | 174 return element; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 200 Expect.equals( | 200 Expect.equals( |
| 201 expectedName, | 201 expectedName, |
| 202 name, | 202 name, |
| 203 "Unexpected name '${name}', " | 203 "Unexpected name '${name}', " |
| 204 "expected '${expectedName}' or for $innerElement."); | 204 "expected '${expectedName}' or for $innerElement."); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 compilationUnit.forEachLocalMember((AstElement element) { | 210 compilationUnit.forEachLocalMember((Element element) { |
| 211 if (element.isClass) { | 211 if (element.isClass) { |
| 212 ClassElement classElement = element; | 212 ClassElement classElement = element; |
| 213 classElement.forEachLocalMember(match); | 213 classElement.forEachLocalMember(match); |
| 214 } else { | 214 } else { |
| 215 match(element); | 215 match(element); |
| 216 } | 216 } |
| 217 }); | 217 }); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 }); | 220 }); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 final Position end; | 317 final Position end; |
| 318 | 318 |
| 319 Interval(this.begin, this.end); | 319 Interval(this.begin, this.end); |
| 320 | 320 |
| 321 bool contains(Position other) { | 321 bool contains(Position other) { |
| 322 return begin <= other && other <= end; | 322 return begin <= other && other <= end; |
| 323 } | 323 } |
| 324 | 324 |
| 325 String toString() => '$begin-$end'; | 325 String toString() => '$begin-$end'; |
| 326 } | 326 } |
| OLD | NEW |