Fixed: [Issue 203] NPE when generating protoc command.
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateNewIndexOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Literals_calculateNewIndexOf_Test.java
similarity index 93%
rename from com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateNewIndexOf_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Literals_calculateNewIndexOf_Test.java
index cdf4137..7580486 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateNewIndexOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Literals_calculateNewIndexOf_Test.java
@@ -6,7 +6,7 @@
  *
  * http://www.eclipse.org/legal/epl-v10.html
  */
-package com.google.eclipse.protobuf.ui.util;
+package com.google.eclipse.protobuf.model.util;
 
 import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule;
 import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith;
@@ -16,6 +16,7 @@
 import org.junit.*;
 
 import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.model.util.Literals;
 import com.google.eclipse.protobuf.protobuf.Literal;
 import com.google.inject.Inject;
 
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/IPaths_areReferringToSameFile_Tests.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java
similarity index 60%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/IPaths_areReferringToSameFile_Tests.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java
index 62a7d42..5706a4b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/IPaths_areReferringToSameFile_Tests.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java
@@ -6,42 +6,45 @@
  *
  * http://www.eclipse.org/legal/epl-v10.html
  */
-package com.google.eclipse.protobuf.util;
+package com.google.eclipse.protobuf.resource;
 
+import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule;
+import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith;
 import static org.junit.Assert.*;
 
 import org.eclipse.core.runtime.*;
 import org.eclipse.emf.common.util.URI;
 import org.junit.*;
 
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.inject.Inject;
+
 /**
- * Tests for <code>{@link IPaths#areReferringToSameFile(IPath, URI)}</code>
+ * Tests for <code>{@link IndexLookup#areReferringToSameFile(IPath, URI)}</code>
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-public class IPaths_areReferringToSameFile_Tests {
-  private IPaths paths;
+public class IndexLookup_areReferringToSameFile_Tests {
+  @Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule());
 
-  @Before public void setUp() {
-    paths = new IPaths();
-  }
+  @Inject private IndexLookup lookup;
 
   @Test public void should_return_true_if_both_have_exactly_equal_segments() {
     String pathValue = "/usr/local/google/proto";
     IPath path = new Path(pathValue);
     URI uri = URI.createPlatformResourceURI(pathValue, false);
-    assertTrue(paths.areReferringToSameFile(path, uri));
+    assertTrue(lookup.areReferringToSameFile(path, uri));
   }
 
   @Test public void should_return_true_if_path_is_subset_of_URI() {
     IPath path = new Path("/google/proto");
     URI uri = URI.createPlatformResourceURI("/usr/local/google/proto", false);
-    assertTrue(paths.areReferringToSameFile(path, uri));
+    assertTrue(lookup.areReferringToSameFile(path, uri));
   }
 
   @Test public void should_return_false_if_last_segments_in_path_and_URI_are_not_equal() {
     IPath path = new Path("/usr/local/google/proto");
     URI uri = URI.createPlatformResourceURI("/usr/local/google/cpp", false);
-    assertFalse(paths.areReferringToSameFile(path, uri));
+    assertFalse(lookup.areReferringToSameFile(path, uri));
   }
 }
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption_segmentsOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption_segmentsOf_Test.java
new file mode 100644
index 0000000..529ba21
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption_segmentsOf_Test.java
@@ -0,0 +1,47 @@
+/*
+ * 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.protoc.command;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static java.io.File.separator;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+import org.eclipse.xtext.util.Strings;
+import org.junit.Test;
+
+/**
+ * Tests for <code>{@link AbstractOutputDirectoryProtocOption#segmentsOf(String)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class AbstractOutputDirectoryProtocOption_segmentsOf_Test {
+  @Test(expected = NullPointerException.class)
+  public void should_throw_error_if_path_is_null() {
+    AbstractOutputDirectoryProtocOption.segmentsOf(null);
+  }
+
+  @Test public void should_separate_segments_using_system_file_separator() {
+    String[] expected = { "folder1" , "folder1_1", "folder1_1_1" };
+    String path = pathFrom(expected);
+    String[] segments = AbstractOutputDirectoryProtocOption.segmentsOf(path);
+    assertThat(segments, equalTo(expected));
+  }
+
+  @Test public void should_separate_segments_for_path_ending_with_system_file_separator() {
+    String[] expected = { "folder1" , "folder1_1" };
+    String path = pathFrom(expected);
+    String[] segments = AbstractOutputDirectoryProtocOption.segmentsOf(path);
+    assertThat(segments, equalTo(expected));
+  }
+
+  private String pathFrom(String[] segments) {
+    return Strings.concat(separator, newArrayList(segments));
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy_resolveUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy_resolveUri_Test.java
index c3149d8..7780e35 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy_resolveUri_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy_resolveUri_Test.java
@@ -39,7 +39,7 @@
 
   @Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule(), new TestModule());
 
-  @Inject private PathMapping mapping;
+  @Inject private ResourceLocations locations;
   @Inject private Uris uris;
   @Inject private MultipleDirectoriesFileResolverStrategy resolver;
 
@@ -76,7 +76,7 @@
     // try the first time as resource platform
     when(uris.referredResourceExists(URI.createURI("platform:/resource/src/protos/imported.proto"))).thenReturn(false);
     // try again, but in the file system this time
-    when(mapping.directoryLocation("/src/protos")).thenReturn("/usr/local/project/src/protos");
+    when(locations.directoryLocation("/src/protos")).thenReturn("/usr/local/project/src/protos");
     when(uris.referredResourceExists(URI.createURI(expected))).thenReturn(true);
     String resolved = resolver.resolveUri("imported.proto", declaringResourceUri, allPreferences);
     assertThat(resolved, equalTo(expected));
@@ -99,7 +99,7 @@
   private static class TestModule extends AbstractTestModule {
     @Override protected void configure() {
       mockAndBind(Uris.class);
-      mockAndBind(PathMapping.class);
+      mockAndBind(ResourceLocations.class);
     }
   }
 }
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java
deleted file mode 100644
index 2efa7eb..0000000
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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 java.io.File.separator;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-import org.junit.Test;
-
-/**
- * Tests for <code>{@link Paths#segmentsOf(String)}</code>.
- *
- * @author alruiz@google.com (Alex Ruiz)
- */
-public class Paths_segmentsOf_Test {
-  @Test(expected = NullPointerException.class)
-  public void should_throw_error_if_path_is_null() {
-    Paths.segmentsOf(null);
-  }
-
-  @Test public void should_separate_segments_using_system_file_separator() {
-    String path = "folder1" + separator + "folder1_1" + separator + "folder1_1_1";
-    assertThat(Paths.segmentsOf(path), equalTo(new String[] { "folder1" , "folder1_1", "folder1_1_1" }));
-  }
-
-  @Test public void should_separate_segments_for_path_ending_with_system_file_separator() {
-    String path = "folder1" + separator + "folder1_1" + separator;
-    assertThat(Paths.segmentsOf(path), equalTo(new String[] { "folder1" , "folder1_1" }));
-  }
-}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
index 5ad93d7..a9f533a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
@@ -12,6 +12,7 @@
 import static com.google.eclipse.protobuf.ui.builder.protoc.ConsolePrinter.createAndDisplayConsole;
 import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
 import static com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences.compilerPreferences;
