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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 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 engine.utilities.dart; 5 library analyzer.src.generated.utilities_dart;
6 6
7 import 'java_core.dart'; 7 import 'package:analyzer/dart/ast/ast.dart' show AnnotatedNode, Comment;
8 import 'package:analyzer/dart/ast/token.dart' show Token;
9 import 'package:analyzer/exception/exception.dart';
10 import 'package:analyzer/src/dart/element/element.dart' show ElementImpl;
11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/util/fast_uri.dart';
13
14 /**
15 * Resolve the [containedUri] against [baseUri] using Dart rules.
16 *
17 * This function behaves similarly to [Uri.resolveUri], except that it properly
18 * handles situations like the following:
19 *
20 * resolveRelativeUri(dart:core, bool.dart) -> dart:core/bool.dart
21 * resolveRelativeUri(package:a/b.dart, ../c.dart) -> package:a/c.dart
22 */
23 Uri resolveRelativeUri(Uri baseUri, Uri containedUri) {
24 if (containedUri.isAbsolute) {
25 return containedUri;
26 }
27 Uri origBaseUri = baseUri;
28 try {
29 String scheme = baseUri.scheme;
30 // dart:core => dart:core/core.dart
31 if (scheme == DartUriResolver.DART_SCHEME) {
32 String part = baseUri.path;
33 if (part.indexOf('/') < 0) {
34 baseUri = FastUri.parse('$scheme:$part/$part.dart');
35 }
36 }
37 // foo.dart + ../bar.dart = ../bar.dart
38 // TODO(scheglov) Remove this temporary workaround.
39 // Should be fixed as https://github.com/dart-lang/sdk/issues/27447
40 List<String> baseSegments = baseUri.pathSegments;
41 List<String> containedSegments = containedUri.pathSegments;
42 if (baseSegments.length == 1 &&
43 containedSegments.length > 0 &&
44 containedSegments[0] == '..') {
45 return containedUri;
46 }
47 return baseUri.resolveUri(containedUri);
48 } catch (exception, stackTrace) {
49 throw new AnalysisException(
50 "Could not resolve URI ($containedUri) relative to source ($origBaseUri) ",
51 new CaughtException(exception, stackTrace));
52 }
53 }
54
55 /**
56 * If the given [node] has a documentation comment, remember its content
57 * and range into the given [element].
58 */
59 void setElementDocumentationComment(ElementImpl element, AnnotatedNode node) {
60 Comment comment = node.documentationComment;
61 if (comment != null && comment.isDocumentation) {
62 element.documentationComment =
63 comment.tokens.map((Token t) => t.lexeme).join('\n');
64 }
65 }
8 66
9 /** 67 /**
10 * Check whether [uri1] starts with (or 'is prefixed by') [uri2] by checking 68 * Check whether [uri1] starts with (or 'is prefixed by') [uri2] by checking
11 * path segments. 69 * path segments.
12 */ 70 */
13 bool startsWith(Uri uri1, Uri uri2) { 71 bool startsWith(Uri uri1, Uri uri2) {
14 List<String> uri1Segments = uri1.pathSegments; 72 List<String> uri1Segments = uri1.pathSegments;
15 List<String> uri2Segments = uri2.pathSegments.toList(); 73 List<String> uri2Segments = uri2.pathSegments.toList();
16 // Punt if empty (https://github.com/dart-lang/sdk/issues/24126) 74 // Punt if empty (https://github.com/dart-lang/sdk/issues/24126)
17 if (uri2Segments.isEmpty) { 75 if (uri2Segments.isEmpty) {
(...skipping 10 matching lines...) Expand all
28 86
29 for (int i = 0; i < uri2Segments.length; ++i) { 87 for (int i = 0; i < uri2Segments.length; ++i) {
30 if (uri2Segments[i] != uri1Segments[i]) { 88 if (uri2Segments[i] != uri1Segments[i]) {
31 return false; 89 return false;
32 } 90 }
33 } 91 }
34 return true; 92 return true;
35 } 93 }
36 94
37 /** 95 /**
38 * The enumeration `ParameterKind` defines the different kinds of parameters. Th ere are two 96 * The kinds of a parameter. There are two basic kinds of parameters: required
39 * basic kinds of parameters: required and optional. Optional parameters are fur ther divided into 97 * and optional. Optional parameters are further divided into two kinds:
40 * two kinds: positional optional and named optional. 98 * positional optional and named optional.
41 */ 99 */
42 class ParameterKind extends Enum<ParameterKind> { 100 class ParameterKind implements Comparable<ParameterKind> {
43 static const ParameterKind REQUIRED = 101 static const ParameterKind REQUIRED =
44 const ParameterKind('REQUIRED', 0, false); 102 const ParameterKind('REQUIRED', 0, false);
45 103
46 static const ParameterKind POSITIONAL = 104 static const ParameterKind POSITIONAL =
47 const ParameterKind('POSITIONAL', 1, true); 105 const ParameterKind('POSITIONAL', 1, true);
48 106
49 static const ParameterKind NAMED = const ParameterKind('NAMED', 2, true); 107 static const ParameterKind NAMED = const ParameterKind('NAMED', 2, true);
50 108
51 static const List<ParameterKind> values = const [REQUIRED, POSITIONAL, NAMED]; 109 static const List<ParameterKind> values = const [REQUIRED, POSITIONAL, NAMED];
52 110
53 /** 111 /**
112 * The name of this parameter.
113 */
114 final String name;
115
116 /**
117 * The ordinal value of the parameter.
118 */
119 final int ordinal;
120
121 /**
54 * A flag indicating whether this is an optional parameter. 122 * A flag indicating whether this is an optional parameter.
55 */ 123 */
56 final bool isOptional; 124 final bool isOptional;
57 125
58 /** 126 /**
59 * Initialize a newly created kind with the given state. 127 * Initialize a newly created kind with the given state.
60 *
61 * @param isOptional `true` if this is an optional parameter
62 */ 128 */
63 const ParameterKind(String name, int ordinal, this.isOptional) 129 const ParameterKind(this.name, this.ordinal, this.isOptional);
64 : super(name, ordinal); 130
131 @override
132 int get hashCode => ordinal;
133
134 @override
135 int compareTo(ParameterKind other) => ordinal - other.ordinal;
136
137 @override
138 String toString() => name;
65 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698