Code cleanup.
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 d32d6d5..53bcd64 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
@@ -40,7 +40,7 @@
@Inject private CompoundElements compoundElements;
@Inject private EObjectFinder finder;
- @Inject private Globals globalScope;
+ @Inject private Globals globals;
@Inject private PluginImageHelper imageHelper;
@Inject private Images imageRegistry;
@Inject private Keywords keywords;
@@ -58,7 +58,7 @@
}
private void proposeCommonFileOptions(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- for (Property fileOption : globalScope.fileOptions()) {
+ for (Property fileOption : globals.fileOptions()) {
String displayString = fileOption.getName();
String proposalText = displayString + " " + keywords.equalSign().getValue() + " ";
boolean isStringOption = properties.isString(fileOption);
@@ -77,10 +77,10 @@
@Override public void completeOption_Value(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
Option option = (Option) model;
- Property fileOption = globalScope.lookupFileOption(option.getName());
+ Property fileOption = globals.lookupFileOption(option.getName());
if (fileOption == null) return;
- if (globalScope.isOptimizeForOption(option)) {
- proposeAndAccept(globalScope.optimizedMode(), context, acceptor);
+ if (globals.isOptimizeForOption(option)) {
+ proposeAndAccept(globals.optimizedMode(), context, acceptor);
return;
}
if (properties.isString(fileOption)) {
@@ -173,7 +173,7 @@
EObject model = context.getCurrentModel();
if (model instanceof Property) return properties.isBool((Property) model);
if (model instanceof Option) {
- Property fileOption = globalScope.lookupFileOption(((Option) model).getName());
+ Property fileOption = globals.lookupFileOption(((Option) model).getName());
return fileOption != null && properties.isBool(fileOption);
}
return false;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java
index e4194a8..9e1030c 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Globals.java
@@ -9,11 +9,12 @@
package com.google.eclipse.protobuf.scoping;
import static java.util.Collections.unmodifiableCollection;
+import static org.eclipse.emf.common.util.URI.createURI;
+import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import java.io.*;
import java.util.*;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parser.IParser;
import org.eclipse.xtext.resource.XtextResource;
@@ -36,14 +37,14 @@
private Protobuf root;
private boolean initialized;
- private Map<String, Property> fileOptions = new LinkedHashMap<String, Property>();
+ private final Map<String, Property> fileOptions = new LinkedHashMap<String, Property>();
private Enum optimizedMode;
@Inject EObjectFinder finder;
@Inject public Globals(IParser parser) {
try {
- XtextResource resource = new XtextResource(URI.createURI(""));
+ XtextResource resource = new XtextResource(createURI("globals.proto"));
IParseResult result = parser.parse(new InputStreamReader(globalScopeContents(), "UTF-8"));
root = (Protobuf) result.getRootASTElement();
resource.getContents().add(root);
@@ -95,12 +96,9 @@
}
private Message fileOptionsMessage() {
- for (ProtobufElement e : root.getElements()) {
- if (!(e instanceof Message)) continue;
- Message m = (Message) e;
+ for (Message m : getAllContentsOfType(root, Message.class))
if ("FileOptions".equals(m.getName())) return m;
- }
- return null;
+ throw new IllegalStateException("Unable to find message 'FileOptions'");
}
private void addFileOption(Property p) {