+import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
 import static org.eclipse.core.resources.IResource.DEPTH_INFINITE;
 
 import java.io.*;
@@ -67,7 +68,7 @@
 
   private IFile protoFile(IResourceDescription resource, IProject project) {
     String path = filePathIfIsProtoFile(resource);
-    return (path == null) ? null : project.getWorkspace().getRoot().getFile(new Path(path));
+    return (path == null) ? null : workspaceRoot().getFile(new Path(path));
   }
 
   private String filePathIfIsProtoFile(IResourceDescription resource) {
@@ -75,19 +76,10 @@
       return null;
     }
     URI uri = resource.getURI();
-    if (!uri.fileExtension().equals("proto")) {
+    if (!uri.isPlatformResource() && !uri.fileExtension().equals("proto")) {
       return null;
     }
-    if (uri.scheme() == null) {
-      return uri.toFileString();
-    }
-    StringBuilder b = new StringBuilder();
-    int segmentCount = uri.segmentCount();
-    for (int i = 1; i < segmentCount; i++)
-     {
-      b.append("/").append(uri.segment(i));
-    }
-    return b.length() == 0 ? null : b.toString();
+    return uri.toPlatformString(true);
   }
 
   private void generateSingleProto(String command, IFile protoFile) throws CoreException {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
index 1478c89..63fdb18 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
@@ -34,7 +34,6 @@
 import com.google.eclipse.protobuf.protobuf.*;
 import com.google.eclipse.protobuf.ui.commands.SmartInsertHandler;
 import com.google.eclipse.protobuf.ui.preferences.editor.numerictag.core.NumericTagPreferences;
-import com.google.eclipse.protobuf.ui.util.Literals;
 import com.google.inject.Inject;
 
 /**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
index 6a9c433..2415f8e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
@@ -38,7 +38,6 @@
 import com.google.eclipse.protobuf.scoping.*;
 import com.google.eclipse.protobuf.ui.grammar.CompoundElement;
 import com.google.eclipse.protobuf.ui.labeling.Images;
-import com.google.eclipse.protobuf.ui.util.Literals;
 import com.google.inject.Inject;
 
 /**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/misc/core/MiscellaneousPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/misc/core/MiscellaneousPreferenceStoreInitializer.java
index f768584..0d394fe 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/misc/core/MiscellaneousPreferenceStoreInitializer.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/misc/core/MiscellaneousPreferenceStoreInitializer.java
@@ -18,6 +18,6 @@
 public class MiscellaneousPreferenceStoreInitializer implements IPreferenceStoreInitializer {
   @Override public void initialize(IPreferenceStoreAccess storeAccess) {
     MiscellaneousPreferences preferences = new MiscellaneousPreferences(storeAccess);
-    preferences.isGoogleInternal().setDefaultValue(true);
+    preferences.isGoogleInternal().setDefaultValue(false);
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/core/DirectoryPath.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/core/DirectoryPath.java
index a49a675..f0f9c4a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/core/DirectoryPath.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/core/DirectoryPath.java
@@ -9,11 +9,12 @@
 package com.google.eclipse.protobuf.ui.preferences.paths.core;
 
 import static com.google.eclipse.protobuf.ui.preferences.paths.core.ProjectVariable.replaceProjectVariableWithProjectName;
+import static com.google.eclipse.protobuf.ui.util.IPaths.directoryLocationInWorkspace;
 
 import java.util.regex.*;
 
 import org.eclipse.core.filesystem.*;
-import org.eclipse.core.resources.*;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.*;
 
 /**
@@ -75,20 +76,14 @@
    * @return the absolute path in the local file system, or {@code null} if no path can be determined.
    */
   public String absolutePathInFileSystem() {
-    Path path = new Path(value);
+    IPath path = new Path(value);
     if (isWorkspacePath()) {
-      return locationOfWorkspaceDirectory(path);
+      return directoryLocationInWorkspace(path);
     }
-    return locationOfFileSystemDirectory(path);
+    return locationInFileSystem(path);
   }
 
-  private String locationOfWorkspaceDirectory(Path path) {
-    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
-    IFolder directory = root.getFolder(path);
-    return directory.getLocation().toOSString();
-  }
-
-  private String locationOfFileSystemDirectory(Path path) {
+  private String locationInFileSystem(IPath path) {
     IFileSystem fileSystem = EFS.getLocalFileSystem();
     IFileInfo fileInfo = fileSystem.getStore(path).fetchInfo();
     if (!fileInfo.isDirectory()) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/DirectorySelectionDialogs.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/DirectorySelectionDialogs.java
index 8969934..662d065 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/DirectorySelectionDialogs.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/DirectorySelectionDialogs.java
@@ -10,6 +10,7 @@
 
 import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
 import static com.google.eclipse.protobuf.ui.preferences.paths.page.Messages.*;
+import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
 import static org.eclipse.core.runtime.IStatus.ERROR;
 import static org.eclipse.core.runtime.Status.OK_STATUS;
 import static org.eclipse.jface.window.Window.OK;
@@ -77,9 +78,5 @@
     return dialog.open();
   }
 
-  private static IWorkspaceRoot workspaceRoot() {
-    return ResourcesPlugin.getWorkspace().getRoot();
-  }
-
   private DirectorySelectionDialogs() {}
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption.java
new file mode 100644
index 0000000..7ff7447
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2012 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.protoc.command;
+
+import static java.io.File.separator;
+import static org.eclipse.core.runtime.IPath.SEPARATOR;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.eclipse.protobuf.ui.preferences.*;
+import com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+abstract class AbstractOutputDirectoryProtocOption implements ProtocOption {
+  private static final NullProgressMonitor NO_MONITOR = new NullProgressMonitor();
+
+  private final String optionName;
+  private final CompilerPreferences preferences;
+  private final IProject project;
+
+  private boolean initialized;
+  private boolean enabled;
+  private IFolder outputDirectory;
+  private String outputDirectoryLocation;
+
+  AbstractOutputDirectoryProtocOption(String optionName, CompilerPreferences preferences, IProject project) {
+    this.optionName = optionName;
+    this.preferences = preferences;
+    this.project = project;
+  }
+
+  @Override public final void addOptionTo(ProtocCommand command) throws CoreException {
+    ensureIsInitialized();
+    if (enabled) {
+      command.appendOption(optionName, outputDirectoryLocation);
+    }
+  }
+
+  final IFolder outputDirectory() throws CoreException {
+    ensureIsInitialized();
+    return outputDirectory;
+  }
+
+  private void ensureIsInitialized() throws CoreException {
+    if (!initialized) {
+      initialize();
+    }
+  }
+
+  private void initialize() throws CoreException {
+    initialized = true;
+    enabled = isEnabled(preferences).getValue();
+    if (enabled) {
+      String directoryName = outputDirectoryName(preferences).getValue();
+      outputDirectory = findOrCreateDirectory(directoryName);
+      outputDirectoryLocation = outputDirectory.getLocation().toOSString();
+    }
+  }
+
+  private IFolder findOrCreateDirectory(String directoryName) throws CoreException {
+    IFolder directory = null;
+    StringBuilder path = new StringBuilder();
+    for (String segment : segmentsOf(directoryName)) {
+      path.append(segment);
+      directory = project.getFolder(path.toString());
+      if (!directory.exists()) {
+        directory.create(true, true, NO_MONITOR);
+      }
+      path.append(SEPARATOR);
+    }
+    return directory;
+  }
+
+  @VisibleForTesting static String[] segmentsOf(String path) {
+    if (path == null) {
+      throw new NullPointerException("The given path should not be null");
+    }
+    return path.split("\\Q" + separator + "\\E");
+  }
+
+  abstract BooleanPreference isEnabled(CompilerPreferences p);
+  abstract StringPreference outputDirectoryName(CompilerPreferences p);
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CppProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CppProtocOption.java
index 2b75808..2541c81 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CppProtocOption.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CppProtocOption.java
@@ -8,55 +8,24 @@
  */
 package com.google.eclipse.protobuf.ui.protoc.command;
 
-import static com.google.eclipse.protobuf.ui.protoc.command.IResources.*;
+import org.eclipse.core.resources.IProject;
 
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
+import com.google.eclipse.protobuf.ui.preferences.*;
 import com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
  */
-class CppProtocOption implements OutputDirectoryProtocOption {
-  private final CompilerPreferences preferences;
-  private final IProject project;
-
-  private boolean initialized;
-  private boolean enabled;
-  private IFolder outputDirectory;
-  private String outputDirectoryLocation;
-
+class CppProtocOption extends AbstractOutputDirectoryProtocOption {
   CppProtocOption(CompilerPreferences preferences, IProject project) {
-    this.preferences = preferences;
-    this.project = project;
+    super("cpp_out", preferences, project);
   }
 
-  @Override public void addOptionTo(ProtocCommand command) throws CoreException {
-    ensureIsInitialized();
-    if (enabled) {
-      command.appendOption("cpp_out", outputDirectoryLocation);
-    }
+  @Override BooleanPreference isEnabled(CompilerPreferences preferences) {
+    return preferences.cppCodeGenerationEnabled();
   }
 
-  @Override public IFolder outputDirectory() throws CoreException {
-    ensureIsInitialized();
-    return outputDirectory;
-  }
-
-  private void ensureIsInitialized() throws CoreException {
-    if (!initialized) {
-      initialize();
-    }
-  }
-
-  private void initialize() throws CoreException {
-    initialized = true;
-    enabled = preferences.cppCodeGenerationEnabled().getValue();
-    if (enabled) {
-      String directoryName = preferences.cppOutputDirectory().getValue();
-      outputDirectory = findOrCreateDirectory(directoryName, project);
-      outputDirectoryLocation = locationOf(outputDirectory);
-    }
+  @Override StringPreference outputDirectoryName(CompilerPreferences preferences) {
+    return preferences.cppOutputDirectory();
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/IResources.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/IResources.java
deleted file mode 100644
index 6e53343..0000000
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/IResources.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2012 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.protoc.command;
-
-import static com.google.eclipse.protobuf.ui.util.Paths.segmentsOf;
-import static org.eclipse.core.runtime.IPath.SEPARATOR;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-final class IResources {
-  private static final NullProgressMonitor NO_MONITOR = new NullProgressMonitor();
-
-  static String locationOf(IFolder directory) {
-    return directory.getLocation().toOSString();
-  }
-
-  static IFolder findOrCreateDirectory(String directoryName, IProject project) throws CoreException {
-    IFolder directory = null;
-    StringBuilder path = new StringBuilder();
-    for (String segment : segmentsOf(directoryName)) {
-      path.append(segment);
-      directory = project.getFolder(path.toString());
-      if (!directory.exists()) {
-        directory.create(true, true, NO_MONITOR);
-      }
-      path.append(SEPARATOR);
-    }
-    return directory;
-  }
-
-  private IResources() {}
-}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java
index e896d16..ad00e08 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java
@@ -67,15 +67,15 @@
   }
 
   private String singleImportRoot(IFile protoFile) {
-    File projectFile = toFile(project);
-    File currentFile = toFile(protoFile);
+    File projectFile = locationAsFileOf(project);
+    File currentFile = locationAsFileOf(protoFile);
     while (!currentFile.getParentFile().equals(projectFile)) {
       currentFile = currentFile.getParentFile();
     }
     return currentFile.toString();
   }
 
-  private File toFile(IResource resource) {
+  private File locationAsFileOf(IResource resource) {
     return resource.getLocation().toFile();
   }
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/JavaProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/JavaProtocOption.java
index 571260f..498c1cd 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/JavaProtocOption.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/JavaProtocOption.java
@@ -8,55 +8,24 @@
  */
 package com.google.eclipse.protobuf.ui.protoc.command;
 
-import static com.google.eclipse.protobuf.ui.protoc.command.IResources.*;
+import org.eclipse.core.resources.IProject;
 
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
+import com.google.eclipse.protobuf.ui.preferences.*;
 import com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
  */
-class JavaProtocOption implements OutputDirectoryProtocOption {
-  private final CompilerPreferences preferences;
-  private final IProject project;
-
-  private boolean initialized;
-  private boolean enabled;
-  private IFolder outputDirectory;
-  private String outputDirectoryLocation;
-
+class JavaProtocOption extends AbstractOutputDirectoryProtocOption {
   JavaProtocOption(CompilerPreferences preferences, IProject project) {
-    this.preferences = preferences;
-    this.project = project;
+    super("java_out", preferences, project);
   }
 
-  @Override public void addOptionTo(ProtocCommand command) throws CoreException {
-    ensureIsInitialized();
-    if (enabled) {
-      command.appendOption("java_out", outputDirectoryLocation);
-    }
+  @Override BooleanPreference isEnabled(CompilerPreferences preferences) {
+    return preferences.javaCodeGenerationEnabled();
   }
 
-  @Override public IFolder outputDirectory() throws CoreException {
-    ensureIsInitialized();
-    return outputDirectory;
-  }
-
-  private void ensureIsInitialized() throws CoreException {
-    if (!initialized) {
-      initialize();
-    }
-  }
-
-  private void initialize() throws CoreException {
-    initialized = true;
-    enabled = preferences.javaCodeGenerationEnabled().getValue();
-    if (enabled) {
-      String directoryName = preferences.javaOutputDirectory().getValue();
-      outputDirectory = findOrCreateDirectory(directoryName, project);
-      outputDirectoryLocation = locationOf(outputDirectory);
-    }
+  @Override StringPreference outputDirectoryName(CompilerPreferences preferences) {
+    return preferences.javaOutputDirectory();
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/OutputDirectoryProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/OutputDirectoryProtocOption.java
deleted file mode 100644
index b8bedd7..0000000
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/OutputDirectoryProtocOption.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2012 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.protoc.command;
-
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-interface OutputDirectoryProtocOption extends ProtocOption {
-  IFolder outputDirectory() throws CoreException;
-}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java
index 713a9c2..0509dca 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java
@@ -65,8 +65,9 @@
   public List<IFolder> outputDirectories() throws CoreException {
     List<IFolder> outputDirectories = newArrayList();
     for (ProtocOption option : options) {
-      if (option instanceof OutputDirectoryProtocOption) {
-        IFolder outputDirectory = ((OutputDirectoryProtocOption) option).outputDirectory();
+      if (option instanceof AbstractOutputDirectoryProtocOption) {
+        AbstractOutputDirectoryProtocOption outputDirectoryProtocOption = (AbstractOutputDirectoryProtocOption) option;
+        IFolder outputDirectory = outputDirectoryProtocOption.outputDirectory();
         if (outputDirectory != null) {
           outputDirectories.add(outputDirectory);
         }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/PythonProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/PythonProtocOption.java
index a8f5390..7da9c74 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/PythonProtocOption.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/PythonProtocOption.java
@@ -8,54 +8,24 @@
  */
 package com.google.eclipse.protobuf.ui.protoc.command;
 
-import static com.google.eclipse.protobuf.ui.protoc.command.IResources.*;
+import org.eclipse.core.resources.IProject;
 
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
+import com.google.eclipse.protobuf.ui.preferences.*;
 import com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
  */
-class PythonProtocOption implements OutputDirectoryProtocOption {
-  private final CompilerPreferences preferences;
-  private final IProject project;
-
-  private boolean initialized;
-  private boolean enabled;
-  private IFolder outputDirectory;
-  private String outputDirectoryLocation;
-
+class PythonProtocOption extends AbstractOutputDirectoryProtocOption {
   PythonProtocOption(CompilerPreferences preferences, IProject project) {
-    this.preferences = preferences;
-    this.project = project;
+    super("python_out", preferences, project);
   }
 
-  @Override public void addOptionTo(ProtocCommand command) throws CoreException {
-    ensureIsInitialized();
-    if (enabled) {
-      command.appendOption("python_out", outputDirectoryLocation);
-    }
+  @Override BooleanPreference isEnabled(CompilerPreferences preferences) {
+    return preferences.pythonCodeGenerationEnabled();
   }
 
-  @Override public IFolder outputDirectory() throws CoreException {
-    ensureIsInitialized();
-    return outputDirectory;
-  }
-
-  private void ensureIsInitialized() throws CoreException {
-    if (!initialized) {
-      initialize();
-    }
-  }
-  private void initialize() throws CoreException {
-    initialized = true;
-    enabled = preferences.pythonCodeGenerationEnabled().getValue();
-    if (enabled) {
-      String directoryName = preferences.pythonOutputDirectory().getValue();
-      outputDirectory = findOrCreateDirectory(directoryName, project);
-      outputDirectoryLocation = locationOf(outputDirectory);
-    }
+  @Override StringPreference outputDirectoryName(CompilerPreferences preferences) {
+    return preferences.pythonOutputDirectory();
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
index ea39979..51f57fc 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
@@ -9,6 +9,7 @@
 package com.google.eclipse.protobuf.ui.scoping;
 
 import static com.google.common.collect.Lists.newArrayList;
+import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
 import static java.util.Collections.*;
 
 import java.util.List;
@@ -84,7 +85,7 @@
 
   private Iterable<PathsPreferences> preferencesFromAllProjects() {
     List<PathsPreferences> allPreferences = newArrayList();
-    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+    IWorkspaceRoot root = workspaceRoot();
     for (IProject project : root.getProjects()) {
       if (project.isHidden() || !project.isAccessible() || !XtextProjectHelper.hasNature(project)) {
         continue;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy.java
index b01f48e..71d6c4c 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolverStrategy.java
@@ -25,7 +25,7 @@
  * @author alruiz@google.com (Alex Ruiz)
  */
 class MultipleDirectoriesFileResolverStrategy implements FileResolverStrategy {
-  @Inject private PathMapping mapping;
+  @Inject private ResourceLocations locations;
   @Inject private Uris uris;
 
   @Override
@@ -53,7 +53,7 @@
       }
     }
     for (String root : unresolvedWorkspacePaths) {
-      String directoryLocation = mapping.directoryLocation(root);
+      String directoryLocation = locations.directoryLocation(root);
       String resolved = resolveUriInFileSystem(importUri, directoryLocation);
       if (resolved != null) {
         return resolved;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java
deleted file mode 100644
index a9bc167..0000000
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.scoping;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.Path;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class PathMapping {
-  String directoryLocation(String workspacePath) {
-    return directory(workspacePath).getLocation().toOSString();
-  }
-
-  private static IFolder directory(String workspacePath) {
-    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
-    return root.getFolder(new Path(workspacePath));
-  }
-}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java
new file mode 100644
index 0000000..b08d423
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java
@@ -0,0 +1,23 @@
+/*
+ * 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.scoping;
+
+import static com.google.eclipse.protobuf.ui.util.IPaths.directoryLocationInWorkspace;
+
+import org.eclipse.core.runtime.*;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class ResourceLocations {
+  String directoryLocation(String workspacePath) {
+    IPath path = new Path(workspacePath);
+    return directoryLocationInWorkspace(path);
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/IPaths.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/IPaths.java
new file mode 100644
index 0000000..3f42b3e
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/IPaths.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012 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 com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * Utility methods related to <code>{@link IPath}</code>s.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public final class IPaths {
+
+  /**
+   * Returns the absolute path in the local file system of a directory in the workspace. The returned value uses the
+   * platform-dependent path separator defined by {@code java.io.File}.
+   * @param path the path of the directory. It can be relative or absolute.
+   * @return the absolute path in the local file system of a directory.
+   */
+  public static String directoryLocationInWorkspace(IPath path) {
+    IFolder directory = workspaceRoot().getFolder(path);
+    return directory.getLocation().toOSString();
+  }
+
+  private IPaths() {}
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
deleted file mode 100644
index 85ca663..0000000
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 java.io.File.separator;
-
-/**
- * Utility methods related to paths.
- *
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class Paths {
-  /**
-   * Returns the segments of the given path.
-   * @param path the given path.
-   * @return the segments of the given path.
-   * @throws NullPointerException if the given path is {@code null}.
-   */
-  public static String[] segmentsOf(String path) {
-    if (path == null) {
-      throw new NullPointerException("The given path should not be null");
-    }
-    return path.split("\\Q" + separator + "\\E");
-  }
-
-  private Paths() {}
-}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java
index f51caee..743fbf6 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java
@@ -9,6 +9,7 @@
 package com.google.eclipse.protobuf.ui.util;
 
 import static com.google.common.collect.Lists.newArrayList;
+import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
 import static java.util.Collections.*;
 
 import java.io.File;
@@ -111,7 +112,7 @@
    * workspace file.
    */
   public IFile referredFile(URI uri) {
-    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+    IWorkspaceRoot root = workspaceRoot();
     IPath path = pathOf(uri);
     return (path != null) ? root.getFile(path) : null;
   }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Workspaces.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Workspaces.java
new file mode 100644
index 0000000..d54a84b
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Workspaces.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2012 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.*;
+
+/**
+ * Utility methods related to workspaces.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public final class Workspaces {
+
+  /**
+   * Returns the root of the workspace.
+   * @return the root of the workspace.
+   */
+  public static IWorkspaceRoot workspaceRoot() {
+    return ResourcesPlugin.getWorkspace().getRoot();
+  }
+
+  private Workspaces() {}
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
index e291d5d..af8d242 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
@@ -31,18 +31,16 @@
   @Inject private ModelObjects modelObjects;
 
   /**
-   * Calculates the index value for the given element. The calculated index value is the maximum of all the
-   * index values of the given element's siblings, plus one. The minimum index value is 1.
+   * Calculates the index value for the given element. The calculated index value is the maximum of all the index values
+   * of the given element's siblings, plus one. The minimum index value is 1.
    * <p>
    * For example, in the following message:
-   *
    * <pre>
    * message Person {
    *   required string name = 1;
    *   optional string email = 2;
    *   optional PhoneNumber phone =
    * </pre>
-   *
    * The calculated index value for the element {@code PhoneNumber} will be 3.
    * </p>
    * @param e the given element.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Literals.java
similarity index 74%
rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
rename to com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Literals.java
index d962ed8..c910a3e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Literals.java
@@ -6,7 +6,7 @@
  *
  * http://www.eclipse.org/legal/epl-v10.html
  */
-package com.google.eclipse.protobuf.ui.util;
+package com.google.eclipse.protobuf.model.util;
 
 import static java.lang.Math.max;
 import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
@@ -23,31 +23,26 @@
  */
 @Singleton public class Literals {
   /**
-   * Calculates the index value for the given literal. The calculated index
-   * value is the maximum of all the index values of the given literal's
-   * siblings, plus one. The minimum index value is zero.
+   * Calculates the index value for the given literal. The calculated index value is the maximum of all the index values
+   * of the given literal's siblings, plus one. The minimum index value is zero.
    * <p>
    * For example, in the following message:
-   *
    * <pre>
    * enum PhoneType {
    *   MOBILE = 0;
    *   HOME = 1;
    *   WORK =
    * </pre>
-   *
    * The calculated index value for the literal {@code WORK} will be 2.
    * </p>
-   *
-   * @param l
-   *          the given literal.
+   * @param literal the given literal.
    * @return the calculated index value.
    */
-  public long calculateNewIndexOf(Literal l) {
+  public long calculateNewIndexOf(Literal literal) {
     long index = -1;
-    List<Literal> allLiterals = getAllContentsOfType(l.eContainer(), Literal.class);
+    List<Literal> allLiterals = getAllContentsOfType(literal.eContainer(), Literal.class);
     for (Literal c : allLiterals) {
-      if (c == l) {
+      if (c == literal) {
         continue;
       }
       index = max(index, c.getIndex());
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/IndexLookup.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/IndexLookup.java
index 65668fd..f1e989e 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/IndexLookup.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/IndexLookup.java
@@ -8,12 +8,13 @@
  */
 package com.google.eclipse.protobuf.resource;
 
+import static com.google.common.base.Objects.equal;
+
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.xtext.resource.*;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.eclipse.protobuf.util.IPaths;
 import com.google.inject.Inject;
 
 /**
@@ -22,7 +23,6 @@
  * @author alruiz@google.com (Alex Ruiz)
  */
 public class IndexLookup {
-  @Inject private IPaths paths;
   @Inject private IResourceDescriptions xtextIndex;
 
   /**
@@ -47,13 +47,24 @@
   private IResourceDescription segmentMatching(IPath path) {
     for (IResourceDescription description : xtextIndex.getAllResourceDescriptions()) {
       URI resourceUri = description.getURI();
-      if (paths.areReferringToSameFile(path, resourceUri)) {
+      if (areReferringToSameFile(path, resourceUri)) {
         return description;
       }
     }
     return null;
   }
 
+  @VisibleForTesting boolean areReferringToSameFile(IPath p, URI u) {
+    int pIndex = p.segmentCount() - 1;
+    int uIndex = u.segmentCount() - 1;
+    while (pIndex >= 0 && uIndex >= 0) {
+      if (!equal(p.segment(pIndex--), u.segment(uIndex--))) {
+        return false;
+      }
+    }
+    return true;
+  }
+
   @VisibleForTesting IResourceDescriptions getXtextIndex() {
     return xtextIndex;
   }
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/IPaths.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/IPaths.java
deleted file mode 100644
index 1b9ac5c..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/IPaths.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2012 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.util;
-
-import static com.google.common.base.Objects.equal;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.emf.common.util.URI;
-
-import com.google.inject.Singleton;
-
-/**
- * Utility methods related to <code>{@link IPath}</code>s.
- *
- * @author alruiz@google.com (Alex Ruiz)
- */
-@Singleton public class IPaths {
-  /**
-   * Indicates whether the given path and URI refer to the same file.
-   * @param p the given path.
-   * @param u the given URI.
-   * @return {@code true} if the given path and URI refer to the same file, {@code false} otherwise.
-   */
-  public boolean areReferringToSameFile(IPath p, URI u) {
-    int pIndex = p.segmentCount() - 1;
-    int uIndex = u.segmentCount() - 1;
-    while (pIndex >= 0 && uIndex >= 0) {
-      if (!equal(p.segment(pIndex--), u.segment(uIndex--))) {
-        return false;
-      }
-    }
-    return true;
-  }
-}