Fixed: [ Issue 95 ] Add ability to view descriptor.proto in an editor.

Fixed hyperlinking in descriptor.proto.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java
index ec8697d..2fad391 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java
@@ -22,9 +22,9 @@
   private final URI fileUri;
   private final String name;
 
-  public UriEditorInput(URI fileUri, String name) {
+  public UriEditorInput(URI fileUri) {
     this.fileUri = fileUri.trimFragment();
-    this.name = name;
+    name = this.fileUri.segment(this.fileUri.segmentCount() - 1);
   }
 
   @SuppressWarnings("rawtypes")
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
index c8146ab..ed7d6ec 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
@@ -10,28 +10,18 @@
 
 import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
 import static com.google.eclipse.protobuf.util.Closeables.close;
-import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
-import static java.util.Collections.singletonMap;
 import static org.eclipse.core.runtime.IStatus.ERROR;
-import static org.eclipse.emf.common.util.URI.createURI;
-import static org.eclipse.emf.ecore.resource.ContentHandler.UNSPECIFIED_CONTENT_TYPE;
-import static org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences;
-import static org.eclipse.xtext.resource.XtextResource.OPTION_ENCODING;
-import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
 
 import java.io.*;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.ide.FileStoreEditorInput;
 import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.ui.editor.model.XtextDocument;
-import org.eclipse.xtext.ui.resource.IResourceSetProvider;
-import org.eclipse.xtext.util.StringInputStream;
 
-import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.eclipse.protobuf.ui.resource.XtextResourceFactory;
 import com.google.inject.Inject;
 
 /**
@@ -39,10 +29,9 @@
  */
 class FileStoreDocumentContentsFactory implements DocumentContentsFactory {
 
-  @Inject private IResourceSetProvider resourceSetProvider;
-  @Inject private Resources resources;
-  @Inject private Files files;
   @Inject private ContentReader contentReader;
+  @Inject private UriEditorInputs files;
+  @Inject private XtextResourceFactory resourceFactory;
 
   public void createContents(XtextDocument document, Object element) throws CoreException {
     FileStoreEditorInput input = supportedEditorInputType().cast(element);
@@ -50,7 +39,7 @@
     try {
       String contents = contentsOf(file);
       document.set(contents);
-      XtextResource resource = createResource(file.toURI().toString(), new StringInputStream(contents));
+      XtextResource resource = resourceFactory.createResource(file.toURI().toString(), contents);
       document.setInput(resource);
     } catch (Throwable t) {
       String message = t.getMessage();
@@ -69,18 +58,6 @@
     }
   }
 
-  private XtextResource createResource(String uri, InputStream input) {
-    ResourceSet resourceSet = resourceSetProvider.get(resources.activeProject());
-    XtextResource resource = (XtextResource) resourceSet.createResource(createURI(uri), UNSPECIFIED_CONTENT_TYPE);
-    try {
-      resource.load(input, singletonMap(OPTION_ENCODING, UTF_8));
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-    resolveLazyCrossReferences(resource, NullImpl);
-    return resource;
-  }
-
   public boolean supportsEditorInputType(IEditorInput input) {
     return supportedEditorInputType().isInstance(input);
   }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
index 027d3b3..1e9a52e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
@@ -20,11 +20,11 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.ui.editor.model.XtextDocument;
 
-import com.google.eclipse.protobuf.scoping.ProtoDescriptor;
-import com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider;
 import com.google.eclipse.protobuf.ui.editor.UriEditorInput;
+import com.google.eclipse.protobuf.ui.resource.XtextResourceFactory;
 import com.google.inject.Inject;
 
 /**
@@ -32,20 +32,17 @@
  */
 class UriDocumentContentsFactory implements DocumentContentsFactory {
 
-  @Inject private ProtoDescriptorProvider descriptorProvider;
   @Inject private ContentReader contentReader;
+  @Inject private XtextResourceFactory resourceFactory;
 
   public void createContents(XtextDocument document, Object element) throws CoreException {
     UriEditorInput input = supportedEditorInputType().cast(element);
-    URI uri = input.getFileUri().trimFragment();
-    if (!descriptorProvider.descriptorLocation().equals(uri)) {
-      throw new UnsupportedOperationException("File to open is not descriptor.proto");
-    }
-    ProtoDescriptor descriptor = descriptorProvider.get();
+    URI uri = input.getFileUri();
     try {
       String contents = contentsOf(uri);
       document.set(contents);
-      document.setInput(descriptor.resource());
+      XtextResource resource = resourceFactory.createResource(uri, contents);
+      document.setInput(resource);
     } catch (Throwable t) {
       String message = t.getMessage();
       if (message == null) message = "";
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/Files.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriEditorInputs.java
similarity index 97%
rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/Files.java
rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriEditorInputs.java
index 48252ce..905de36 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/Files.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriEditorInputs.java
@@ -21,7 +21,7 @@
  * @author alruiz@google.com (Alex Ruiz)
  */
 @Singleton
-class Files {
+class UriEditorInputs {
 
   File fileFrom(IURIEditorInput input) {
     URI uri = input.getURI();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java
new file mode 100644
index 0000000..584e464
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java
@@ -0,0 +1,67 @@
+/*
+ * 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.resource;
+
+import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
+import static java.util.Collections.singletonMap;
+import static org.eclipse.emf.common.util.URI.createURI;
+import static org.eclipse.emf.ecore.resource.ContentHandler.UNSPECIFIED_CONTENT_TYPE;
+import static org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences;
+import static org.eclipse.xtext.resource.XtextResource.OPTION_ENCODING;
+import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
+
+import java.io.IOException;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.resource.IResourceSetProvider;
+import org.eclipse.xtext.util.StringInputStream;
+
+import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Factory of <code>{@link XtextResource}</code>s.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+@Singleton
+public class XtextResourceFactory {
+
+  @Inject private IResourceSetProvider resourceSetProvider;
+  @Inject private Resources resources;
+
+  /**
+   * Creates a new <code>{@link XtextResource}</code>.
+   * @param uri the URI of the file containing the EMF model.
+   * @param contents the contents of the file.
+   * @return the created {@code XtextResource}.
+   * @throws IOException if something goes wrong.
+   */
+  public XtextResource createResource(String uri, String contents) throws IOException {
+    return createResource(createURI(uri), contents);
+  }
+
+  /**
+   * Creates a new <code>{@link XtextResource}</code>.
+   * @param uri the URI of the file containing the EMF model.
+   * @param contents the contents of the file.
+   * @return the created {@code XtextResource}.
+   * @throws IOException if something goes wrong.
+   */
+  public XtextResource createResource(URI uri, String contents) throws IOException {
+    ResourceSet resourceSet = resourceSetProvider.get(resources.activeProject());
+    XtextResource resource = (XtextResource) resourceSet.createResource(uri, UNSPECIFIED_CONTENT_TYPE);
+    resource.load(new StringInputStream(contents), singletonMap(OPTION_ENCODING, UTF_8));
+    resolveLazyCrossReferences(resource, NullImpl);
+    return resource;
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
index 99a7eb8..966017a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
@@ -93,7 +93,7 @@
   }
 
   public IEditorPart openProtoFileInPlugin(URI uri) throws PartInitException {
-    IEditorInput editorInput = new UriEditorInput(uri, "descriptor.proto");
+    IEditorInput editorInput = new UriEditorInput(uri);
     return openFile(editorInput);
   }
 
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
index a27e34a..fae683b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
@@ -22,7 +22,8 @@
 
 import com.google.eclipse.protobuf.protobuf.*;
 import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.util.*;
+import com.google.eclipse.protobuf.util.FieldOptions;
+import com.google.eclipse.protobuf.util.Properties;
 import com.google.inject.Inject;
 
 /**
@@ -33,7 +34,6 @@
   @Inject private FieldOptions fieldOptions;
   @Inject private ImportUriResolver uriResolver;
   @Inject private IQualifiedNameProvider qualifiedNameProvider;
-  @Inject private Imports imports;
   @Inject private Properties properties;
 
   @Check public void checkDefaultValueType(FieldOption option) {