Fixed: [ Issue 63 ] Group elements can contain nested groups and enums
https://code.google.com/p/protobuf-dt/issues/detail?id=63
diff --git a/com.google.eclipse.protobuf.feature/feature.xml b/com.google.eclipse.protobuf.feature/feature.xml
new file mode 100644
index 0000000..7be8049
--- /dev/null
+++ b/com.google.eclipse.protobuf.feature/feature.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="com.google.eclipse.protobuf"
+ label="Protocol Buffer Editor"
+ version="1.0.1.qualifier"
+ provider-name="Google, Inc.">
+
+ <description url="https://code.google.com/p/protobuf-dt/">
+ An Eclipse-based Development Environment for Protocol Buffers
+ </description>
+
+ <copyright>
+ 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
+
+Contributors:
+Google, Inc. - initial API and implementation
+ </copyright>
+
+ <license url="http://www.eclipse.org/legal/epl-v10.html">
+ 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
+
+Contributors:
+Google, Inc. - initial API and implementation
+ </license>
+
+ <url>
+ <update label="protobuf-dt" url="http://protobuf-dt.googlecode.com/svn/trunk/update-site"/>
+ </url>
+
+ <requires>
+ <import plugin="org.eclipse.xtext"/>
+ <import plugin="org.eclipse.xtext.util"/>
+ <import plugin="org.eclipse.emf.ecore"/>
+ <import plugin="org.eclipse.emf.common"/>
+ <import plugin="org.antlr.runtime"/>
+ <import plugin="org.eclipse.core.runtime" version="3.7.0" match="greaterOrEqual"/>
+ <import plugin="org.apache.log4j"/>
+ <import plugin="org.apache.commons.logging"/>
+ <import plugin="org.eclipse.xtext.ui"/>
+ <import plugin="org.eclipse.ui.editors" version="3.5.0" match="greaterOrEqual"/>
+ <import plugin="org.eclipse.ui.ide" version="3.5.0" match="greaterOrEqual"/>
+ <import plugin="org.eclipse.xtext.ui.shared"/>
+ <import plugin="org.eclipse.ui"/>
+ <import plugin="org.eclipse.xtext.builder"/>
+ <import plugin="com.ibm.icu"/>
+ <import plugin="org.eclipse.emf.databinding"/>
+ <import plugin="org.eclipse.core.resources"/>
+ <import plugin="org.eclipse.core.filesystem" version="1.3.100" match="greaterOrEqual"/>
+ </requires>
+
+ <plugin
+ id="com.google.eclipse.protobuf"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="com.google.eclipse.protobuf.ui"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+</feature>
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
index 11b60a4..8993736 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
@@ -65,18 +65,25 @@
}
if (element instanceof Field) {
highlightName(element, acceptor, highlightId);
- highLightFieldOptionNames((Field) element, acceptor, highlightId);
+ highlightFieldOptionNames((Field) element, acceptor, highlightId);
}
if (element instanceof Group) {
- for (Property property : ((Group) element).getElements()) {
- highlightName(property, acceptor, highlightId);
- highLightFieldOptionNames(property, acceptor, highlightId);
- }
+ highlightElementNames((Group) element, acceptor, highlightId);
}
}
}
- private void highLightFieldOptionNames(Field field, IHighlightedPositionAcceptor acceptor, String highlightId) {
+ private void highlightElementNames(Group group, IHighlightedPositionAcceptor acceptor, String highlightId) {
+ for (GroupElement e : group.getElements()) {
+ if (e instanceof Property) {
+ Field field = (Field) e;
+ highlightName(field, acceptor, highlightId);
+ highlightFieldOptionNames(field, acceptor, highlightId);
+ }
+ }
+ }
+
+ private void highlightFieldOptionNames(Field field, IHighlightedPositionAcceptor acceptor, String highlightId) {
for (FieldOption option : field.getFieldOptions()) {
highlightName(option, acceptor, highlightId);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index d27a97b..3ae2591 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -54,9 +54,13 @@
Group:
modifier=Modifier 'group' name=Name '=' index=INT
('[' (fieldOptions+=FieldOption (',' fieldOptions+=FieldOption)*) ']')? '{'
- elements+=Property*
+ elements+=GroupElement*
'}'(';')?;
+GroupElement:
+ Field | Option | Enum
+;
+
Property:
modifier=Modifier type=AbstractTypeReference name=Name '=' index=INT
(
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
index 9758fe2..0d09afb 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
@@ -17,7 +17,7 @@
import org.eclipse.emf.common.util.*;
import org.eclipse.emf.ecore.*;
-import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.*;
import org.eclipse.xtext.naming.*;
import org.eclipse.xtext.resource.*;
import org.eclipse.xtext.scoping.IScope;
@@ -105,9 +105,9 @@
Package importRootPackage = finder.packageOf(root);
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
for (Import anImport : imports) {
- XtextResource imported = importedResource(anImport);
- EObject importedRoot = imported.getParseResult().getRootASTElement();
- if (arePackagesRelated(importRootPackage, importedRoot)) {
+ Resource imported = importedResource(anImport);
+ EObject importedRoot = rootElementOf(imported);
+ if (importedRoot != null && arePackagesRelated(importRootPackage, importedRoot)) {
descriptions.addAll(typesIn(importedRoot));
continue;
}
@@ -116,18 +116,33 @@
return descriptions;
}
- private XtextResource importedResource(Import anImport) {
+ private Resource importedResource(Import anImport) {
ResourceSet resourceSet = finder.rootOf(anImport).eResource().getResourceSet();
URI importUri = createURI(uriResolver.apply(anImport));
- return (XtextResource) resourceSet.getResource(importUri, true);
+ try {
+ return resourceSet.getResource(importUri, true);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return null;
+ }
}
+ private /* Protobuf */ EObject rootElementOf(Resource resource) {
+ if (resource instanceof XtextResource) return ((XtextResource) resource).getParseResult().getRootASTElement();
+ TreeIterator<Object> contents = getAllContents(resource, true);
+ if (contents.hasNext()) {
+ Object next = contents.next();
+ if (next instanceof EObject) return (EObject) next;
+ }
+ return null;
+ }
+
private boolean arePackagesRelated(Package aPackage, EObject root) {
Package p = finder.packageOf(root);
return packageResolver.areRelated(aPackage, p);
}
- private <T extends Type> Collection<IEObjectDescription> children(XtextResource resource, Class<T> targetType) {
+ private <T extends Type> Collection<IEObjectDescription> children(Resource resource, Class<T> targetType) {
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
TreeIterator<Object> contents = getAllContents(resource, true);
while (contents.hasNext()) {