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

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/ProjectImpl.java

Issue 126303002: Version 1.1.0-dev.5.3 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 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.tools.core.internal.analysis.model; 14 package com.google.dart.tools.core.internal.analysis.model;
15 15
16 import com.google.dart.engine.AnalysisEngine; 16 import com.google.dart.engine.AnalysisEngine;
17 import com.google.dart.engine.context.AnalysisContext; 17 import com.google.dart.engine.context.AnalysisContext;
18 import com.google.dart.engine.index.Index; 18 import com.google.dart.engine.index.Index;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 import java.util.Collection; 61 import java.util.Collection;
62 import java.util.HashMap; 62 import java.util.HashMap;
63 import java.util.HashSet; 63 import java.util.HashSet;
64 import java.util.Iterator; 64 import java.util.Iterator;
65 import java.util.List; 65 import java.util.List;
66 import java.util.Map.Entry; 66 import java.util.Map.Entry;
67 import java.util.Set; 67 import java.util.Set;
68 68
69 /** 69 /**
70 * Represents an Eclipse project that has a Dart nature. 70 * Represents an Eclipse project that has a Dart nature.
71 * 71 *
72 * @coverage dart.tools.core.model 72 * @coverage dart.tools.core.model
73 */ 73 */
74 public class ProjectImpl extends ContextManagerImpl implements Project { 74 public class ProjectImpl extends ContextManagerImpl implements Project {
75 75
76 public static class AnalysisContextFactory { 76 public static class AnalysisContextFactory {
77 public AnalysisContext createContext() { 77 public AnalysisContext createContext() {
78 return AnalysisEngine.getInstance().createAnalysisContext(); 78 return AnalysisEngine.getInstance().createAnalysisContext();
79 } 79 }
80 80
81 public File[] getPackageRoots(IContainer container) { 81 public File[] getPackageRoots(IContainer container) {
82 return ProjectImpl.getPackageRoots( 82 return ProjectImpl.getPackageRoots(
83 DartCore.getPlugin(), 83 DartCore.getPlugin(),
84 CmdLineOptions.getOptions(), 84 CmdLineOptions.getOptions(),
85 container); 85 container);
86 } 86 }
87 } 87 }
88 88
89 /** 89 /**
90 * Answer the package roots for the specified project with the given options. May return an empty 90 * Answer the package roots for the specified project with the given options. May return an empty
91 * array if no package roots are specified either at the project level or in t he command line 91 * array if no package roots are specified either at the project level or in t he command line
92 * options. 92 * options.
93 * 93 *
94 * @param core the instance of DartCore used to access project preferences 94 * @param core the instance of DartCore used to access project preferences
95 * @param options the command line options (not {@code null}) 95 * @param options the command line options (not {@code null})
96 * @param container the container for which package roots are to be returned 96 * @param container the container for which package roots are to be returned
97 * @return the package roots (not {@code null}, contains no {@code null}s) 97 * @return the package roots (not {@code null}, contains no {@code null}s)
98 */ 98 */
99 public static File[] getPackageRoots(DartCore core, CmdLineOptions options, IC ontainer container) { 99 public static File[] getPackageRoots(
100 DartCore core, CmdLineOptions options, IContainer container) {
100 if (container instanceof IProject) { 101 if (container instanceof IProject) {
101 IEclipsePreferences prefs = core.getProjectPreferences((IProject) containe r); 102 IEclipsePreferences prefs = core.getProjectPreferences((IProject) containe r);
102 String setting = prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, ""); 103 String setting = prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, "");
103 if (setting != null && setting.length() > 0) { 104 if (setting != null && setting.length() > 0) {
104 ArrayList<File> files = new ArrayList<File>(); 105 ArrayList<File> files = new ArrayList<File>();
105 String[] paths = setting.split(File.pathSeparator); 106 String[] paths = setting.split(File.pathSeparator);
106 for (String path : paths) { 107 for (String path : paths) {
107 files.add(new File(path)); 108 files.add(new File(path));
108 } 109 }
109 return files.toArray(new File[files.size()]); 110 return files.toArray(new File[files.size()]);
110 } 111 }
111 112
112 File packOverrideDir = options.getPackageOverrideDirectory(); 113 File packOverrideDir = options.getPackageOverrideDirectory();
113 if (packOverrideDir != null) { 114 if (packOverrideDir != null) {
114 File root = new File(packOverrideDir, container.getLocation().toOSString ()); 115 File root = new File(packOverrideDir, container.getLocation().toOSString ());
115 return new File[] {new File(root, DartCore.PACKAGES_DIRECTORY_NAME)}; 116 return new File[] {new File(root, DartCore.PACKAGES_DIRECTORY_NAME)};
116 } 117 }
117 118
118 } 119 }
119 return options.getPackageRoots(); 120 return options.getPackageRoots();
120 } 121 }
121 122
122 /** 123 /**
123 * The Eclipse project associated with this Dart project (not {@code null}) 124 * The Eclipse project associated with this Dart project (not {@code null})
124 */ 125 */
125 private final IProject projectResource; 126 private final IProject projectResource;
126 127
127 /** 128 /**
128 * The project resource location on disk or {@code null} if it has not yet bee n initialized. 129 * The project resource location on disk or {@code null} if it has not yet bee n initialized.
129 * 130 *
130 * @see #getResourceLocation() 131 * @see #getResourceLocation()
131 */ 132 */
132 private IPath projectResourceLocation; 133 private IPath projectResourceLocation;
133 134
134 /** 135 /**
135 * The factory used to create new {@link AnalysisContext} (not {@code null}) 136 * The factory used to create new {@link AnalysisContext} (not {@code null})
136 */ 137 */
137 private final AnalysisContextFactory factory; 138 private final AnalysisContextFactory factory;
138 139
139 /** 140 /**
(...skipping 14 matching lines...) Expand all
154 * no pubspec or package root is defined. 155 * no pubspec or package root is defined.
155 */ 156 */
156 private ResourceMap defaultResourceMap; 157 private ResourceMap defaultResourceMap;
157 158
158 /** 159 /**
159 * The index which is updated when contexts are discarded (not {@code null}). 160 * The index which is updated when contexts are discarded (not {@code null}).
160 */ 161 */
161 private final Index index; 162 private final Index index;
162 163
163 /** 164 /**
165 * The default package resolver used for the project
166 */
167 private UriResolver defaultPackageResolver;
168
169 /**
164 * Construct a new instance representing a Dart project 170 * Construct a new instance representing a Dart project
165 * 171 *
166 * @param resource the Eclipse project associated with this Dart project (not {@code null}) 172 * @param resource the Eclipse project associated with this Dart project (not {@code null})
167 * @param sdk the Dart SDK to use when initializing contexts (not {@code null} ) 173 * @param sdk the Dart SDK to use when initializing contexts (not {@code null} )
168 */ 174 */
169 public ProjectImpl(IProject resource, DartSdk sdk) { 175 public ProjectImpl(IProject resource, DartSdk sdk) {
170 this(resource, sdk, DartCore.getProjectManager().getIndex(), new AnalysisCon textFactory()); 176 this(resource, sdk, DartCore.getProjectManager().getIndex(), new AnalysisCon textFactory());
171 } 177 }
172 178
173 /** 179 /**
174 * Construct a new instance representing a Dart project 180 * Construct a new instance representing a Dart project
175 * 181 *
176 * @param resource the Eclipse project associated with this Dart project (not {@code null}) 182 * @param resource the Eclipse project associated with this Dart project (not {@code null})
177 * @param sdk the Dart SDK to use when initializing contexts (not {@code null} ) 183 * @param sdk the Dart SDK to use when initializing contexts (not {@code null} )
178 * @param index the index to be updated when contexts are discarded (not {@cod e null}) 184 * @param index the index to be updated when contexts are discarded (not {@cod e null})
179 * @param factory the factory used to construct new analysis contexts (not {@c ode null}) 185 * @param factory the factory used to construct new analysis contexts (not {@c ode null})
180 */ 186 */
181 public ProjectImpl(IProject resource, DartSdk sdk, Index index, AnalysisContex tFactory factory) { 187 public ProjectImpl(IProject resource, DartSdk sdk, Index index, AnalysisContex tFactory factory) {
182 super(sdk); 188 super(sdk);
183 if (resource == null | factory == null | sdk == null) { 189 if (resource == null | factory == null | sdk == null) {
184 throw new IllegalArgumentException(); 190 throw new IllegalArgumentException();
185 } 191 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 return; 368 return;
363 } 369 }
364 370
365 // If there is already a pubFolder, then ignore the addition 371 // If there is already a pubFolder, then ignore the addition
366 if (getPubFolder(container.getFullPath()) != null) { 372 if (getPubFolder(container.getFullPath()) != null) {
367 return; 373 return;
368 } 374 }
369 375
370 // Create and cache a new pub folder 376 // Create and cache a new pub folder
371 DartSdk sdk = getSdk(); 377 DartSdk sdk = getSdk();
372 PubFolderImpl pubFolder = new PubFolderImpl(container, createContext(conta iner, sdk), sdk); 378 UriResolver pkgResolver = getPackageUriResolver(container, sdk, true);
379 PubFolderImpl pubFolder = new PubFolderImpl(
380 container,
381 createContext(container, sdk),
382 sdk,
383 pkgResolver);
373 pubFolders.put(container.getFullPath(), pubFolder); 384 pubFolders.put(container.getFullPath(), pubFolder);
374 385
375 // If this is the project, then adjust the context source factory 386 // If this is the project, then adjust the context source factory
376 if (container.getType() == PROJECT) { 387 if (container.getType() == PROJECT) {
377 initContext( 388 initContext(
378 defaultContext, 389 defaultContext,
379 projectResource, 390 projectResource,
380 sdk, 391 sdk,
381 getPackageUriResolver(projectResource, sdk, true)); 392 getPackageUriResolver(projectResource, sdk, true));
382 } 393 }
383 394
384 // Merge any overlapping pub folders 395 // Merge any overlapping pub folders
385 for (Iterator<Entry<IPath, PubFolder>> iter = pubFolders.entrySet().iterat or(); iter.hasNext();) { 396 for (Iterator<Entry<IPath, PubFolder>> iter = pubFolders.entrySet().iterat or();
397 iter.hasNext();) {
386 Entry<IPath, PubFolder> entry = iter.next(); 398 Entry<IPath, PubFolder> entry = iter.next();
387 PubFolder parent = getParentPubFolder(entry.getKey()); 399 PubFolder parent = getParentPubFolder(entry.getKey());
388 if (parent != null) { 400 if (parent != null) {
389 parent.getContext().mergeContext(entry.getValue().getContext()); 401 parent.getContext().mergeContext(entry.getValue().getContext());
390 iter.remove(); 402 iter.remove();
391 } 403 }
392 } 404 }
393 } 405 }
394 } 406 }
395 407
(...skipping 22 matching lines...) Expand all
418 getSdk(), 430 getSdk(),
419 getPackageUriResolver(container, getSdk(), false)); 431 getPackageUriResolver(container, getSdk(), false));
420 } 432 }
421 433
422 // Traverse container to find pubspec files that were overshadowed by the one just removed 434 // Traverse container to find pubspec files that were overshadowed by the one just removed
423 createPubFolders(container); 435 createPubFolders(container);
424 } 436 }
425 } 437 }
426 438
427 @Override 439 @Override
440 public String resolvePathToPackage(String path) {
441
442 PubFolder folder = getPubFolder(new Path(path));
443 if (folder != null) {
444 return folder.resolvePathToPackage(path);
445 } else {
446 if (defaultPackageResolver instanceof ExplicitPackageUriResolver) {
447 return ((ExplicitPackageUriResolver) defaultPackageResolver).resolvePath ToPackage(path);
448 }
449 }
450 return null;
451 }
452
453 @Override
428 public IFileInfo resolveUriToFileInfo(IResource relativeTo, String uri) { 454 public IFileInfo resolveUriToFileInfo(IResource relativeTo, String uri) {
429 455
430 AnalysisContext context = getContext(relativeTo); 456 AnalysisContext context = getContext(relativeTo);
431 Source source = context.getSourceFactory().forUri(uri); 457 Source source = context.getSourceFactory().forUri(uri);
432 458
433 ResourceMap map = getResourceMap(relativeTo); 459 ResourceMap map = getResourceMap(relativeTo);
434 if (source != null && map != null) { 460 if (source != null && map != null) {
435 IFile resource = map.getResource(source); 461 IFile resource = map.getResource(source);
436 if (resource != null) { 462 if (resource != null) {
437 return new FileInfo(resource); 463 return new FileInfo(resource);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } catch (Exception e) { 495 } catch (Exception e) {
470 name = "unknown: " + e.getMessage(); 496 name = "unknown: " + e.getMessage();
471 } 497 }
472 return getClass().getSimpleName() + "[" + name + "]@" + Integer.toHexString( hashCode()); 498 return getClass().getSimpleName() + "[" + name + "]@" + Integer.toHexString( hashCode());
473 } 499 }
474 500
475 /** 501 /**
476 * Answer the {@link AnalysisContext} for the specified container, creating on e if necessary. Must 502 * Answer the {@link AnalysisContext} for the specified container, creating on e if necessary. Must
477 * synchronize against {@link #pubFolders} before calling this method and eith er call 503 * synchronize against {@link #pubFolders} before calling this method and eith er call
478 * {@link #initialize()} or check that {@link #isInitialized()} returns {@code true}. 504 * {@link #initialize()} or check that {@link #isInitialized()} returns {@code true}.
479 * 505 *
480 * @param container the container with sources to be analyzed (not {@code null }) 506 * @param container the container with sources to be analyzed (not {@code null })
481 * @param sdk the Dart SDK to use when initializing the context (not {@code nu ll}) 507 * @param sdk the Dart SDK to use when initializing the context (not {@code nu ll})
482 * @return the context (not {@code null}) 508 * @return the context (not {@code null})
483 */ 509 */
484 private AnalysisContext createContext(IContainer container, DartSdk sdk) { 510 private AnalysisContext createContext(IContainer container, DartSdk sdk) {
485 if (container.equals(projectResource)) { 511 if (container.equals(projectResource)) {
486 return defaultContext; 512 return defaultContext;
487 } 513 }
488 AnalysisContext context; 514 AnalysisContext context;
489 IPath location = container.getLocation(); 515 IPath location = container.getLocation();
490 if (location != null) { 516 if (location != null) {
491 SourceContainer sourceContainer = new DirectoryBasedSourceContainer(locati on.toFile()); 517 SourceContainer sourceContainer = new DirectoryBasedSourceContainer(locati on.toFile());
492 context = defaultContext.extractContext(sourceContainer); 518 context = defaultContext.extractContext(sourceContainer);
493 } else { 519 } else {
494 logNoLocation(container); 520 logNoLocation(container);
495 context = factory.createContext(); 521 context = factory.createContext();
496 } 522 }
497 return initContext(context, container, sdk, getPackageUriResolver(container, sdk, true)); 523 return initContext(context, container, sdk, getPackageUriResolver(container, sdk, true));
498 } 524 }
499 525
500 /** 526 /**
501 * Create pub folders for any pubspec files found within the specified contain er. Must synchronize 527 * Create pub folders for any pubspec files found within the specified contain er. Must synchronize
502 * against {@link #pubFolders} before calling this method and either call {@li nk #initialize()} or 528 * against {@link #pubFolders} before calling this method and either call {@li nk #initialize()} or
503 * check that {@link #isInitialized()} returns {@code true}. 529 * check that {@link #isInitialized()} returns {@code true}.
504 * 530 *
505 * @param container the container (not {@code null}) 531 * @param container the container (not {@code null})
506 */ 532 */
507 private void createPubFolders(IContainer container) { 533 private void createPubFolders(IContainer container) {
508 DeltaProcessor processor = new DeltaProcessor(this); 534 DeltaProcessor processor = new DeltaProcessor(this);
509 processor.addDeltaListener(new DeltaAdapter() { 535 processor.addDeltaListener(new DeltaAdapter() {
510 @Override 536 @Override
511 public void pubspecAdded(ResourceDeltaEvent event) { 537 public void pubspecAdded(ResourceDeltaEvent event) {
512 IContainer container = event.getResource().getParent(); 538 IContainer container = event.getResource().getParent();
513 IPath path = container.getFullPath(); 539 IPath path = container.getFullPath();
514 // Pub folders do not nest, so don't create a folder if a parent folder already exists 540 // Pub folders do not nest, so don't create a folder if a parent folder already exists
515 if (getParentPubFolder(path) == null) { 541 if (getParentPubFolder(path) == null) {
516 DartSdk sdk = getSdk(); 542 DartSdk sdk = getSdk();
517 pubFolders.put(path, new PubFolderImpl(container, createContext(contai ner, sdk), sdk)); 543 UriResolver pkgResolver = getPackageUriResolver(container, sdk, true);
544 pubFolders.put(
545 path,
546 new PubFolderImpl(container, createContext(container, sdk), sdk, p kgResolver));
518 } 547 }
519 } 548 }
520 }); 549 });
521 try { 550 try {
522 processor.traverse(container); 551 processor.traverse(container);
523 } catch (CoreException e) { 552 } catch (CoreException e) {
524 DartCore.logError("Failed to build pub folder mapping", e); 553 DartCore.logError("Failed to build pub folder mapping", e);
525 } 554 }
526 // Remove nested pub folders 555 // Remove nested pub folders
527 Iterator<Entry<IPath, PubFolder>> iter = pubFolders.entrySet().iterator(); 556 Iterator<Entry<IPath, PubFolder>> iter = pubFolders.entrySet().iterator();
528 while (iter.hasNext()) { 557 while (iter.hasNext()) {
529 Entry<IPath, PubFolder> entry = iter.next(); 558 Entry<IPath, PubFolder> entry = iter.next();
530 PubFolder parent = getParentPubFolder(entry.getKey()); 559 PubFolder parent = getParentPubFolder(entry.getKey());
531 if (parent != null) { 560 if (parent != null) {
532 parent.getContext().mergeContext(entry.getValue().getContext()); 561 parent.getContext().mergeContext(entry.getValue().getContext());
533 iter.remove(); 562 iter.remove();
534 } 563 }
535 } 564 }
536 } 565 }
537 566
538 /** 567 /**
539 * Answer all the {@link AnalysisContext} for this project. Must synchronize a gainst 568 * Answer all the {@link AnalysisContext} for this project. Must synchronize a gainst
540 * {@link #pubFolders} before calling this method and either call {@link #init ialize()} or check 569 * {@link #pubFolders} before calling this method and either call {@link #init ialize()} or check
541 * that {@link #isInitialized()} returns {@code true}. 570 * that {@link #isInitialized()} returns {@code true}.
542 * 571 *
543 * @return all the analysis contexts in the project 572 * @return all the analysis contexts in the project
544 */ 573 */
545 private AnalysisContext[] getAnalysisContexts() { 574 private AnalysisContext[] getAnalysisContexts() {
546 Set<AnalysisContext> contexts = new HashSet<AnalysisContext>(); 575 Set<AnalysisContext> contexts = new HashSet<AnalysisContext>();
547 for (PubFolder folder : getPubFolders()) { 576 for (PubFolder folder : getPubFolders()) {
548 contexts.add(folder.getContext()); 577 contexts.add(folder.getContext());
549 } 578 }
550 contexts.add(getDefaultContext()); 579 contexts.add(getDefaultContext());
551 return contexts.toArray(new AnalysisContext[contexts.size()]); 580 return contexts.toArray(new AnalysisContext[contexts.size()]);
552 } 581 }
553 582
554 /** 583 /**
555 * Find the most appropriate package resolver for the given container, based o n presence of 584 * Find the most appropriate package resolver for the given container, based o n presence of
556 * pubspec, package roots etc. 585 * pubspec, package roots etc.
557 * 586 *
558 * @return UriResolver used to resolve package: uris. 587 * @return UriResolver used to resolve package: uris.
559 */ 588 */
560 private UriResolver getPackageUriResolver(IContainer container, DartSdk sdk, b oolean hasPubspec) { 589 private UriResolver getPackageUriResolver(IContainer container, DartSdk sdk, b oolean hasPubspec) {
561 590
562 UriResolver pkgResolver = null; 591 UriResolver pkgResolver = null;
563 File[] packageRoots = factory.getPackageRoots(container); 592 File[] packageRoots = factory.getPackageRoots(container);
564 File[] packagesDirs = null; 593 File[] packagesDirs = null;
565 if (hasPubspec) { 594 if (hasPubspec) {
566 IPath location = container.getLocation(); 595 IPath location = container.getLocation();
567 if (location != null) { 596 if (location != null) {
(...skipping 11 matching lines...) Expand all
579 (DirectoryBasedDartSdk) sdk, 608 (DirectoryBasedDartSdk) sdk,
580 container.getLocation().toFile()); 609 container.getLocation().toFile());
581 } 610 }
582 return pkgResolver; 611 return pkgResolver;
583 } 612 }
584 613
585 /** 614 /**
586 * Find the {@link PubFolder} defined for an ancestor. Must synchronize agains t 615 * Find the {@link PubFolder} defined for an ancestor. Must synchronize agains t
587 * {@link #pubFolders} before calling this method and either call {@link #init ialize()} or check 616 * {@link #pubFolders} before calling this method and either call {@link #init ialize()} or check
588 * that {@link #isInitialized()} returns {@code true}. 617 * that {@link #isInitialized()} returns {@code true}.
589 * 618 *
590 * @param path the resource's full path 619 * @param path the resource's full path
591 * @return the containing pub folder or {@code null} if none 620 * @return the containing pub folder or {@code null} if none
592 */ 621 */
593 private PubFolder getParentPubFolder(IPath path) { 622 private PubFolder getParentPubFolder(IPath path) {
594 return path.segmentCount() > 1 ? getPubFolder(path.removeLastSegments(1)) : null; 623 return path.segmentCount() > 1 ? getPubFolder(path.removeLastSegments(1)) : null;
595 } 624 }
596 625
597 /** 626 /**
598 * Answer the {@link PubFolder} for the specified resource path. Must synchron ize against 627 * Answer the {@link PubFolder} for the specified resource path. Must synchron ize against
599 * {@link #pubFolders} before calling this method and either call {@link #init ialize()} or check 628 * {@link #pubFolders} before calling this method and either call {@link #init ialize()} or check
600 * that {@link #isInitialized()} returns {@code true}. 629 * that {@link #isInitialized()} returns {@code true}.
601 * 630 *
602 * @param path the resource full path (not {@code null}) 631 * @param path the resource full path (not {@code null})
603 * @return the folder or {@code null} if none is found 632 * @return the folder or {@code null} if none is found
604 */ 633 */
605 private PubFolder getPubFolder(IPath path) { 634 private PubFolder getPubFolder(IPath path) {
606 if (pubFolders.size() == 0) { 635 if (pubFolders.size() == 0) {
607 return null; 636 return null;
608 } 637 }
609 for (int count = path.segmentCount() - 1; count >= 0; count--) { 638 for (int count = path.segmentCount() - 1; count >= 0; count--) {
610 PubFolder pubFolder = pubFolders.get(path.removeLastSegments(count)); 639 PubFolder pubFolder = pubFolders.get(path.removeLastSegments(count));
611 if (pubFolder != null) { 640 if (pubFolder != null) {
(...skipping 10 matching lines...) Expand all
622 if (projectResourceLocation == null) { 651 if (projectResourceLocation == null) {
623 projectResourceLocation = projectResource.getLocation(); 652 projectResourceLocation = projectResource.getLocation();
624 } 653 }
625 return projectResourceLocation; 654 return projectResourceLocation;
626 } 655 }
627 656
628 /** 657 /**
629 * Initialize the context for analyzing sources in the specified directory. Mu st synchronize 658 * Initialize the context for analyzing sources in the specified directory. Mu st synchronize
630 * against {@link #pubFolders} before calling this method and either call {@li nk #initialize()} or 659 * against {@link #pubFolders} before calling this method and either call {@li nk #initialize()} or
631 * check that {@link #isInitialized()} returns {@code true}. 660 * check that {@link #isInitialized()} returns {@code true}.
632 * 661 *
633 * @param context the context to be initialized (not {@code null}) 662 * @param context the context to be initialized (not {@code null})
634 * @param container the container with sources to be analyzed 663 * @param container the container with sources to be analyzed
635 * @param sdk the Dart SDK to use when initializing the context (not {@code nu ll}) 664 * @param sdk the Dart SDK to use when initializing the context (not {@code nu ll})
636 * @param hasPubspec {@code true} if the container has a pubspec file 665 * @param hasPubspec {@code true} if the container has a pubspec file
637 * @return the context (not {@code null}) 666 * @return the context (not {@code null})
638 */ 667 */
639 private AnalysisContext initContext(AnalysisContext context, IContainer contai ner, DartSdk sdk, 668 private AnalysisContext initContext(
640 UriResolver pkgResolver) { 669 AnalysisContext context, IContainer container, DartSdk sdk, UriResolver pk gResolver) {
641 DartUriResolver dartResolver = new DartUriResolver(sdk); 670 DartUriResolver dartResolver = new DartUriResolver(sdk);
642 671
643 FileUriResolver fileResolver = new FileUriResolver(); 672 FileUriResolver fileResolver = new FileUriResolver();
644 673
645 SourceFactory sourceFactory; 674 SourceFactory sourceFactory;
646 675
647 if (pkgResolver != null) { 676 if (pkgResolver != null) {
648 sourceFactory = new SourceFactory(dartResolver, pkgResolver, fileResolver) ; 677 sourceFactory = new SourceFactory(dartResolver, pkgResolver, fileResolver) ;
649 } else { 678 } else {
650 logNoLocation(container); 679 logNoLocation(container);
(...skipping 14 matching lines...) Expand all
665 694
666 /** 695 /**
667 * Initialize {@link #pubFolders} and {@link #defaultContext} if not already b een initialized. 696 * Initialize {@link #pubFolders} and {@link #defaultContext} if not already b een initialized.
668 * Must synchronize against {@link #pubFolders} before calling this method. 697 * Must synchronize against {@link #pubFolders} before calling this method.
669 */ 698 */
670 private void initialize() { 699 private void initialize() {
671 if (isInitialized()) { 700 if (isInitialized()) {
672 return; 701 return;
673 } 702 }
674 boolean hasPubspec = projectResource.getFile(PUBSPEC_FILE_NAME).exists(); 703 boolean hasPubspec = projectResource.getFile(PUBSPEC_FILE_NAME).exists();
704 defaultPackageResolver = getPackageUriResolver(projectResource, getSdk(), ha sPubspec);
675 defaultContext = initContext( 705 defaultContext = initContext(
676 factory.createContext(), 706 factory.createContext(),
677 projectResource, 707 projectResource,
678 getSdk(), 708 getSdk(),
679 getPackageUriResolver(projectResource, getSdk(), hasPubspec)); 709 defaultPackageResolver);
680 defaultResourceMap = new SimpleResourceMapImpl(projectResource, defaultConte xt); 710 defaultResourceMap = new SimpleResourceMapImpl(projectResource, defaultConte xt);
681 createPubFolders(projectResource); 711 createPubFolders(projectResource);
682 } 712 }
683 713
684 /** 714 /**
685 * Answer true if {@link #defaultContext} and {@link #pubFolders} have been in itialized. Must 715 * Answer true if {@link #defaultContext} and {@link #pubFolders} have been in itialized. Must
686 * synchronize against {@link #pubFolders} before calling this method. 716 * synchronize against {@link #pubFolders} before calling this method.
687 * 717 *
688 * @return {@code true} if initialized, else {@code false} 718 * @return {@code true} if initialized, else {@code false}
689 */ 719 */
690 private boolean isInitialized() { 720 private boolean isInitialized() {
691 return defaultContext != null; 721 return defaultContext != null;
692 } 722 }
693 723
694 private void logNoLocation(IContainer container) { 724 private void logNoLocation(IContainer container) {
695 DartCore.logInformation("No location for " + container); 725 DartCore.logInformation("No location for " + container);
696 } 726 }
697 } 727 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698