Added support for variable ${project} in import roots.
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_parse_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_parse_Test.java
index 2122362..7dc12eb 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_parse_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_parse_Test.java
@@ -26,6 +26,12 @@
     assertThat(path.isWorkspacePath(), equalTo(true));
   }
 
+  @Test public void should_parse_project_path() {
+    DirectoryPath path = DirectoryPath.parse("/${project}/src}");
+    assertThat(path.value(), equalTo("/${project}/src}"));
+    assertThat(path.isWorkspacePath(), equalTo(true));
+  }
+
   @Test public void should_parse_file_system_path() {
     DirectoryPath path = DirectoryPath.parse("/test/src");
     assertThat(path.value(), equalTo("/test/src"));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_toString_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_toString_Test.java
index 0b90114..c387983 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_toString_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath_toString_Test.java
@@ -25,6 +25,11 @@
     assertThat(path.toString(), equalTo("${workspace_loc:/test/src}"));
   }
 
+  @Test public void should_specify_is_project_path() {
+    DirectoryPath path = new DirectoryPath("/${project}/src", true);
+    assertThat(path.toString(), equalTo("/${project}/src"));
+  }
+
   @Test public void should_return_plain_value_if_it_is_not_workspace_path() {
     DirectoryPath path = new DirectoryPath("/test/src", false);
     assertThat(path.toString(), equalTo("/test/src"));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
index 032d125..c117191 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
@@ -15,11 +15,10 @@
 import org.junit.*;
 
 import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.Property;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
+import com.google.eclipse.protobuf.protobuf.*;
 
 /**
- * Tests for <code>{@link Fields#calculateTagNumberOf(Property)}</code>.
+ * Tests for <code>{@link Fields#calculateTagNumberOf(Field)}</code>.
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/ProjectVariable_useProjectName_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/ProjectVariable_useProjectName_Test.java
new file mode 100644
index 0000000..417f81a
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/ProjectVariable_useProjectName_Test.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.util;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.*;
+
+import org.eclipse.core.resources.IProject;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProjectVariable#useProjectName(String, IProject)}</code>.
+ * 
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProjectVariable_useProjectName_Test {
+
+  private IProject project;
+  
+  @Before public void setUp() {
+    project = mock(IProject.class);
+  }
+  
+  @Test public void should_use_project_name_if_path_contains_variable() {
+    when(project.getName()).thenReturn("test");
+    String newPath = ProjectVariable.useProjectName("/${project}/src/test", project);
+    assertThat(newPath, equalTo("/test/src/test"));
+  }
+  
+  @Test public void should_not_use_project_name_if_path_does_not_contain_variable() {
+    when(project.getName()).thenReturn("test");
+    String newPath = ProjectVariable.useProjectName("/main/src/test", project);
+    assertThat(newPath, equalTo("/main/src/test"));
+  }
+
+  @Test public void should_not_use_project_name_if_path_already_contains_it() {
+    when(project.getName()).thenReturn("test");
+    String newPath = ProjectVariable.useProjectName("/test/src/test", project);
+    assertThat(newPath, equalTo("/test/src/test"));
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/ProjectVariable_useProjectVariable_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/ProjectVariable_useProjectVariable_Test.java
new file mode 100644
index 0000000..4cab0c5
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/ProjectVariable_useProjectVariable_Test.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.util;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.*;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.*;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProjectVariable#useProjectVariable(IPath, IProject)}</code>.
+ * 
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProjectVariable_useProjectVariable_Test {
+
+  private IProject project;
+  
+  @Before public void setUp() {
+    project = mock(IProject.class);
+  }
+  
+  @Test public void should_use_variable_if_path_contains_project_name() {
+    IPath path = new Path("/test/src/test");
+    when(project.getName()).thenReturn("test");
+    IPath newPath = ProjectVariable.useProjectVariable(path, project);
+    assertThat(newPath.toString(), equalTo("/${project}/src/test"));
+  }
+  
+  @Test public void should_not_use_variable_if_path_does_not_contain_project_name() {
+    IPath path = new Path("/main/src/test");
+    when(project.getName()).thenReturn("test");
+    IPath newPath = ProjectVariable.useProjectVariable(path, project);
+    assertThat(newPath.toString(), equalTo("/main/src/test"));
+  }
+
+  @Test public void should_not_use_variable_if_path_already_contains_it() {
+    IPath path = new Path("/${project}/src/test");
+    when(project.getName()).thenReturn("test");
+    IPath newPath = ProjectVariable.useProjectVariable(path, project);
+    assertThat(newPath.toString(), equalTo("/${project}/src/test"));
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Strings_firstCharToLowerCase_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Strings_firstCharToLowerCase_Test.java
index 6453372..47fd9b1 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Strings_firstCharToLowerCase_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Strings_firstCharToLowerCase_Test.java
@@ -12,7 +12,6 @@
 import static org.hamcrest.core.IsNull.nullValue;
 import static org.junit.Assert.assertThat;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
index 1e55016..6aa9563 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
@@ -64,7 +64,7 @@
   private List<String> importRoots(IProject project) {
     List<String> paths = new ArrayList<String>();
     PathsPreferences preferences = pathsPreferencesProvider.getPreferences(project);
-    List<DirectoryPath> directoryPaths = preferences.directoryPaths();
+    List<DirectoryPath> directoryPaths = preferences.importRoots();
     for (DirectoryPath path : directoryPaths) {
       String location = locationOfDirectory(path, project);
       if (location != null) paths.add(location);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java
index cd4cd0d..5679b03 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java
@@ -10,18 +10,20 @@
 
 import static com.google.eclipse.protobuf.ui.preferences.paths.DirectorySelectionDialogs.*;
 import static com.google.eclipse.protobuf.ui.preferences.paths.Messages.*;
+import static com.google.eclipse.protobuf.ui.util.ProjectVariable.useProjectVariable;
 import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID;
 import static org.eclipse.xtext.util.Strings.isEmpty;
 
+import com.google.eclipse.protobuf.ui.preferences.InputDialog;
+
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.*;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.*;
 import org.eclipse.swt.widgets.*;
 
-import com.google.eclipse.protobuf.ui.preferences.InputDialog;
-
 /**
  * Dialog where users can select a path (in the workspace or file system) to be included in resolution of imports.
  *
@@ -29,6 +31,8 @@
  */
 public class AddDirectoryDialog extends InputDialog {
 
+  private final IProject project;
+
   private DirectoryPath selectedPath;
 
   private Text txtPath;
@@ -43,6 +47,7 @@
    */
   public AddDirectoryDialog(Shell parent, IProject project) {
     super(parent, addDirectoryPath);
+    this.project = project;
   }
 
   /** {@inheritDoc} */
@@ -94,16 +99,17 @@
   private void addEventListeners() {
     btnWorkspace.addSelectionListener(new SelectionAdapter() {
       @Override public void widgetSelected(SelectionEvent e) {
-        String path = showWorkspaceDirectoryDialog(getShell(), enteredPathText());
+        IPath path = showWorkspaceDirectorySelectionDialog(getShell(), enteredPathText());
         if (path != null) {
-          txtPath.setText(path.trim());
+          path = useProjectVariable(path, project);
+          txtPath.setText(path.toString().trim());
           btnIsWorkspacePath.setSelection(true);
         }
       }
     });
     btnFileSystem.addSelectionListener(new SelectionAdapter() {
       @Override public void widgetSelected(SelectionEvent e) {
-        String path = showFileSystemFolderDialog(getShell(), enteredPathText());
+        String path = showFileSystemDirectorySelectionDialog(getShell(), enteredPathText());
         if (path != null) {
           txtPath.setText(path.trim());
           btnIsWorkspacePath.setSelection(false);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java
index 985589c..611426d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java
@@ -8,8 +8,9 @@
  */
 package com.google.eclipse.protobuf.ui.preferences.paths;
 
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import static com.google.eclipse.protobuf.ui.util.ProjectVariable.containsProjectVariable;
+
+import java.util.regex.*;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
@@ -24,6 +25,7 @@
   static DirectoryPath parse(String path) {
     Matcher matcher = WORKSPACE_PATH_PATTERN.matcher(path);
     if (matcher.matches()) return new DirectoryPath(matcher.group(1), true);
+    if (containsProjectVariable(path)) return new DirectoryPath(path, true);
     return new DirectoryPath(path, false);
   }
   
@@ -34,7 +36,7 @@
   
   /** {@inheritDoc} */
   @Override public String toString() {
-    if (!isWorkspacePath) return value;
+    if (!isWorkspacePath || containsProjectVariable(value)) return value;
     return "${workspace_loc:" + value + "}";
   }
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java
index e978653..cf088d0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java
@@ -32,20 +32,21 @@
  */
 class DirectorySelectionDialogs {
 
-  static String showWorkspaceDirectoryDialog(Shell shell, String initialPath) {
-    return showWorkspaceDirectoryDialog(shell, initialPath, null);
+  static IPath showWorkspaceDirectorySelectionDialog(Shell shell, String initialPath) {
+    return showWorkspaceDirectorySelectionDialog(shell, initialPath, null);
   }
 
-  static String showWorkspaceDirectoryDialog(Shell shell, String initialPath, IProject project) {
+  static IPath showWorkspaceDirectorySelectionDialog(Shell shell, String initialPath, IProject project) {
     String currentPathText = initialPath.replaceAll("\"", "");
     URI uri = URI.create(currentPathText);
     ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(),
         new WorkbenchContentProvider());
-    dialog.setInput(project == null ? workspaceRoot() : project);
+    IWorkspaceRoot workspaceRoot = workspaceRoot();
+    dialog.setInput(project == null ? workspaceRoot : project);
     dialog.setComparator(new ResourceComparator(NAME));
     IResource container = null;
     if (uri.isAbsolute()) {
-      IContainer containers[] = workspaceRoot().findContainersForLocationURI(uri);
+      IContainer containers[] = workspaceRoot.findContainersForLocationURI(uri);
       if (containers != null && containers.length > 0) container = containers[0];
     }
     dialog.setInitialSelection(container);
@@ -60,11 +61,10 @@
     dialog.setMessage(selectWorkspaceDirectory);
     if (dialog.open() != OK) return null;
     IResource resource = (IResource) dialog.getFirstResult();
-    if (resource == null) return null;
-    return resource.getFullPath().toString();
+    return (resource == null) ? null : resource.getFullPath();
   }
 
-  static String showFileSystemFolderDialog(Shell shell, String filterPath) {
+  static String showFileSystemDirectorySelectionDialog(Shell shell, String filterPath) {
     DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN | SWT.APPLICATION_MODAL);
     if (filterPath != null && filterPath.trim().length() != 0) dialog.setFilterPath(filterPath);
     dialog.setMessage(selectFileSystemDirectory);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java
index bd15f7d..c7faae3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java
@@ -78,7 +78,7 @@
     IPreferenceStore store = getPreferenceStore();
     btnOneFolderOnly.setSelection(store.getBoolean(FILES_IN_ONE_DIRECTORY_ONLY));
     btnMultipleFolders.setSelection(store.getBoolean(FILES_IN_MULTIPLE_DIRECTORIES));
-    setDirectoryPaths(store.getString(DIRECTORY_PATHS));
+    setDirectoryPaths(store.getString(IMPORT_ROOTS));
     enableProjectOptions(true);
   }
 
@@ -113,7 +113,7 @@
   @Override protected void performDefaults(IPreferenceStore store) {
     btnOneFolderOnly.setSelection(store.getDefaultBoolean(FILES_IN_ONE_DIRECTORY_ONLY));
     btnMultipleFolders.setSelection(store.getDefaultBoolean(FILES_IN_MULTIPLE_DIRECTORIES));
-    setDirectoryPaths(store.getDefaultString(DIRECTORY_PATHS));
+    setDirectoryPaths(store.getDefaultString(IMPORT_ROOTS));
     enableProjectOptions(true);
     super.performDefaults();
   }
@@ -138,7 +138,7 @@
   @Override protected void savePreferences(IPreferenceStore store) {
     store.setValue(FILES_IN_ONE_DIRECTORY_ONLY, btnOneFolderOnly.getSelection());
     store.setValue(FILES_IN_MULTIPLE_DIRECTORIES, btnMultipleFolders.getSelection());
-    store.setValue(DIRECTORY_PATHS, directoryNames());
+    store.setValue(IMPORT_ROOTS, directoryNames());
   }
 
   private String directoryNames() {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java
index 0766d28..0eb2245 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java
@@ -26,7 +26,7 @@
     IPreferenceStore store = access.getWritablePreferenceStore();
     store.setDefault(FILES_IN_ONE_DIRECTORY_ONLY, true);
     store.setDefault(FILES_IN_MULTIPLE_DIRECTORIES, false);
-    store.setDefault(DIRECTORY_PATHS, "");
+    store.setDefault(IMPORT_ROOTS, "");
   }
 
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java
index 262203b..f276046 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java
@@ -9,7 +9,7 @@
 package com.google.eclipse.protobuf.ui.preferences.paths;
 
 import static com.google.eclipse.protobuf.ui.preferences.paths.PathResolutionType.SINGLE_DIRECTORY;
-import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.DIRECTORY_PATHS;
+import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.IMPORT_ROOTS;
 import static com.google.eclipse.protobuf.ui.util.Strings.CSV_PATTERN;
 import static java.util.Collections.*;
 
@@ -27,27 +27,27 @@
 public class PathsPreferences {
 
   private final PathResolutionType pathResolutionType;
-  private final List<DirectoryPath> directoryPaths;
+  private final List<DirectoryPath> importRoots;
 
   PathsPreferences(IPreferenceStore store) {
     pathResolutionType = PathResolutionType.readFrom(store);
-    directoryPaths = directoryPaths(pathResolutionType, store);
+    importRoots = importRoots(pathResolutionType, store);
   }
 
-  private static List<DirectoryPath> directoryPaths(PathResolutionType types, IPreferenceStore store) {
+  private static List<DirectoryPath> importRoots(PathResolutionType types, IPreferenceStore store) {
     if (types.equals(SINGLE_DIRECTORY)) return emptyList();
-    List<DirectoryPath> paths = new ArrayList<DirectoryPath>();
-    for (String directoryPath : store.getString(DIRECTORY_PATHS).split(CSV_PATTERN)) {
-      paths.add(DirectoryPath.parse(directoryPath));
+    List<DirectoryPath> roots = new ArrayList<DirectoryPath>();
+    for (String root : store.getString(IMPORT_ROOTS).split(CSV_PATTERN)) {
+      roots.add(DirectoryPath.parse(root));
     }
-    return unmodifiableList(paths);
+    return unmodifiableList(roots);
   }
 
   public PathResolutionType pathResolutionType() {
     return pathResolutionType;
   }
 
-  public List<DirectoryPath> directoryPaths() {
-    return directoryPaths;
+  public List<DirectoryPath> importRoots() {
+    return importRoots;
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java
index 936db6f..4bd8025 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java
@@ -15,7 +15,7 @@
 
   static final String FILES_IN_ONE_DIRECTORY_ONLY = "paths.filesInOneDirectoryOnly";
   static final String FILES_IN_MULTIPLE_DIRECTORIES = "paths.filesInMultipleDirectories";
-  static final String DIRECTORY_PATHS = "paths.directoryPaths";
+  static final String IMPORT_ROOTS = "paths.directoryPaths";
 
   private PreferenceNames() {}
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
index b4f7db7..b39adbc 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
@@ -8,6 +8,8 @@
  */
 package com.google.eclipse.protobuf.ui.scoping;
 
+import static com.google.eclipse.protobuf.ui.util.ProjectVariable.useProjectName;
+
 import java.util.List;
 
 import org.eclipse.core.filesystem.*;
@@ -18,7 +20,7 @@
 
 import com.google.eclipse.protobuf.ui.preferences.paths.DirectoryPath;
 import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences;
-import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.eclipse.protobuf.ui.util.*;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
@@ -35,32 +37,32 @@
 
   /** {@inheritDoc} */
   public String resolveUri(String importUri, URI declaringResourceUri, IProject project, PathsPreferences preferences) {
-    List<DirectoryPath> directoryPaths = preferences.directoryPaths();
-    for (DirectoryPath directoryPath : directoryPaths) {
-      String resolved = resolveUri(importUri, directoryPath);
+    List<DirectoryPath> importRoots = preferences.importRoots();
+    for (DirectoryPath root : importRoots) {
+      String resolved = resolveUri(importUri, root, project);
       if (resolved != null) return resolved;
     }
-    for (DirectoryPath directoryPath : directoryPaths) {
-      if (!directoryPath.isWorkspacePath()) continue;
-      String resolved = resolveUriFileSystem(importUri, mapping.folderLocation(directoryPath.value()));
+    for (DirectoryPath root : importRoots) {
+      if (!root.isWorkspacePath()) continue;
+      String resolved = resolveUriInFileSystem(importUri, mapping.folderLocation(root.value()));
       if (resolved != null) return resolved;
     }
     return null;
   }
 
-  private String resolveUri(String importUri, DirectoryPath importRoot) {
+  private String resolveUri(String importUri, DirectoryPath importRoot, IProject project) {
     String root = importRoot.value();
-    if (importRoot.isWorkspacePath()) return resolveUriInWorkspace(importUri, root);
-    return resolveUriFileSystem(importUri, root);
+    if (importRoot.isWorkspacePath()) return resolveUriInWorkspace(importUri, root, project);
+    return resolveUriInFileSystem(importUri, root);
   }
 
-  private String resolveUriInWorkspace(String importUri, String importRoot) {
-    String path = PREFIX + importRoot + SEPARATOR + importUri;
+  private String resolveUriInWorkspace(String importUri, String importRoot, IProject project) {
+    String path = PREFIX + useProjectName(importRoot, project) + SEPARATOR + importUri;
     boolean exists = resources.fileExists(URI.createURI(path));
     return (exists) ? path : null;
   }
 
-  private String resolveUriFileSystem(String importUri, String importRoot) {
+  private String resolveUriInFileSystem(String importUri, String importRoot) {
     IFileSystem fileSystem = EFS.getLocalFileSystem();
     IPath path = new Path(importRoot + SEPARATOR + importUri);
     IFileInfo fileInfo = fileSystem.getStore(path).fetchInfo();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/ProjectVariable.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/ProjectVariable.java
new file mode 100644
index 0000000..787c78b
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/ProjectVariable.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.util;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.*;
+
+/**
+ * ${project} variable.
+ * 
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProjectVariable {
+
+  private static final String VARIABLE_VALUE = "${project}";
+
+  public static IPath useProjectVariable(IPath path, IProject project) {
+    return switchNames(path, project.getName(), VARIABLE_VALUE);
+  }
+  
+  public static String useProjectName(String path, IProject project) {
+    IPath newPath = switchNames(new Path(path), VARIABLE_VALUE, project.getName());
+    return newPath.toString();
+  }
+  
+  private static IPath switchNames(IPath path, String originalName, String newName) {
+    if (!originalName.equals(path.segment(0))) return path;
+    IPath newPath = new Path(newName);
+    newPath = newPath.append(path.removeFirstSegments(1));
+    if (path.isAbsolute()) newPath = newPath.makeAbsolute();
+    return newPath;
+  }
+
+  public static boolean containsProjectVariable(String path) {
+    return path != null && path.contains(VARIABLE_VALUE);
+  }
+}