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

Side by Side Diff: pkg/analyzer/lib/src/generated/utilities_dart.dart

Issue 2242883003: Fix resolveRelativeUri() to handle correctly empty contained Uri(s). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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) 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 analyzer.src.generated.utilities_dart; 5 library analyzer.src.generated.utilities_dart;
6 6
7 import 'package:analyzer/dart/ast/ast.dart' show AnnotatedNode, Comment; 7 import 'package:analyzer/dart/ast/ast.dart' show AnnotatedNode, Comment;
8 import 'package:analyzer/dart/ast/token.dart' show Token; 8 import 'package:analyzer/dart/ast/token.dart' show Token;
9 import 'package:analyzer/src/dart/element/element.dart' show ElementImpl; 9 import 'package:analyzer/src/dart/element/element.dart' show ElementImpl;
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
11 import 'package:analyzer/src/generated/java_engine.dart'; 11 import 'package:analyzer/src/generated/java_engine.dart';
12 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/util/fast_uri.dart'; 13 import 'package:analyzer/src/util/fast_uri.dart';
14 14
15 /** 15 /**
16 * Resolve the [containedUri] against [baseUri] using Dart rules. 16 * Resolve the [containedUri] against [baseUri] using Dart rules.
17 * 17 *
18 * This function behaves similarly to [Uri.resolveUri], except that it properly 18 * This function behaves similarly to [Uri.resolveUri], except that it properly
19 * handles situations like the following: 19 * handles situations like the following:
20 * 20 *
21 * resolveRelativeUri(dart:core, bool.dart) -> dart:core/bool.dart 21 * resolveRelativeUri(dart:core, bool.dart) -> dart:core/bool.dart
22 * resolveRelativeUri(package:a/b.dart, ../c.dart) -> package:a/c.dart 22 * resolveRelativeUri(package:a/b.dart, ../c.dart) -> package:a/c.dart
23 */ 23 */
24 Uri resolveRelativeUri(Uri baseUri, Uri containedUri) { 24 Uri resolveRelativeUri(Uri baseUri, Uri containedUri) {
25 if (containedUri.isAbsolute) { 25 if (containedUri.isAbsolute) {
26 return containedUri; 26 return containedUri;
27 } 27 }
28 Uri origBaseUri = baseUri; 28 Uri origBaseUri = baseUri;
29 try { 29 try {
30 bool isOpaque = baseUri.isAbsolute && !baseUri.path.startsWith('/'); 30 String scheme = baseUri.scheme;
31 if (isOpaque) { 31 if (scheme == DartUriResolver.DART_SCHEME) {
32 String scheme = baseUri.scheme;
33 String part = baseUri.path; 32 String part = baseUri.path;
34 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) { 33 if (part.indexOf('/') < 0) {
35 part = "$part/$part.dart"; 34 baseUri = FastUri.parse('$scheme:$part/$part.dart');
36 } 35 }
37 baseUri = FastUri.parse("$scheme:/$part");
38 } 36 }
39 Uri result = baseUri.resolveUri(containedUri); 37 return baseUri.resolveUri(containedUri);
40 if (isOpaque) {
41 result =
42 FastUri.parse("${result.scheme}:${result.path.substring(1)}");
43 }
44 return result;
45 } catch (exception, stackTrace) { 38 } catch (exception, stackTrace) {
46 throw new AnalysisException( 39 throw new AnalysisException(
47 "Could not resolve URI ($containedUri) relative to source ($origBaseUri) ", 40 "Could not resolve URI ($containedUri) relative to source ($origBaseUri) ",
48 new CaughtException(exception, stackTrace)); 41 new CaughtException(exception, stackTrace));
49 } 42 }
50 } 43 }
51 44
52 /** 45 /**
53 * If the given [node] has a documentation comment, remember its content 46 * If the given [node] has a documentation comment, remember its content
54 * and range into the given [element]. 47 * and range into the given [element].
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 final bool isOptional; 105 final bool isOptional;
113 106
114 /** 107 /**
115 * Initialize a newly created kind with the given state. 108 * Initialize a newly created kind with the given state.
116 * 109 *
117 * @param isOptional `true` if this is an optional parameter 110 * @param isOptional `true` if this is an optional parameter
118 */ 111 */
119 const ParameterKind(String name, int ordinal, this.isOptional) 112 const ParameterKind(String name, int ordinal, this.isOptional)
120 : super(name, ordinal); 113 : super(name, ordinal);
121 } 114 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | pkg/analyzer/test/generated/all_the_rest_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698