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

Side by Side Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/LibraryResolver2.java

Issue 594843006: Fix for issue 14497 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
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.ast.Combinator; 16 import com.google.dart.engine.ast.Combinator;
17 import com.google.dart.engine.ast.CompilationUnit; 17 import com.google.dart.engine.ast.CompilationUnit;
18 import com.google.dart.engine.ast.CompilationUnitMember;
18 import com.google.dart.engine.ast.Directive; 19 import com.google.dart.engine.ast.Directive;
19 import com.google.dart.engine.ast.ExportDirective; 20 import com.google.dart.engine.ast.ExportDirective;
21 import com.google.dart.engine.ast.FunctionTypeAlias;
20 import com.google.dart.engine.ast.HideCombinator; 22 import com.google.dart.engine.ast.HideCombinator;
21 import com.google.dart.engine.ast.ImportDirective; 23 import com.google.dart.engine.ast.ImportDirective;
22 import com.google.dart.engine.ast.NamespaceDirective; 24 import com.google.dart.engine.ast.NamespaceDirective;
23 import com.google.dart.engine.ast.NodeList; 25 import com.google.dart.engine.ast.NodeList;
24 import com.google.dart.engine.ast.ShowCombinator; 26 import com.google.dart.engine.ast.ShowCombinator;
25 import com.google.dart.engine.ast.SimpleIdentifier; 27 import com.google.dart.engine.ast.SimpleIdentifier;
26 import com.google.dart.engine.ast.StringLiteral; 28 import com.google.dart.engine.ast.StringLiteral;
29 import com.google.dart.engine.ast.TypeAlias;
27 import com.google.dart.engine.context.AnalysisContext; 30 import com.google.dart.engine.context.AnalysisContext;
28 import com.google.dart.engine.context.AnalysisException; 31 import com.google.dart.engine.context.AnalysisException;
29 import com.google.dart.engine.element.Element; 32 import com.google.dart.engine.element.Element;
30 import com.google.dart.engine.element.ExportElement; 33 import com.google.dart.engine.element.ExportElement;
31 import com.google.dart.engine.element.FunctionElement; 34 import com.google.dart.engine.element.FunctionElement;
32 import com.google.dart.engine.element.ImportElement; 35 import com.google.dart.engine.element.ImportElement;
33 import com.google.dart.engine.element.LibraryElement; 36 import com.google.dart.engine.element.LibraryElement;
34 import com.google.dart.engine.element.NamespaceCombinator; 37 import com.google.dart.engine.element.NamespaceCombinator;
35 import com.google.dart.engine.error.AnalysisError; 38 import com.google.dart.engine.error.AnalysisError;
36 import com.google.dart.engine.error.AnalysisErrorListener; 39 import com.google.dart.engine.error.AnalysisErrorListener;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 import java.util.List; 72 import java.util.List;
70 73
71 /** 74 /**
72 * Instances of the class {@code LibraryResolver} are used to resolve one or mor e mutually dependent 75 * Instances of the class {@code LibraryResolver} are used to resolve one or mor e mutually dependent
73 * libraries within a single context. 76 * libraries within a single context.
74 * 77 *
75 * @coverage dart.engine.resolver 78 * @coverage dart.engine.resolver
76 */ 79 */
77 public class LibraryResolver2 { 80 public class LibraryResolver2 {
78 /** 81 /**
82 * Instances of the class {@code TypeAliasInfo} hold information about a {@lin k TypeAlias}.
83 */
84 private static class TypeAliasInfo {
85 private ResolvableLibrary library;
86 private Source source;
87 private FunctionTypeAlias typeAlias;
88
89 /**
90 * Initialize a newly created information holder with the given information.
91 *
92 * @param library the library containing the type alias
93 * @param source the source of the file containing the type alias
94 * @param typeAlias the type alias being remembered
95 */
96 public TypeAliasInfo(ResolvableLibrary library, Source source, FunctionTypeA lias typeAlias) {
97 this.library = library;
98 this.source = source;
99 this.typeAlias = typeAlias;
100 }
101 }
102
103 /**
79 * Report that the core library could not be resolved in the given analysis co ntext and throw an 104 * Report that the core library could not be resolved in the given analysis co ntext and throw an
80 * exception. 105 * exception.
81 * 106 *
82 * @param analysisContext the analysis context in which the failure occurred 107 * @param analysisContext the analysis context in which the failure occurred
83 * @param coreLibrarySource the source representing the core library 108 * @param coreLibrarySource the source representing the core library
84 * @throws AnalysisException always 109 * @throws AnalysisException always
85 */ 110 */
86 @DartBlockBody({"throw new AnalysisException(\"Could not resolve dart:core\"); "}) 111 @DartBlockBody({"throw new AnalysisException(\"Could not resolve dart:core\"); "})
87 public static void missingCoreLibrary(AnalysisContext analysisContext, Source coreLibrarySource) 112 public static void missingCoreLibrary(AnalysisContext analysisContext, Source coreLibrarySource)
88 throws AnalysisException { 113 throws AnalysisException {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 buildElementModels(); 254 buildElementModels();
230 instrumentation.metric("buildElementModels", "complete"); 255 instrumentation.metric("buildElementModels", "complete");
231 LibraryElement coreElement = coreLibrary.getLibraryElement(); 256 LibraryElement coreElement = coreLibrary.getLibraryElement();
232 if (coreElement == null) { 257 if (coreElement == null) {
233 missingCoreLibrary(analysisContext, coreLibrarySource); 258 missingCoreLibrary(analysisContext, coreLibrarySource);
234 } 259 }
235 buildDirectiveModels(); 260 buildDirectiveModels();
236 instrumentation.metric("buildDirectiveModels", "complete"); 261 instrumentation.metric("buildDirectiveModels", "complete");
237 typeProvider = new TypeProviderImpl(coreElement); 262 typeProvider = new TypeProviderImpl(coreElement);
238 buildEnumMembers(); 263 buildEnumMembers();
264 buildTypeAliases();
239 buildTypeHierarchies(); 265 buildTypeHierarchies();
240 instrumentation.metric("buildTypeHierarchies", "complete"); 266 instrumentation.metric("buildTypeHierarchies", "complete");
241 // 267 //
242 // Perform resolution and type analysis. 268 // Perform resolution and type analysis.
243 // 269 //
244 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra ries or whether we 270 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra ries or whether we
245 // want to only resolve the target library. The advantage to resolving eve rything is that we 271 // want to only resolve the target library. The advantage to resolving eve rything is that we
246 // have already done part of the work so we'll avoid duplicated effort. Th e disadvantage of 272 // have already done part of the work so we'll avoid duplicated effort. Th e disadvantage of
247 // resolving everything is that we might do extra work that we don't reall y care about. Another 273 // resolving everything is that we might do extra work that we don't reall y care about. Another
248 // possibility is to add a parameter to this method and punt the decision to the clients. 274 // possibility is to add a parameter to this method and punt the decision to the clients.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 for (int j = 0; j < dependencyCount; j++) { 487 for (int j = 0; j < dependencyCount; j++) {
462 ResolvableLibrary dependency = dependencies[j]; 488 ResolvableLibrary dependency = dependencies[j];
463 //dependency.setErrorListener(errorListener); 489 //dependency.setErrorListener(errorListener);
464 libraryMap.put(dependency.getLibrarySource(), dependency); 490 libraryMap.put(dependency.getLibrarySource(), dependency);
465 } 491 }
466 } 492 }
467 return libraryMap; 493 return libraryMap;
468 } 494 }
469 495
470 /** 496 /**
497 * Resolve the types referenced by function type aliases across all of the fun ction type aliases
498 * defined in the current cycle.
499 *
500 * @throws AnalysisException if any of the function type aliases could not be resolved
501 */
502 private void buildTypeAliases() throws AnalysisException {
503 TimeCounterHandle timeCounter = PerformanceStatistics.resolve.start();
504 try {
505 List<TypeAliasInfo> typeAliases = new ArrayList<TypeAliasInfo>();
506 for (ResolvableLibrary library : librariesInCycle) {
507 for (ResolvableCompilationUnit unit : library.getResolvableCompilationUn its()) {
508 for (CompilationUnitMember member : unit.getCompilationUnit().getDecla rations()) {
509 if (member instanceof FunctionTypeAlias) {
510 typeAliases.add(new TypeAliasInfo(
511 library,
512 unit.getSource(),
513 (FunctionTypeAlias) member));
514 }
515 }
516 }
517 }
518 // TODO(brianwilkerson) We need to sort the type aliases such that all ali ases referenced by
519 // an alias T are resolved before we resolve T.
520 for (TypeAliasInfo info : typeAliases) {
521 TypeResolverVisitor visitor = new TypeResolverVisitor(
522 info.library,
523 info.source,
524 typeProvider);
525 info.typeAlias.accept(visitor);
526 }
527 } finally {
528 timeCounter.stop();
529 }
530 }
531
532 /**
471 * Resolve the type hierarchy across all of the types declared in the librarie s in the current 533 * Resolve the type hierarchy across all of the types declared in the librarie s in the current
472 * cycle. 534 * cycle.
473 * 535 *
474 * @throws AnalysisException if any of the type hierarchies could not be resol ved 536 * @throws AnalysisException if any of the type hierarchies could not be resol ved
475 */ 537 */
476 private void buildTypeHierarchies() throws AnalysisException { 538 private void buildTypeHierarchies() throws AnalysisException {
477 TimeCounterHandle timeCounter = PerformanceStatistics.resolve.start(); 539 TimeCounterHandle timeCounter = PerformanceStatistics.resolve.start();
478 try { 540 try {
479 for (ResolvableLibrary library : librariesInCycle) { 541 for (ResolvableLibrary library : librariesInCycle) {
480 for (ResolvableCompilationUnit unit : library.getResolvableCompilationUn its()) { 542 for (ResolvableCompilationUnit unit : library.getResolvableCompilationUn its()) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 try { 639 try {
578 for (Source source : library.getCompilationUnitSources()) { 640 for (Source source : library.getCompilationUnitSources()) {
579 CompilationUnit ast = library.getAST(source); 641 CompilationUnit ast = library.getAST(source);
580 new PolymerCompilationUnitBuilder(ast).build(); 642 new PolymerCompilationUnitBuilder(ast).build();
581 } 643 }
582 } finally { 644 } finally {
583 timeCounter.stop(); 645 timeCounter.stop();
584 } 646 }
585 } 647 }
586 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698