| 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; | 5 library analysis.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:math' show max; | 9 import 'dart:math' show max; |
| 10 | 10 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 418 } |
| 419 | 419 |
| 420 /** | 420 /** |
| 421 * Return the primary [ContextSourcePair] representing the given [path]. | 421 * Return the primary [ContextSourcePair] representing the given [path]. |
| 422 * | 422 * |
| 423 * The [AnalysisContext] of this pair will be the context that explicitly | 423 * The [AnalysisContext] of this pair will be the context that explicitly |
| 424 * contains the path, if any such context exists, otherwise it will be the | 424 * contains the path, if any such context exists, otherwise it will be the |
| 425 * first context that implicitly analyzes it. | 425 * first context that implicitly analyzes it. |
| 426 * | 426 * |
| 427 * If the [path] is not analyzed by any context, a [ContextSourcePair] with | 427 * If the [path] is not analyzed by any context, a [ContextSourcePair] with |
| 428 * `null` context and `file` [Source] is returned. | 428 * a `null` context and `file` [Source] is returned. |
| 429 * | 429 * |
| 430 * If the [path] dosn't represent a file, `null` is returned as a [Source]. | 430 * If the [path] dosn't represent a file, a [ContextSourcePair] with a `null` |
| 431 * context and `null` [Source] is returned. |
| 431 * | 432 * |
| 432 * Does not return `null`. | 433 * Does not return `null`. |
| 433 */ | 434 */ |
| 434 ContextSourcePair getContextSourcePair(String path) { | 435 ContextSourcePair getContextSourcePair(String path) { |
| 435 // try SDK | 436 // try SDK |
| 436 { | 437 { |
| 437 Uri uri = resourceProvider.pathContext.toUri(path); | 438 Uri uri = resourceProvider.pathContext.toUri(path); |
| 438 Source sdkSource = defaultSdk.fromFileUri(uri); | 439 Source sdkSource = defaultSdk.fromFileUri(uri); |
| 439 if (sdkSource != null) { | 440 if (sdkSource != null) { |
| 440 AnalysisContext anyContext = folderMap.values.first; | 441 AnalysisContext anyContext = folderMap.values.first; |
| 441 return new ContextSourcePair(anyContext, sdkSource); | 442 return new ContextSourcePair(anyContext, sdkSource); |
| 442 } | 443 } |
| 443 } | 444 } |
| 444 // try to find the deep-most containing context | 445 // try to find the deep-most containing context |
| 445 Resource resource = resourceProvider.getResource(path); | 446 Resource resource = resourceProvider.getResource(path); |
| 446 File file = resource is File ? resource : null; | 447 if (resource is! File) { |
| 448 return new ContextSourcePair(null, null); |
| 449 } |
| 450 File file = resource; |
| 447 { | 451 { |
| 448 AnalysisContext containingContext = getContainingContext(path); | 452 AnalysisContext containingContext = getContainingContext(path); |
| 449 if (containingContext != null) { | 453 if (containingContext != null) { |
| 450 Source source = file != null | 454 Source source = |
| 451 ? ContextManager.createSourceInContext(containingContext, file) | 455 ContextManager.createSourceInContext(containingContext, file); |
| 452 : null; | |
| 453 return new ContextSourcePair(containingContext, source); | 456 return new ContextSourcePair(containingContext, source); |
| 454 } | 457 } |
| 455 } | 458 } |
| 456 // try to find a context that analysed the file | 459 // try to find a context that analysed the file |
| 457 for (AnalysisContext context in folderMap.values) { | 460 for (AnalysisContext context in folderMap.values) { |
| 458 Source source = file != null | 461 Source source = ContextManager.createSourceInContext(context, file); |
| 459 ? ContextManager.createSourceInContext(context, file) | |
| 460 : null; | |
| 461 SourceKind kind = context.getKindOf(source); | 462 SourceKind kind = context.getKindOf(source); |
| 462 if (kind != SourceKind.UNKNOWN) { | 463 if (kind != SourceKind.UNKNOWN) { |
| 463 return new ContextSourcePair(context, source); | 464 return new ContextSourcePair(context, source); |
| 464 } | 465 } |
| 465 } | 466 } |
| 466 // try to find a context for which the file is a priority source | 467 // try to find a context for which the file is a priority source |
| 467 for (InternalAnalysisContext context in folderMap.values) { | 468 for (InternalAnalysisContext context in folderMap.values) { |
| 468 List<Source> sources = context.getSourcesWithFullName(path); | 469 List<Source> sources = context.getSourcesWithFullName(path); |
| 469 if (sources.isNotEmpty) { | 470 if (sources.isNotEmpty) { |
| 470 Source source = sources.first; | 471 Source source = sources.first; |
| 471 return new ContextSourcePair(context, source); | 472 return new ContextSourcePair(context, source); |
| 472 } | 473 } |
| 473 } | 474 } |
| 474 // file-based source | 475 // file-based source |
| 475 Source fileSource = file != null ? file.createSource() : null; | 476 Source fileSource = file.createSource(); |
| 476 return new ContextSourcePair(null, fileSource); | 477 return new ContextSourcePair(null, fileSource); |
| 477 } | 478 } |
| 478 | 479 |
| 479 /** | 480 /** |
| 480 * Returns [Element]s at the given [offset] of the given [file]. | 481 * Returns [Element]s at the given [offset] of the given [file]. |
| 481 * | 482 * |
| 482 * May be empty if cannot be resolved, but not `null`. | 483 * May be empty if cannot be resolved, but not `null`. |
| 483 */ | 484 */ |
| 484 List<Element> getElementsAtOffset(String file, int offset) { | 485 List<Element> getElementsAtOffset(String file, int offset) { |
| 485 List<AstNode> nodes = getNodesAtOffset(file, offset); | 486 List<AstNode> nodes = getNodesAtOffset(file, offset); |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 /** | 1500 /** |
| 1500 * The [PerformanceTag] for time spent in server request handlers. | 1501 * The [PerformanceTag] for time spent in server request handlers. |
| 1501 */ | 1502 */ |
| 1502 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1503 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1503 | 1504 |
| 1504 /** | 1505 /** |
| 1505 * The [PerformanceTag] for time spent in split store microtasks. | 1506 * The [PerformanceTag] for time spent in split store microtasks. |
| 1506 */ | 1507 */ |
| 1507 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1508 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1508 } | 1509 } |
| OLD | NEW |