| 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 library analysis_server.src.get_handler; | 5 library analysis_server.src.status.get_handler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 import 'dart:math'; | 11 import 'dart:math'; |
| 12 | 12 |
| 13 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
| 14 import 'package:analysis_server/src/domain_completion.dart'; | 14 import 'package:analysis_server/src/domain_completion.dart'; |
| 15 import 'package:analysis_server/src/domain_execution.dart'; | 15 import 'package:analysis_server/src/domain_execution.dart'; |
| 16 import 'package:analysis_server/src/operation/operation.dart'; | 16 import 'package:analysis_server/src/operation/operation.dart'; |
| 17 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 17 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 18 import 'package:analysis_server/src/operation/operation_queue.dart'; | 18 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 19 import 'package:analysis_server/src/protocol.dart' hide Element; | 19 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 20 import 'package:analysis_server/src/services/index/index.dart'; | 20 import 'package:analysis_server/src/services/index/index.dart'; |
| 21 import 'package:analysis_server/src/services/index/local_index.dart'; | 21 import 'package:analysis_server/src/services/index/local_index.dart'; |
| 22 import 'package:analysis_server/src/services/index/store/split_store.dart'; | 22 import 'package:analysis_server/src/services/index/store/split_store.dart'; |
| 23 import 'package:analysis_server/src/socket_server.dart'; | 23 import 'package:analysis_server/src/socket_server.dart'; |
| 24 import 'package:analysis_server/src/status/ast_writer.dart'; | 24 import 'package:analysis_server/src/status/ast_writer.dart'; |
| 25 import 'package:analysis_server/src/status/element_writer.dart'; | 25 import 'package:analysis_server/src/status/element_writer.dart'; |
| 26 import 'package:analyzer/file_system/file_system.dart'; | 26 import 'package:analyzer/file_system/file_system.dart'; |
| 27 import 'package:analyzer/src/context/cache.dart'; |
| 27 import 'package:analyzer/src/generated/ast.dart'; | 28 import 'package:analyzer/src/generated/ast.dart'; |
| 28 import 'package:analyzer/src/generated/element.dart'; | 29 import 'package:analyzer/src/generated/element.dart'; |
| 29 import 'package:analyzer/src/generated/engine.dart'; | 30 import 'package:analyzer/src/generated/engine.dart' |
| 31 hide AnalysisContextImpl, AnalysisTask; |
| 30 import 'package:analyzer/src/generated/java_engine.dart'; | 32 import 'package:analyzer/src/generated/java_engine.dart'; |
| 31 import 'package:analyzer/src/generated/source.dart'; | 33 import 'package:analyzer/src/generated/source.dart'; |
| 34 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 32 import 'package:analyzer/src/generated/utilities_general.dart'; | 35 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 33 import 'package:analyzer/task/model.dart' as newTask; | 36 import 'package:analyzer/src/task/dart.dart'; |
| 37 import 'package:analyzer/task/dart.dart'; |
| 38 import 'package:analyzer/task/model.dart'; |
| 34 import 'package:plugin/plugin.dart'; | 39 import 'package:plugin/plugin.dart'; |
| 35 | 40 |
| 36 /** | 41 /** |
| 37 * A function that can be used to generate HTML output into the given [buffer]. | 42 * A function that can be used to generate HTML output into the given [buffer]. |
| 38 * The HTML that is generated must be valid (special characters must already be | 43 * The HTML that is generated must be valid (special characters must already be |
| 39 * encoded). | 44 * encoded). |
| 40 */ | 45 */ |
| 41 typedef void HtmlGenerator(StringBuffer buffer); | 46 typedef void HtmlGenerator(StringBuffer buffer); |
| 42 | 47 |
| 43 /** | 48 /** |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 /** | 220 /** |
| 216 * Return the folder being managed by the given [analysisServer] that matches | 221 * Return the folder being managed by the given [analysisServer] that matches |
| 217 * the given [contextFilter], or `null` if there is none. | 222 * the given [contextFilter], or `null` if there is none. |
| 218 */ | 223 */ |
| 219 Folder _findFolder(AnalysisServer analysisServer, String contextFilter) { | 224 Folder _findFolder(AnalysisServer analysisServer, String contextFilter) { |
| 220 return analysisServer.folderMap.keys.firstWhere( | 225 return analysisServer.folderMap.keys.firstWhere( |
| 221 (Folder folder) => folder.path == contextFilter, orElse: () => null); | 226 (Folder folder) => folder.path == contextFilter, orElse: () => null); |
| 222 } | 227 } |
| 223 | 228 |
| 224 /** | 229 /** |
| 230 * Return any AST structure stored in the given [entry]. |
| 231 */ |
| 232 CompilationUnit _getAnyAst(CacheEntry entry) { |
| 233 CompilationUnit unit = entry.getValue(PARSED_UNIT); |
| 234 if (unit != null) { |
| 235 return unit; |
| 236 } |
| 237 unit = entry.getValue(RESOLVED_UNIT1); |
| 238 if (unit != null) { |
| 239 return unit; |
| 240 } |
| 241 unit = entry.getValue(RESOLVED_UNIT2); |
| 242 if (unit != null) { |
| 243 return unit; |
| 244 } |
| 245 unit = entry.getValue(RESOLVED_UNIT3); |
| 246 if (unit != null) { |
| 247 return unit; |
| 248 } |
| 249 unit = entry.getValue(RESOLVED_UNIT4); |
| 250 if (unit != null) { |
| 251 return unit; |
| 252 } |
| 253 unit = entry.getValue(RESOLVED_UNIT5); |
| 254 if (unit != null) { |
| 255 return unit; |
| 256 } |
| 257 return entry.getValue(RESOLVED_UNIT); |
| 258 } |
| 259 |
| 260 /** |
| 225 * Return `true` if the given analysis [context] has at least one entry with | 261 * Return `true` if the given analysis [context] has at least one entry with |
| 226 * an exception. | 262 * an exception. |
| 227 */ | 263 */ |
| 228 bool _hasException(AnalysisContextImpl context) { | 264 bool _hasException(InternalAnalysisContext context) { |
| 229 bool hasException = false; | 265 MapIterator<AnalysisTarget, CacheEntry> iterator = |
| 230 context.visitCacheItems((Source source, SourceEntry sourceEntry, | 266 context.analysisCache.iterator(); |
| 231 DataDescriptor rowDesc, CacheState state) { | 267 while (iterator.moveNext()) { |
| 232 if (sourceEntry.exception != null) { | 268 if (iterator.value.exception != null) { |
| 233 hasException = true; | 269 return true; |
| 234 } | 270 } |
| 235 }); | 271 } |
| 236 return hasException; | 272 return false; |
| 237 } | 273 } |
| 238 | 274 |
| 239 /** | 275 /** |
| 240 * Return the folder in the [folderMap] with which the given [context] is | 276 * Return the folder in the [folderMap] with which the given [context] is |
| 241 * associated. | 277 * associated. |
| 242 */ | 278 */ |
| 243 Folder _keyForValue( | 279 Folder _keyForValue( |
| 244 Map<Folder, AnalysisContext> folderMap, AnalysisContext context) { | 280 Map<Folder, AnalysisContext> folderMap, AnalysisContext context) { |
| 245 for (Folder folder in folderMap.keys) { | 281 for (Folder folder in folderMap.keys) { |
| 246 if (folderMap[folder] == context) { | 282 if (folderMap[folder] == context) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 buffer.write('<p><b>Task performace data</b></p>'); | 335 buffer.write('<p><b>Task performace data</b></p>'); |
| 300 buffer.write( | 336 buffer.write( |
| 301 '<table style="border-collapse: separate; border-spacing: 10px 5px
;">'); | 337 '<table style="border-collapse: separate; border-spacing: 10px 5px
;">'); |
| 302 _writeRow(buffer, [ | 338 _writeRow(buffer, [ |
| 303 'Task Name', | 339 'Task Name', |
| 304 'Count', | 340 'Count', |
| 305 'Total Time (in ms)', | 341 'Total Time (in ms)', |
| 306 'Average Time (in ms)' | 342 'Average Time (in ms)' |
| 307 ], header: true); | 343 ], header: true); |
| 308 | 344 |
| 309 Map<Type, int> countMap = newTask.AnalysisTask.countMap; | 345 Map<Type, int> countMap = AnalysisTask.countMap; |
| 310 Map<Type, Stopwatch> stopwatchMap = newTask.AnalysisTask.stopwatchMap; | 346 Map<Type, Stopwatch> stopwatchMap = AnalysisTask.stopwatchMap; |
| 311 List<Type> taskClasses = stopwatchMap.keys.toList(); | 347 List<Type> taskClasses = stopwatchMap.keys.toList(); |
| 312 taskClasses.sort((Type first, Type second) => | 348 taskClasses.sort((Type first, Type second) => |
| 313 first.toString().compareTo(second.toString())); | 349 first.toString().compareTo(second.toString())); |
| 314 int totalTime = 0; | 350 int totalTime = 0; |
| 315 taskClasses.forEach((Type taskClass) { | 351 taskClasses.forEach((Type taskClass) { |
| 316 int count = countMap[taskClass]; | 352 int count = countMap[taskClass]; |
| 317 if (count == null) { | 353 if (count == null) { |
| 318 count = 0; | 354 count = 0; |
| 319 } | 355 } |
| 320 int taskTime = stopwatchMap[taskClass].elapsedMilliseconds; | 356 int taskTime = stopwatchMap[taskClass].elapsedMilliseconds; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 Folder folder = _findFolder(analysisServer, contextFilter); | 418 Folder folder = _findFolder(analysisServer, contextFilter); |
| 383 if (folder == null) { | 419 if (folder == null) { |
| 384 return _returnFailure(request, 'Invalid context: $contextFilter'); | 420 return _returnFailure(request, 'Invalid context: $contextFilter'); |
| 385 } | 421 } |
| 386 String sourceUri = request.uri.queryParameters[SOURCE_QUERY_PARAM]; | 422 String sourceUri = request.uri.queryParameters[SOURCE_QUERY_PARAM]; |
| 387 if (sourceUri == null) { | 423 if (sourceUri == null) { |
| 388 return _returnFailure( | 424 return _returnFailure( |
| 389 request, 'Query parameter $SOURCE_QUERY_PARAM required'); | 425 request, 'Query parameter $SOURCE_QUERY_PARAM required'); |
| 390 } | 426 } |
| 391 | 427 |
| 392 AnalysisContextImpl context = analysisServer.folderMap[folder]; | 428 InternalAnalysisContext context = analysisServer.folderMap[folder]; |
| 393 | 429 |
| 394 _writeResponse(request, (StringBuffer buffer) { | 430 _writeResponse(request, (StringBuffer buffer) { |
| 395 _writePage(buffer, 'Analysis Server - AST Structure', [ | 431 _writePage(buffer, 'Analysis Server - AST Structure', [ |
| 396 'Context: $contextFilter', | 432 'Context: $contextFilter', |
| 397 'File: $sourceUri' | 433 'File: $sourceUri' |
| 398 ], (HttpResponse) { | 434 ], (HttpResponse) { |
| 399 Source source = context.sourceFactory.forUri(sourceUri); | 435 Source source = context.sourceFactory.forUri(sourceUri); |
| 400 if (source == null) { | 436 if (source == null) { |
| 401 buffer.write('<p>Not found.</p>'); | 437 buffer.write('<p>Not found.</p>'); |
| 402 return; | 438 return; |
| 403 } | 439 } |
| 404 SourceEntry entry = context.getReadableSourceEntryOrNull(source); | 440 CacheEntry entry = context.analysisCache.get(source); |
| 405 if (entry == null) { | 441 if (entry == null) { |
| 406 buffer.write('<p>Not found.</p>'); | 442 buffer.write('<p>Not found.</p>'); |
| 407 return; | 443 return; |
| 408 } | 444 } |
| 409 CompilationUnit ast = (entry as DartEntry).anyParsedCompilationUnit; | 445 CompilationUnit ast = _getAnyAst(entry); |
| 410 if (ast == null) { | 446 if (ast == null) { |
| 411 buffer.write('<p>null</p>'); | 447 buffer.write('<p>null</p>'); |
| 412 return; | 448 return; |
| 413 } | 449 } |
| 414 AstWriter writer = new AstWriter(buffer); | 450 AstWriter writer = new AstWriter(buffer); |
| 415 ast.accept(writer); | 451 ast.accept(writer); |
| 416 if (writer.exceptions.isNotEmpty) { | 452 if (writer.exceptions.isNotEmpty) { |
| 417 buffer.write('<h3>Exceptions while creating page</h3>'); | 453 buffer.write('<h3>Exceptions while creating page</h3>'); |
| 418 for (CaughtException exception in writer.exceptions) { | 454 for (CaughtException exception in writer.exceptions) { |
| 419 _writeException(buffer, exception); | 455 _writeException(buffer, exception); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 441 if (folder == null) { | 477 if (folder == null) { |
| 442 return _returnFailure(request, 'Invalid context: $contextFilter'); | 478 return _returnFailure(request, 'Invalid context: $contextFilter'); |
| 443 } | 479 } |
| 444 String sourceUri = request.uri.queryParameters[SOURCE_QUERY_PARAM]; | 480 String sourceUri = request.uri.queryParameters[SOURCE_QUERY_PARAM]; |
| 445 if (sourceUri == null) { | 481 if (sourceUri == null) { |
| 446 return _returnFailure( | 482 return _returnFailure( |
| 447 request, 'Query parameter $SOURCE_QUERY_PARAM required'); | 483 request, 'Query parameter $SOURCE_QUERY_PARAM required'); |
| 448 } | 484 } |
| 449 | 485 |
| 450 List<Folder> allContexts = <Folder>[]; | 486 List<Folder> allContexts = <Folder>[]; |
| 451 Map<Folder, SourceEntry> entryMap = new HashMap<Folder, SourceEntry>(); | 487 Map<Folder, List<CacheEntry>> entryMap = |
| 488 new HashMap<Folder, List<CacheEntry>>(); |
| 452 analysisServer.folderMap | 489 analysisServer.folderMap |
| 453 .forEach((Folder folder, AnalysisContextImpl context) { | 490 .forEach((Folder folder, InternalAnalysisContext context) { |
| 454 Source source = context.sourceFactory.forUri(sourceUri); | 491 Source source = context.sourceFactory.forUri(sourceUri); |
| 455 if (source != null) { | 492 if (source != null) { |
| 456 SourceEntry entry = context.getReadableSourceEntryOrNull(source); | 493 MapIterator<AnalysisTarget, CacheEntry> iterator = |
| 457 if (entry != null) { | 494 context.analysisCache.iterator(); |
| 458 allContexts.add(folder); | 495 while (iterator.moveNext()) { |
| 459 entryMap[folder] = entry; | 496 if (source == iterator.key.source) { |
| 497 if (!allContexts.contains(folder)) { |
| 498 allContexts.add(folder); |
| 499 } |
| 500 List<CacheEntry> entries = entryMap[folder]; |
| 501 if (entries == null) { |
| 502 entries = <CacheEntry>[]; |
| 503 entryMap[folder] = entries; |
| 504 } |
| 505 entries.add(iterator.value); |
| 506 } |
| 460 } | 507 } |
| 461 } | 508 } |
| 462 }); | 509 }); |
| 463 allContexts.sort((Folder firstFolder, Folder secondFolder) => | 510 allContexts.sort((Folder firstFolder, Folder secondFolder) => |
| 464 firstFolder.path.compareTo(secondFolder.path)); | 511 firstFolder.path.compareTo(secondFolder.path)); |
| 465 AnalysisContextImpl context = analysisServer.folderMap[folder]; | 512 InternalAnalysisContext context = analysisServer.folderMap[folder]; |
| 466 | 513 |
| 467 _writeResponse(request, (StringBuffer buffer) { | 514 _writeResponse(request, (StringBuffer buffer) { |
| 468 _writePage(buffer, 'Analysis Server - Cache Entry', [ | 515 _writePage(buffer, 'Analysis Server - Cache Entry', [ |
| 469 'Context: $contextFilter', | 516 'Context: $contextFilter', |
| 470 'File: $sourceUri' | 517 'File: $sourceUri' |
| 471 ], (HttpResponse) { | 518 ], (HttpResponse) { |
| 472 buffer.write('<h3>Analyzing Contexts</h3><p>'); | 519 buffer.write('<h3>Analyzing Contexts</h3><p>'); |
| 473 bool first = true; | 520 bool first = true; |
| 474 allContexts.forEach((Folder folder) { | 521 allContexts.forEach((Folder folder) { |
| 475 if (first) { | 522 if (first) { |
| 476 first = false; | 523 first = false; |
| 477 } else { | 524 } else { |
| 478 buffer.write('<br>'); | 525 buffer.write('<br>'); |
| 479 } | 526 } |
| 480 AnalysisContextImpl analyzingContext = | 527 InternalAnalysisContext analyzingContext = |
| 481 analysisServer.folderMap[folder]; | 528 analysisServer.folderMap[folder]; |
| 482 if (analyzingContext == context) { | 529 if (analyzingContext == context) { |
| 483 buffer.write(folder.path); | 530 buffer.write(folder.path); |
| 484 } else { | 531 } else { |
| 485 buffer.write(makeLink(CACHE_ENTRY_PATH, { | 532 buffer.write(makeLink(CACHE_ENTRY_PATH, { |
| 486 CONTEXT_QUERY_PARAM: folder.path, | 533 CONTEXT_QUERY_PARAM: folder.path, |
| 487 SOURCE_QUERY_PARAM: sourceUri | 534 SOURCE_QUERY_PARAM: sourceUri |
| 488 }, HTML_ESCAPE.convert(folder.path))); | 535 }, HTML_ESCAPE.convert(folder.path))); |
| 489 } | 536 } |
| 490 if (entryMap[folder].explicitlyAdded) { | 537 if (entryMap[folder][0].explicitlyAdded) { |
| 491 buffer.write(' (explicit)'); | 538 buffer.write(' (explicit)'); |
| 492 } else { | 539 } else { |
| 493 buffer.write(' (implicit)'); | 540 buffer.write(' (implicit)'); |
| 494 } | 541 } |
| 495 }); | 542 }); |
| 496 buffer.write('</p>'); | 543 buffer.write('</p>'); |
| 497 | 544 |
| 498 SourceEntry entry = entryMap[folder]; | 545 List<CacheEntry> entries = entryMap[folder]; |
| 499 if (entry == null) { | 546 if (entries == null) { |
| 500 buffer.write('<p>Not being analyzed in this context.</p>'); | 547 buffer.write('<p>Not being analyzed in this context.</p>'); |
| 501 return; | 548 return; |
| 502 } | 549 } |
| 503 Map<String, String> linkParameters = <String, String>{ | 550 for (CacheEntry entry in entries) { |
| 504 CONTEXT_QUERY_PARAM: folder.path, | 551 Map<String, String> linkParameters = <String, String>{ |
| 505 SOURCE_QUERY_PARAM: sourceUri | 552 CONTEXT_QUERY_PARAM: folder.path, |
| 506 }; | 553 SOURCE_QUERY_PARAM: sourceUri |
| 554 }; |
| 555 List<ResultDescriptor> results = entry.nonInvalidResults; |
| 556 results.sort((ResultDescriptor first, ResultDescriptor second) => |
| 557 first.toString().compareTo(second.toString())); |
| 507 | 558 |
| 508 buffer.write('<h3>Library Independent</h3>'); | 559 buffer.write('<h3>'); |
| 509 _writeDescriptorTable(buffer, entry.descriptors, entry.getState, | 560 buffer.write(HTML_ESCAPE.convert(entry.target.toString())); |
| 510 entry.getValue, linkParameters); | 561 buffer.write('</h3>'); |
| 511 if (entry is DartEntry) { | 562 buffer.write('<dl>'); |
| 512 for (Source librarySource in entry.containingLibraries) { | 563 buffer.write('<dt>time</dt><dd>'); |
| 513 String libraryName = HTML_ESCAPE.convert(librarySource.fullName); | 564 buffer.write(entry.modificationTime); |
| 514 buffer.write('<h3>In library $libraryName:</h3>'); | 565 buffer.write('</dd></dl>'); |
| 515 _writeDescriptorTable(buffer, entry.libraryDescriptors, | 566 for (ResultDescriptor result in results) { |
| 516 (DataDescriptor descriptor) => | 567 ResultData data = entry.getResultData(result); |
| 517 entry.getStateInLibrary(descriptor, librarySource), | 568 String descriptorName = HTML_ESCAPE.convert(result.toString()); |
| 518 (DataDescriptor descriptor) => | 569 String descriptorState = HTML_ESCAPE.convert(data.state.toString()); |
| 519 entry.getValueInLibrary(descriptor, librarySource), | 570 buffer.write('<dt>$descriptorName ($descriptorState)</dt><dd>'); |
| 520 linkParameters); | 571 try { |
| 572 _writeValueAsHtml(buffer, data.value, linkParameters); |
| 573 } catch (exception) { |
| 574 buffer.write('(${HTML_ESCAPE.convert(exception.toString())})'); |
| 575 } |
| 576 buffer.write('</dd>'); |
| 521 } | 577 } |
| 522 } | 578 if (entry.exception != null) { |
| 523 if (entry.exception != null) { | 579 buffer.write('<dt>exception</dt><dd>'); |
| 524 buffer.write('<h3>Exception</h3>'); | 580 _writeException(buffer, entry.exception); |
| 525 _writeException(buffer, entry.exception); | 581 buffer.write('</dd></dl>'); |
| 582 } |
| 583 buffer.write('</dl>'); |
| 526 } | 584 } |
| 527 }); | 585 }); |
| 528 }); | 586 }); |
| 529 } | 587 } |
| 530 | 588 |
| 531 /** | 589 /** |
| 532 * Return a response indicating the set of source files in a certain cache | 590 * Return a response indicating the set of source files in a certain cache |
| 533 * state. | 591 * state. |
| 534 */ | 592 */ |
| 535 void _returnCacheState(HttpRequest request) { | 593 void _returnCacheState(HttpRequest request) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 560 request, 'Query parameter $STATE_QUERY_PARAM is invalid'); | 618 request, 'Query parameter $STATE_QUERY_PARAM is invalid'); |
| 561 } | 619 } |
| 562 // Figure out which descriptor is being searched for. | 620 // Figure out which descriptor is being searched for. |
| 563 String descriptorFilter = | 621 String descriptorFilter = |
| 564 request.uri.queryParameters[DESCRIPTOR_QUERY_PARAM]; | 622 request.uri.queryParameters[DESCRIPTOR_QUERY_PARAM]; |
| 565 if (descriptorFilter == null) { | 623 if (descriptorFilter == null) { |
| 566 return _returnFailure( | 624 return _returnFailure( |
| 567 request, 'Query parameter $DESCRIPTOR_QUERY_PARAM required'); | 625 request, 'Query parameter $DESCRIPTOR_QUERY_PARAM required'); |
| 568 } | 626 } |
| 569 | 627 |
| 570 Folder folder = _findFolder(analysisServer, contextFilter); | 628 // TODO(brianwilkerson) Figure out how to convert the 'descriptorFilter' to |
| 571 AnalysisContextImpl context = analysisServer.folderMap[folder]; | 629 // a ResultDescriptor so that we can query the state, then uncomment the |
| 572 List<String> links = <String>[]; | 630 // code below that computes and prints the list of links. |
| 573 context.visitCacheItems((Source source, SourceEntry dartEntry, | 631 // Folder folder = _findFolder(analysisServer, contextFilter); |
| 574 DataDescriptor rowDesc, CacheState state) { | 632 // InternalAnalysisContext context = analysisServer.folderMap[folder]; |
| 575 if (state != stateFilter || rowDesc.toString() != descriptorFilter) { | 633 // List<String> links = <String>[]; |
| 576 return; | 634 // MapIterator<AnalysisTarget, CacheEntry> iterator = context.analysisCache.i
terator(); |
| 577 } | 635 // while (iterator.moveNext()) { |
| 578 String link = makeLink(CACHE_ENTRY_PATH, { | 636 // Source source = iterator.key.source; |
| 579 CONTEXT_QUERY_PARAM: folder.path, | 637 // if (source != null) { |
| 580 SOURCE_QUERY_PARAM: source.uri.toString() | 638 // CacheEntry entry = iterator.value; |
| 581 }, HTML_ESCAPE.convert(source.fullName)); | 639 // if (entry.getState(result) == stateFilter) { |
| 582 links.add(link); | 640 // String link = makeLink(CACHE_ENTRY_PATH, { |
| 583 }); | 641 // CONTEXT_QUERY_PARAM: folder.path, |
| 642 // SOURCE_QUERY_PARAM: source.uri.toString() |
| 643 // }, HTML_ESCAPE.convert(source.fullName)); |
| 644 // links.add(link); |
| 645 // } |
| 646 // } |
| 647 // } |
| 584 | 648 |
| 585 _writeResponse(request, (StringBuffer buffer) { | 649 _writeResponse(request, (StringBuffer buffer) { |
| 586 _writePage(buffer, 'Analysis Server - Cache Search', [ | 650 _writePage(buffer, 'Analysis Server - Cache Search', [ |
| 587 'Context: $contextFilter', | 651 'Context: $contextFilter', |
| 588 'Descriptor: ${HTML_ESCAPE.convert(descriptorFilter)}', | 652 'Descriptor: ${HTML_ESCAPE.convert(descriptorFilter)}', |
| 589 'State: ${HTML_ESCAPE.convert(stateQueryParam)}' | 653 'State: ${HTML_ESCAPE.convert(stateQueryParam)}' |
| 590 ], (StringBuffer buffer) { | 654 ], (StringBuffer buffer) { |
| 591 buffer.write('<p>${links.length} files found</p>'); | 655 buffer.write('<p>Cache search is not yet implemented.</p>'); |
| 592 buffer.write('<ul>'); | 656 // buffer.write('<p>${links.length} files found</p>'); |
| 593 links.forEach((String link) { | 657 // buffer.write('<ul>'); |
| 594 buffer.write('<li>$link</li>'); | 658 // links.forEach((String link) { |
| 595 }); | 659 // buffer.write('<li>$link</li>'); |
| 596 buffer.write('</ul>'); | 660 // }); |
| 661 // buffer.write('</ul>'); |
| 597 }); | 662 }); |
| 598 }); | 663 }); |
| 599 } | 664 } |
| 600 | 665 |
| 601 /** | 666 /** |
| 602 * Return a response displaying overall performance information. | 667 * Return a response displaying overall performance information. |
| 603 */ | 668 */ |
| 604 void _returnCommunicationPerformance(HttpRequest request) { | 669 void _returnCommunicationPerformance(HttpRequest request) { |
| 605 AnalysisServer analysisServer = _server.analysisServer; | 670 AnalysisServer analysisServer = _server.analysisServer; |
| 606 if (analysisServer == null) { | 671 if (analysisServer == null) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 Folder folder = _findFolder(analysisServer, contextFilter); | 763 Folder folder = _findFolder(analysisServer, contextFilter); |
| 699 if (folder == null) { | 764 if (folder == null) { |
| 700 return _returnFailure(request, 'Invalid context: $contextFilter'); | 765 return _returnFailure(request, 'Invalid context: $contextFilter'); |
| 701 } | 766 } |
| 702 | 767 |
| 703 List<String> priorityNames; | 768 List<String> priorityNames; |
| 704 List<String> explicitNames = <String>[]; | 769 List<String> explicitNames = <String>[]; |
| 705 List<String> implicitNames = <String>[]; | 770 List<String> implicitNames = <String>[]; |
| 706 Map<String, String> links = new HashMap<String, String>(); | 771 Map<String, String> links = new HashMap<String, String>(); |
| 707 List<CaughtException> exceptions = <CaughtException>[]; | 772 List<CaughtException> exceptions = <CaughtException>[]; |
| 708 AnalysisContextImpl context = analysisServer.folderMap[folder]; | 773 InternalAnalysisContext context = analysisServer.folderMap[folder]; |
| 709 priorityNames = context.prioritySources | 774 priorityNames = context.prioritySources |
| 710 .map((Source source) => source.fullName) | 775 .map((Source source) => source.fullName) |
| 711 .toList(); | 776 .toList(); |
| 712 context.visitCacheItems((Source source, SourceEntry sourceEntry, | 777 MapIterator<AnalysisTarget, CacheEntry> iterator = |
| 713 DataDescriptor rowDesc, CacheState state) { | 778 context.analysisCache.iterator(); |
| 714 String sourceName = source.fullName; | 779 while (iterator.moveNext()) { |
| 715 if (!links.containsKey(sourceName)) { | 780 Source source = iterator.key.source; |
| 716 CaughtException exception = sourceEntry.exception; | 781 if (source != null) { |
| 717 if (exception != null) { | 782 CacheEntry entry = iterator.value; |
| 718 exceptions.add(exception); | 783 String sourceName = source.fullName; |
| 784 if (!links.containsKey(sourceName)) { |
| 785 CaughtException exception = entry.exception; |
| 786 if (exception != null) { |
| 787 exceptions.add(exception); |
| 788 } |
| 789 String link = makeLink(CACHE_ENTRY_PATH, { |
| 790 CONTEXT_QUERY_PARAM: folder.path, |
| 791 SOURCE_QUERY_PARAM: source.uri.toString() |
| 792 }, sourceName, exception != null); |
| 793 if (entry.explicitlyAdded) { |
| 794 explicitNames.add(sourceName); |
| 795 } else { |
| 796 implicitNames.add(sourceName); |
| 797 } |
| 798 links[sourceName] = link; |
| 719 } | 799 } |
| 720 String link = makeLink(CACHE_ENTRY_PATH, { | |
| 721 CONTEXT_QUERY_PARAM: folder.path, | |
| 722 SOURCE_QUERY_PARAM: source.uri.toString() | |
| 723 }, sourceName, exception != null); | |
| 724 if (sourceEntry.explicitlyAdded) { | |
| 725 explicitNames.add(sourceName); | |
| 726 } else { | |
| 727 implicitNames.add(sourceName); | |
| 728 } | |
| 729 links[sourceName] = link; | |
| 730 } | 800 } |
| 731 }); | 801 } |
| 732 explicitNames.sort(); | 802 explicitNames.sort(); |
| 733 implicitNames.sort(); | 803 implicitNames.sort(); |
| 734 | 804 |
| 735 _overlayContents.clear(); | 805 _overlayContents.clear(); |
| 736 context.visitContentCache((String fullName, int stamp, String contents) { | 806 context.visitContentCache((String fullName, int stamp, String contents) { |
| 737 _overlayContents[fullName] = contents; | 807 _overlayContents[fullName] = contents; |
| 738 }); | 808 }); |
| 739 | 809 |
| 740 void _writeFiles( | 810 void _writeFiles( |
| 741 StringBuffer buffer, String title, List<String> fileNames) { | 811 StringBuffer buffer, String title, List<String> fileNames) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 Folder folder = _findFolder(analysisServer, contextFilter); | 884 Folder folder = _findFolder(analysisServer, contextFilter); |
| 815 if (folder == null) { | 885 if (folder == null) { |
| 816 return _returnFailure(request, 'Invalid context: $contextFilter'); | 886 return _returnFailure(request, 'Invalid context: $contextFilter'); |
| 817 } | 887 } |
| 818 String sourceUri = request.uri.queryParameters[SOURCE_QUERY_PARAM]; | 888 String sourceUri = request.uri.queryParameters[SOURCE_QUERY_PARAM]; |
| 819 if (sourceUri == null) { | 889 if (sourceUri == null) { |
| 820 return _returnFailure( | 890 return _returnFailure( |
| 821 request, 'Query parameter $SOURCE_QUERY_PARAM required'); | 891 request, 'Query parameter $SOURCE_QUERY_PARAM required'); |
| 822 } | 892 } |
| 823 | 893 |
| 824 AnalysisContextImpl context = analysisServer.folderMap[folder]; | 894 InternalAnalysisContext context = analysisServer.folderMap[folder]; |
| 825 | 895 |
| 826 _writeResponse(request, (StringBuffer buffer) { | 896 _writeResponse(request, (StringBuffer buffer) { |
| 827 _writePage(buffer, 'Analysis Server - Element Model', [ | 897 _writePage(buffer, 'Analysis Server - Element Model', [ |
| 828 'Context: $contextFilter', | 898 'Context: $contextFilter', |
| 829 'File: $sourceUri' | 899 'File: $sourceUri' |
| 830 ], (StringBuffer buffer) { | 900 ], (StringBuffer buffer) { |
| 831 Source source = context.sourceFactory.forUri(sourceUri); | 901 Source source = context.sourceFactory.forUri(sourceUri); |
| 832 if (source == null) { | 902 if (source == null) { |
| 833 buffer.write('<p>Not found.</p>'); | 903 buffer.write('<p>Not found.</p>'); |
| 834 return; | 904 return; |
| 835 } | 905 } |
| 836 SourceEntry entry = context.getReadableSourceEntryOrNull(source); | 906 CacheEntry entry = context.analysisCache.get(source); |
| 837 if (entry == null) { | 907 if (entry == null) { |
| 838 buffer.write('<p>Not found.</p>'); | 908 buffer.write('<p>Not found.</p>'); |
| 839 return; | 909 return; |
| 840 } | 910 } |
| 841 LibraryElement element = entry.getValue(DartEntry.ELEMENT); | 911 LibraryElement element = entry.getValue(LIBRARY_ELEMENT); |
| 842 if (element == null) { | 912 if (element == null) { |
| 843 buffer.write('<p>null</p>'); | 913 buffer.write('<p>null</p>'); |
| 844 return; | 914 return; |
| 845 } | 915 } |
| 846 element.accept(new ElementWriter(buffer)); | 916 element.accept(new ElementWriter(buffer)); |
| 847 }); | 917 }); |
| 848 }); | 918 }); |
| 849 } | 919 } |
| 850 | 920 |
| 851 void _returnFailure(HttpRequest request, String message) { | 921 void _returnFailure(HttpRequest request, String message) { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 <p><strong># Notifications</strong> - the total number of notifications | 1247 <p><strong># Notifications</strong> - the total number of notifications |
| 1178 sent to the client with completion results for this request. | 1248 sent to the client with completion results for this request. |
| 1179 <p><strong># Suggestions</strong> - the number of suggestions | 1249 <p><strong># Suggestions</strong> - the number of suggestions |
| 1180 sent to the client in the first notification, followed by a comma, | 1250 sent to the client in the first notification, followed by a comma, |
| 1181 followed by the number of suggestions send to the client | 1251 followed by the number of suggestions send to the client |
| 1182 in the last notification. If there is only one notification, | 1252 in the last notification. If there is only one notification, |
| 1183 then there will be only one number in this column.'''); | 1253 then there will be only one number in this column.'''); |
| 1184 } | 1254 } |
| 1185 | 1255 |
| 1186 /** | 1256 /** |
| 1187 * Generate a table showing the cache values corresponding to the given | |
| 1188 * [descriptors], using [getState] to get the cache state corresponding to | |
| 1189 * each descriptor, and [getValue] to get the cached value corresponding to | |
| 1190 * each descriptor. Append the resulting HTML to the given [buffer]. The | |
| 1191 * [linkParameters] will be used if the value is too large to be displayed on | |
| 1192 * the current page and needs to be linked to a separate page. | |
| 1193 */ | |
| 1194 void _writeDescriptorTable(StringBuffer buffer, | |
| 1195 List<DataDescriptor> descriptors, CacheState getState(DataDescriptor), | |
| 1196 dynamic getValue(DataDescriptor), Map<String, String> linkParameters) { | |
| 1197 buffer.write('<dl>'); | |
| 1198 for (DataDescriptor descriptor in descriptors) { | |
| 1199 String descriptorName = HTML_ESCAPE.convert(descriptor.toString()); | |
| 1200 String descriptorState = | |
| 1201 HTML_ESCAPE.convert(getState(descriptor).toString()); | |
| 1202 buffer.write('<dt>$descriptorName ($descriptorState)</dt><dd>'); | |
| 1203 try { | |
| 1204 _writeValueAsHtml(buffer, getValue(descriptor), linkParameters); | |
| 1205 } catch (exception) { | |
| 1206 buffer.write('(${HTML_ESCAPE.convert(exception.toString())})'); | |
| 1207 } | |
| 1208 buffer.write('</dd>'); | |
| 1209 } | |
| 1210 buffer.write('</dl>'); | |
| 1211 } | |
| 1212 | |
| 1213 /** | |
| 1214 * Write the status of the edit domain (on the main status page) to the given | 1257 * Write the status of the edit domain (on the main status page) to the given |
| 1215 * [buffer]. | 1258 * [buffer]. |
| 1216 */ | 1259 */ |
| 1217 void _writeEditStatus(StringBuffer buffer) { | 1260 void _writeEditStatus(StringBuffer buffer) { |
| 1218 buffer.write('<h3>Edit Domain</h3>'); | 1261 buffer.write('<h3>Edit Domain</h3>'); |
| 1219 _writeTwoColumns(buffer, (StringBuffer buffer) { | 1262 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 1220 buffer.write('<p><b>Performance Data</b></p>'); | 1263 buffer.write('<p><b>Performance Data</b></p>'); |
| 1221 buffer.write('<p>'); | 1264 buffer.write('<p>'); |
| 1222 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); | 1265 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); |
| 1223 buffer.write('</p>'); | 1266 buffer.write('</p>'); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 */ | 1669 */ |
| 1627 static String makeLink( | 1670 static String makeLink( |
| 1628 String path, Map<String, String> params, String innerHtml, | 1671 String path, Map<String, String> params, String innerHtml, |
| 1629 [bool hasError = false]) { | 1672 [bool hasError = false]) { |
| 1630 Uri uri = new Uri(path: path, queryParameters: params); | 1673 Uri uri = new Uri(path: path, queryParameters: params); |
| 1631 String href = HTML_ESCAPE.convert(uri.toString()); | 1674 String href = HTML_ESCAPE.convert(uri.toString()); |
| 1632 String classAttribute = hasError ? ' class="error"' : ''; | 1675 String classAttribute = hasError ? ' class="error"' : ''; |
| 1633 return '<a href="$href"$classAttribute>$innerHtml</a>'; | 1676 return '<a href="$href"$classAttribute>$innerHtml</a>'; |
| 1634 } | 1677 } |
| 1635 } | 1678 } |
| OLD | NEW |