| Index: dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/ProjectImpl.java
|
| ===================================================================
|
| --- dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/ProjectImpl.java (revision 31563)
|
| +++ dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/ProjectImpl.java (working copy)
|
| @@ -1,11 +1,11 @@
|
| /*
|
| * Copyright (c) 2013, the Dart project authors.
|
| - *
|
| + *
|
| * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
|
| * in compliance with the License. You may obtain a copy of the License at
|
| - *
|
| + *
|
| * http://www.eclipse.org/legal/epl-v10.html
|
| - *
|
| + *
|
| * Unless required by applicable law or agreed to in writing, software distributed under the License
|
| * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
| * or implied. See the License for the specific language governing permissions and limitations under
|
| @@ -68,7 +68,7 @@
|
|
|
| /**
|
| * Represents an Eclipse project that has a Dart nature.
|
| - *
|
| + *
|
| * @coverage dart.tools.core.model
|
| */
|
| public class ProjectImpl extends ContextManagerImpl implements Project {
|
| @@ -90,13 +90,14 @@
|
| * Answer the package roots for the specified project with the given options. May return an empty
|
| * array if no package roots are specified either at the project level or in the command line
|
| * options.
|
| - *
|
| + *
|
| * @param core the instance of DartCore used to access project preferences
|
| * @param options the command line options (not {@code null})
|
| * @param container the container for which package roots are to be returned
|
| * @return the package roots (not {@code null}, contains no {@code null}s)
|
| */
|
| - public static File[] getPackageRoots(DartCore core, CmdLineOptions options, IContainer container) {
|
| + public static File[] getPackageRoots(
|
| + DartCore core, CmdLineOptions options, IContainer container) {
|
| if (container instanceof IProject) {
|
| IEclipsePreferences prefs = core.getProjectPreferences((IProject) container);
|
| String setting = prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, "");
|
| @@ -126,7 +127,7 @@
|
|
|
| /**
|
| * The project resource location on disk or {@code null} if it has not yet been initialized.
|
| - *
|
| + *
|
| * @see #getResourceLocation()
|
| */
|
| private IPath projectResourceLocation;
|
| @@ -161,8 +162,13 @@
|
| private final Index index;
|
|
|
| /**
|
| + * The default package resolver used for the project
|
| + */
|
| + private UriResolver defaultPackageResolver;
|
| +
|
| + /**
|
| * Construct a new instance representing a Dart project
|
| - *
|
| + *
|
| * @param resource the Eclipse project associated with this Dart project (not {@code null})
|
| * @param sdk the Dart SDK to use when initializing contexts (not {@code null})
|
| */
|
| @@ -172,7 +178,7 @@
|
|
|
| /**
|
| * Construct a new instance representing a Dart project
|
| - *
|
| + *
|
| * @param resource the Eclipse project associated with this Dart project (not {@code null})
|
| * @param sdk the Dart SDK to use when initializing contexts (not {@code null})
|
| * @param index the index to be updated when contexts are discarded (not {@code null})
|
| @@ -369,7 +375,12 @@
|
|
|
| // Create and cache a new pub folder
|
| DartSdk sdk = getSdk();
|
| - PubFolderImpl pubFolder = new PubFolderImpl(container, createContext(container, sdk), sdk);
|
| + UriResolver pkgResolver = getPackageUriResolver(container, sdk, true);
|
| + PubFolderImpl pubFolder = new PubFolderImpl(
|
| + container,
|
| + createContext(container, sdk),
|
| + sdk,
|
| + pkgResolver);
|
| pubFolders.put(container.getFullPath(), pubFolder);
|
|
|
| // If this is the project, then adjust the context source factory
|
| @@ -382,7 +393,8 @@
|
| }
|
|
|
| // Merge any overlapping pub folders
|
| - for (Iterator<Entry<IPath, PubFolder>> iter = pubFolders.entrySet().iterator(); iter.hasNext();) {
|
| + for (Iterator<Entry<IPath, PubFolder>> iter = pubFolders.entrySet().iterator();
|
| + iter.hasNext();) {
|
| Entry<IPath, PubFolder> entry = iter.next();
|
| PubFolder parent = getParentPubFolder(entry.getKey());
|
| if (parent != null) {
|
| @@ -425,6 +437,20 @@
|
| }
|
|
|
| @Override
|
| + public String resolvePathToPackage(String path) {
|
| +
|
| + PubFolder folder = getPubFolder(new Path(path));
|
| + if (folder != null) {
|
| + return folder.resolvePathToPackage(path);
|
| + } else {
|
| + if (defaultPackageResolver instanceof ExplicitPackageUriResolver) {
|
| + return ((ExplicitPackageUriResolver) defaultPackageResolver).resolvePathToPackage(path);
|
| + }
|
| + }
|
| + return null;
|
| + }
|
| +
|
| + @Override
|
| public IFileInfo resolveUriToFileInfo(IResource relativeTo, String uri) {
|
|
|
| AnalysisContext context = getContext(relativeTo);
|
| @@ -476,7 +502,7 @@
|
| * Answer the {@link AnalysisContext} for the specified container, creating one if necessary. Must
|
| * synchronize against {@link #pubFolders} before calling this method and either call
|
| * {@link #initialize()} or check that {@link #isInitialized()} returns {@code true}.
|
| - *
|
| + *
|
| * @param container the container with sources to be analyzed (not {@code null})
|
| * @param sdk the Dart SDK to use when initializing the context (not {@code null})
|
| * @return the context (not {@code null})
|
| @@ -501,7 +527,7 @@
|
| * Create pub folders for any pubspec files found within the specified container. Must synchronize
|
| * against {@link #pubFolders} before calling this method and either call {@link #initialize()} or
|
| * check that {@link #isInitialized()} returns {@code true}.
|
| - *
|
| + *
|
| * @param container the container (not {@code null})
|
| */
|
| private void createPubFolders(IContainer container) {
|
| @@ -514,7 +540,10 @@
|
| // Pub folders do not nest, so don't create a folder if a parent folder already exists
|
| if (getParentPubFolder(path) == null) {
|
| DartSdk sdk = getSdk();
|
| - pubFolders.put(path, new PubFolderImpl(container, createContext(container, sdk), sdk));
|
| + UriResolver pkgResolver = getPackageUriResolver(container, sdk, true);
|
| + pubFolders.put(
|
| + path,
|
| + new PubFolderImpl(container, createContext(container, sdk), sdk, pkgResolver));
|
| }
|
| }
|
| });
|
| @@ -539,7 +568,7 @@
|
| * Answer all the {@link AnalysisContext} for this project. Must synchronize against
|
| * {@link #pubFolders} before calling this method and either call {@link #initialize()} or check
|
| * that {@link #isInitialized()} returns {@code true}.
|
| - *
|
| + *
|
| * @return all the analysis contexts in the project
|
| */
|
| private AnalysisContext[] getAnalysisContexts() {
|
| @@ -554,7 +583,7 @@
|
| /**
|
| * Find the most appropriate package resolver for the given container, based on presence of
|
| * pubspec, package roots etc.
|
| - *
|
| + *
|
| * @return UriResolver used to resolve package: uris.
|
| */
|
| private UriResolver getPackageUriResolver(IContainer container, DartSdk sdk, boolean hasPubspec) {
|
| @@ -586,7 +615,7 @@
|
| * Find the {@link PubFolder} defined for an ancestor. Must synchronize against
|
| * {@link #pubFolders} before calling this method and either call {@link #initialize()} or check
|
| * that {@link #isInitialized()} returns {@code true}.
|
| - *
|
| + *
|
| * @param path the resource's full path
|
| * @return the containing pub folder or {@code null} if none
|
| */
|
| @@ -598,7 +627,7 @@
|
| * Answer the {@link PubFolder} for the specified resource path. Must synchronize against
|
| * {@link #pubFolders} before calling this method and either call {@link #initialize()} or check
|
| * that {@link #isInitialized()} returns {@code true}.
|
| - *
|
| + *
|
| * @param path the resource full path (not {@code null})
|
| * @return the folder or {@code null} if none is found
|
| */
|
| @@ -629,15 +658,15 @@
|
| * Initialize the context for analyzing sources in the specified directory. Must synchronize
|
| * against {@link #pubFolders} before calling this method and either call {@link #initialize()} or
|
| * check that {@link #isInitialized()} returns {@code true}.
|
| - *
|
| + *
|
| * @param context the context to be initialized (not {@code null})
|
| * @param container the container with sources to be analyzed
|
| * @param sdk the Dart SDK to use when initializing the context (not {@code null})
|
| * @param hasPubspec {@code true} if the container has a pubspec file
|
| * @return the context (not {@code null})
|
| */
|
| - private AnalysisContext initContext(AnalysisContext context, IContainer container, DartSdk sdk,
|
| - UriResolver pkgResolver) {
|
| + private AnalysisContext initContext(
|
| + AnalysisContext context, IContainer container, DartSdk sdk, UriResolver pkgResolver) {
|
| DartUriResolver dartResolver = new DartUriResolver(sdk);
|
|
|
| FileUriResolver fileResolver = new FileUriResolver();
|
| @@ -672,11 +701,12 @@
|
| return;
|
| }
|
| boolean hasPubspec = projectResource.getFile(PUBSPEC_FILE_NAME).exists();
|
| + defaultPackageResolver = getPackageUriResolver(projectResource, getSdk(), hasPubspec);
|
| defaultContext = initContext(
|
| factory.createContext(),
|
| projectResource,
|
| getSdk(),
|
| - getPackageUriResolver(projectResource, getSdk(), hasPubspec));
|
| + defaultPackageResolver);
|
| defaultResourceMap = new SimpleResourceMapImpl(projectResource, defaultContext);
|
| createPubFolders(projectResource);
|
| }
|
| @@ -684,7 +714,7 @@
|
| /**
|
| * Answer true if {@link #defaultContext} and {@link #pubFolders} have been initialized. Must
|
| * synchronize against {@link #pubFolders} before calling this method.
|
| - *
|
| + *
|
| * @return {@code true} if initialized, else {@code false}
|
| */
|
| private boolean isInitialized() {
|
|
|