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

Side by Side Diff: pkg/analyzer/lib/src/summary/prelink.dart

Issue 1831133005: Consolidate duplicate code for resloving URIs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Sort Created 4 years, 8 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'package:analyzer/src/generated/java_core.dart'; 5 import 'package:analyzer/src/generated/java_core.dart';
6 import 'package:analyzer/src/generated/java_engine.dart'; 6 import 'package:analyzer/src/generated/java_engine.dart';
7 import 'package:analyzer/src/generated/source.dart'; 7 import 'package:analyzer/src/generated/source.dart';
8 import 'package:analyzer/src/generated/utilities_dart.dart';
8 import 'package:analyzer/src/summary/format.dart'; 9 import 'package:analyzer/src/summary/format.dart';
9 import 'package:analyzer/src/summary/idl.dart'; 10 import 'package:analyzer/src/summary/idl.dart';
10 import 'package:analyzer/src/summary/name_filter.dart'; 11 import 'package:analyzer/src/summary/name_filter.dart';
11 12
12 /** 13 /**
13 * Create a [LinkedLibraryBuilder] corresponding to the given 14 * Create a [LinkedLibraryBuilder] corresponding to the given
14 * [definingUnit], which should be the defining compilation unit for a library. 15 * [definingUnit], which should be the defining compilation unit for a library.
15 * Compilation units referenced by the defining compilation unit via `part` 16 * Compilation units referenced by the defining compilation unit via `part`
16 * declarations will be retrieved using [getPart]. Public namespaces for 17 * declarations will be retrieved using [getPart]. Public namespaces for
17 * libraries referenced by the defining compilation unit via `import` 18 * libraries referenced by the defining compilation unit via `import`
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 504 }
504 505
505 /** 506 /**
506 * Resolve [relativeUri] relative to [sourceUri]. Works correctly if 507 * Resolve [relativeUri] relative to [sourceUri]. Works correctly if
507 * [sourceUri] is also relative. 508 * [sourceUri] is also relative.
508 */ 509 */
509 String resolveUri(String sourceUri, String relativeUri) { 510 String resolveUri(String sourceUri, String relativeUri) {
510 if (sourceUri == null) { 511 if (sourceUri == null) {
511 return relativeUri; 512 return relativeUri;
512 } else { 513 } else {
513 // return Uri.parse(sourceUri).resolve(relativeUri).toString(); 514 return resolveRelativeUri(Uri.parse(sourceUri), Uri.parse(relativeUri))
514 // TODO(paulberry): this algorithm is mostly copied from FileBasedSource. 515 .toString();
515 // The code should be refactored so it can be shared.
516 Uri containedUri = Uri.parse(relativeUri);
517 if (containedUri.isAbsolute) {
518 return relativeUri;
519 }
520 Uri uri = Uri.parse(sourceUri);
521 try {
522 Uri baseUri = uri;
523 bool isOpaque = uri.isAbsolute && !uri.path.startsWith('/');
524 if (isOpaque) {
525 String scheme = uri.scheme;
526 String part = uri.path;
527 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) {
528 part = "$part/$part.dart";
529 }
530 baseUri = parseUriWithException("$scheme:/$part");
531 }
532 Uri result = baseUri.resolveUri(containedUri);
533 if (isOpaque) {
534 result = parseUriWithException(
535 "${result.scheme}:${result.path.substring(1)}");
536 }
537 //print('$sourceUri | $relativeUri -> $result');
538 return result.toString();
539 } catch (exception, stackTrace) {
540 throw new AnalysisException(
541 "Could not resolve URI ($containedUri) relative to source ($uri)",
542 new CaughtException(exception, stackTrace));
543 }
544 } 516 }
545 } 517 }
546 } 518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698