OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.engine.internal.resolver; | 14 package com.google.dart.engine.internal.resolver; |
15 | 15 |
16 import com.google.dart.engine.AnalysisEngine; | 16 import com.google.dart.engine.AnalysisEngine; |
17 import com.google.dart.engine.ast.Combinator; | 17 import com.google.dart.engine.ast.Combinator; |
18 import com.google.dart.engine.ast.CompilationUnit; | 18 import com.google.dart.engine.ast.CompilationUnit; |
| 19 import com.google.dart.engine.ast.CompilationUnitMember; |
19 import com.google.dart.engine.ast.Directive; | 20 import com.google.dart.engine.ast.Directive; |
20 import com.google.dart.engine.ast.ExportDirective; | 21 import com.google.dart.engine.ast.ExportDirective; |
| 22 import com.google.dart.engine.ast.FunctionTypeAlias; |
21 import com.google.dart.engine.ast.HideCombinator; | 23 import com.google.dart.engine.ast.HideCombinator; |
22 import com.google.dart.engine.ast.ImportDirective; | 24 import com.google.dart.engine.ast.ImportDirective; |
23 import com.google.dart.engine.ast.NamespaceDirective; | 25 import com.google.dart.engine.ast.NamespaceDirective; |
24 import com.google.dart.engine.ast.NodeList; | 26 import com.google.dart.engine.ast.NodeList; |
25 import com.google.dart.engine.ast.ShowCombinator; | 27 import com.google.dart.engine.ast.ShowCombinator; |
26 import com.google.dart.engine.ast.SimpleIdentifier; | 28 import com.google.dart.engine.ast.SimpleIdentifier; |
27 import com.google.dart.engine.ast.StringInterpolation; | 29 import com.google.dart.engine.ast.StringInterpolation; |
28 import com.google.dart.engine.ast.StringLiteral; | 30 import com.google.dart.engine.ast.StringLiteral; |
| 31 import com.google.dart.engine.ast.TypeAlias; |
29 import com.google.dart.engine.ast.UriBasedDirective; | 32 import com.google.dart.engine.ast.UriBasedDirective; |
30 import com.google.dart.engine.context.AnalysisException; | 33 import com.google.dart.engine.context.AnalysisException; |
31 import com.google.dart.engine.element.Element; | 34 import com.google.dart.engine.element.Element; |
32 import com.google.dart.engine.element.ExportElement; | 35 import com.google.dart.engine.element.ExportElement; |
33 import com.google.dart.engine.element.FunctionElement; | 36 import com.google.dart.engine.element.FunctionElement; |
34 import com.google.dart.engine.element.ImportElement; | 37 import com.google.dart.engine.element.ImportElement; |
35 import com.google.dart.engine.element.LibraryElement; | 38 import com.google.dart.engine.element.LibraryElement; |
36 import com.google.dart.engine.element.NamespaceCombinator; | 39 import com.google.dart.engine.element.NamespaceCombinator; |
37 import com.google.dart.engine.error.AnalysisError; | 40 import com.google.dart.engine.error.AnalysisError; |
38 import com.google.dart.engine.error.AnalysisErrorListener; | 41 import com.google.dart.engine.error.AnalysisErrorListener; |
(...skipping 20 matching lines...) Expand all Loading... |
59 import com.google.dart.engine.source.Source; | 62 import com.google.dart.engine.source.Source; |
60 import com.google.dart.engine.source.SourceKind; | 63 import com.google.dart.engine.source.SourceKind; |
61 import com.google.dart.engine.utilities.general.TimeCounter.TimeCounterHandle; | 64 import com.google.dart.engine.utilities.general.TimeCounter.TimeCounterHandle; |
62 import com.google.dart.engine.utilities.instrumentation.Instrumentation; | 65 import com.google.dart.engine.utilities.instrumentation.Instrumentation; |
63 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; | 66 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; |
64 import com.google.dart.engine.utilities.io.UriUtilities; | 67 import com.google.dart.engine.utilities.io.UriUtilities; |
65 | 68 |
66 import java.util.ArrayList; | 69 import java.util.ArrayList; |
67 import java.util.HashMap; | 70 import java.util.HashMap; |
68 import java.util.HashSet; | 71 import java.util.HashSet; |
| 72 import java.util.List; |
69 import java.util.Set; | 73 import java.util.Set; |
70 | 74 |
71 /** | 75 /** |
72 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent | 76 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent |
73 * libraries within a single context. | 77 * libraries within a single context. |
74 * | 78 * |
75 * @coverage dart.engine.resolver | 79 * @coverage dart.engine.resolver |
76 */ | 80 */ |
77 public class LibraryResolver { | 81 public class LibraryResolver { |
78 /** | 82 /** |
| 83 * Instances of the class {@code TypeAliasInfo} hold information about a {@lin
k TypeAlias}. |
| 84 */ |
| 85 private static class TypeAliasInfo { |
| 86 private Library library; |
| 87 private Source source; |
| 88 private FunctionTypeAlias typeAlias; |
| 89 |
| 90 /** |
| 91 * Initialize a newly created information holder with the given information. |
| 92 * |
| 93 * @param library the library containing the type alias |
| 94 * @param source the source of the file containing the type alias |
| 95 * @param typeAlias the type alias being remembered |
| 96 */ |
| 97 public TypeAliasInfo(Library library, Source source, FunctionTypeAlias typeA
lias) { |
| 98 this.library = library; |
| 99 this.source = source; |
| 100 this.typeAlias = typeAlias; |
| 101 } |
| 102 } |
| 103 |
| 104 /** |
79 * The analysis context in which the libraries are being analyzed. | 105 * The analysis context in which the libraries are being analyzed. |
80 */ | 106 */ |
81 private InternalAnalysisContext analysisContext; | 107 private InternalAnalysisContext analysisContext; |
82 | 108 |
83 /** | 109 /** |
84 * The listener to which analysis errors will be reported, this error listener
is either | 110 * The listener to which analysis errors will be reported, this error listener
is either |
85 * references {@link #recordingErrorListener}, or it unions the passed | 111 * references {@link #recordingErrorListener}, or it unions the passed |
86 * {@link AnalysisErrorListener} with the {@link #recordingErrorListener}. | 112 * {@link AnalysisErrorListener} with the {@link #recordingErrorListener}. |
87 */ | 113 */ |
88 private RecordingErrorListener errorListener; | 114 private RecordingErrorListener errorListener; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // | 230 // |
205 buildElementModels(); | 231 buildElementModels(); |
206 instrumentation.metric("buildElementModels", "complete"); | 232 instrumentation.metric("buildElementModels", "complete"); |
207 LibraryElement coreElement = coreLibrary.getLibraryElement(); | 233 LibraryElement coreElement = coreLibrary.getLibraryElement(); |
208 if (coreElement == null) { | 234 if (coreElement == null) { |
209 throw new AnalysisException("Could not resolve dart:core"); | 235 throw new AnalysisException("Could not resolve dart:core"); |
210 } | 236 } |
211 buildDirectiveModels(); | 237 buildDirectiveModels(); |
212 instrumentation.metric("buildDirectiveModels", "complete"); | 238 instrumentation.metric("buildDirectiveModels", "complete"); |
213 typeProvider = new TypeProviderImpl(coreElement); | 239 typeProvider = new TypeProviderImpl(coreElement); |
| 240 buildTypeAliases(); |
214 buildTypeHierarchies(); | 241 buildTypeHierarchies(); |
215 instrumentation.metric("buildTypeHierarchies", "complete"); | 242 instrumentation.metric("buildTypeHierarchies", "complete"); |
216 // | 243 // |
217 // Perform resolution and type analysis. | 244 // Perform resolution and type analysis. |
218 // | 245 // |
219 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we | 246 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we |
220 // want to only resolve the target library. The advantage to resolving eve
rything is that we | 247 // want to only resolve the target library. The advantage to resolving eve
rything is that we |
221 // have already done part of the work so we'll avoid duplicated effort. Th
e disadvantage of | 248 // have already done part of the work so we'll avoid duplicated effort. Th
e disadvantage of |
222 // resolving everything is that we might do extra work that we don't reall
y care about. Another | 249 // resolving everything is that we might do extra work that we don't reall
y care about. Another |
223 // possibility is to add a parameter to this method and punt the decision
to the clients. | 250 // possibility is to add a parameter to this method and punt the decision
to the clients. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 buildElementModels(); | 318 buildElementModels(); |
292 instrumentation.metric("buildElementModels", "complete"); | 319 instrumentation.metric("buildElementModels", "complete"); |
293 LibraryElement coreElement = coreLibrary.getLibraryElement(); | 320 LibraryElement coreElement = coreLibrary.getLibraryElement(); |
294 if (coreElement == null) { | 321 if (coreElement == null) { |
295 throw new AnalysisException("Could not resolve dart:core"); | 322 throw new AnalysisException("Could not resolve dart:core"); |
296 } | 323 } |
297 buildDirectiveModels(); | 324 buildDirectiveModels(); |
298 instrumentation.metric("buildDirectiveModels", "complete"); | 325 instrumentation.metric("buildDirectiveModels", "complete"); |
299 typeProvider = new TypeProviderImpl(coreElement); | 326 typeProvider = new TypeProviderImpl(coreElement); |
300 buildEnumMembers(); | 327 buildEnumMembers(); |
| 328 buildTypeAliases(); |
301 buildTypeHierarchies(); | 329 buildTypeHierarchies(); |
302 instrumentation.metric("buildTypeHierarchies", "complete"); | 330 instrumentation.metric("buildTypeHierarchies", "complete"); |
303 // | 331 // |
304 // Perform resolution and type analysis. | 332 // Perform resolution and type analysis. |
305 // | 333 // |
306 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we | 334 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra
ries or whether we |
307 // want to only resolve the target library. The advantage to resolving eve
rything is that we | 335 // want to only resolve the target library. The advantage to resolving eve
rything is that we |
308 // have already done part of the work so we'll avoid duplicated effort. Th
e disadvantage of | 336 // have already done part of the work so we'll avoid duplicated effort. Th
e disadvantage of |
309 // resolving everything is that we might do extra work that we don't reall
y care about. Another | 337 // resolving everything is that we might do extra work that we don't reall
y care about. Another |
310 // possibility is to add a parameter to this method and punt the decision
to the clients. | 338 // possibility is to add a parameter to this method and punt the decision
to the clients. |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 EnumMemberBuilder builder = new EnumMemberBuilder(typeProvider); | 604 EnumMemberBuilder builder = new EnumMemberBuilder(typeProvider); |
577 library.getAST(source).accept(builder); | 605 library.getAST(source).accept(builder); |
578 } | 606 } |
579 } | 607 } |
580 } finally { | 608 } finally { |
581 timeCounter.stop(); | 609 timeCounter.stop(); |
582 } | 610 } |
583 } | 611 } |
584 | 612 |
585 /** | 613 /** |
| 614 * Resolve the types referenced by function type aliases across all of the fun
ction type aliases |
| 615 * defined in the current cycle. |
| 616 * |
| 617 * @throws AnalysisException if any of the function type aliases could not be
resolved |
| 618 */ |
| 619 private void buildTypeAliases() throws AnalysisException { |
| 620 TimeCounterHandle timeCounter = PerformanceStatistics.resolve.start(); |
| 621 try { |
| 622 List<TypeAliasInfo> typeAliases = new ArrayList<TypeAliasInfo>(); |
| 623 for (Library library : librariesInCycles) { |
| 624 for (Source source : library.getCompilationUnitSources()) { |
| 625 CompilationUnit ast = library.getAST(source); |
| 626 for (CompilationUnitMember member : ast.getDeclarations()) { |
| 627 if (member instanceof FunctionTypeAlias) { |
| 628 typeAliases.add(new TypeAliasInfo(library, source, (FunctionTypeAl
ias) member)); |
| 629 } |
| 630 } |
| 631 } |
| 632 } |
| 633 // TODO(brianwilkerson) We need to sort the type aliases such that all ali
ases referenced by |
| 634 // an alias T are resolved before we resolve T. |
| 635 for (TypeAliasInfo info : typeAliases) { |
| 636 TypeResolverVisitor visitor = new TypeResolverVisitor( |
| 637 info.library, |
| 638 info.source, |
| 639 typeProvider); |
| 640 info.typeAlias.accept(visitor); |
| 641 } |
| 642 } finally { |
| 643 timeCounter.stop(); |
| 644 } |
| 645 } |
| 646 |
| 647 /** |
586 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current | 648 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current |
587 * cycle. | 649 * cycle. |
588 * | 650 * |
589 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 651 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
590 */ | 652 */ |
591 private void buildTypeHierarchies() throws AnalysisException { | 653 private void buildTypeHierarchies() throws AnalysisException { |
592 TimeCounterHandle timeCounter = PerformanceStatistics.resolve.start(); | 654 TimeCounterHandle timeCounter = PerformanceStatistics.resolve.start(); |
593 try { | 655 try { |
594 for (Library library : librariesInCycles) { | 656 for (Library library : librariesInCycles) { |
595 for (Source source : library.getCompilationUnitSources()) { | 657 for (Source source : library.getCompilationUnitSources()) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 return null; | 948 return null; |
887 } | 949 } |
888 String uriContent = uriLiteral.getStringValue().trim(); | 950 String uriContent = uriLiteral.getStringValue().trim(); |
889 if (uriContent == null || uriContent.isEmpty()) { | 951 if (uriContent == null || uriContent.isEmpty()) { |
890 return null; | 952 return null; |
891 } | 953 } |
892 uriContent = UriUtilities.encode(uriContent); | 954 uriContent = UriUtilities.encode(uriContent); |
893 return analysisContext.getSourceFactory().resolveUri(librarySource, uriConte
nt); | 955 return analysisContext.getSourceFactory().resolveUri(librarySource, uriConte
nt); |
894 } | 956 } |
895 } | 957 } |
OLD | NEW |