Set default value of index in Literals to -1, using post-processing.
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ExtendedGenerator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ExtendedGenerator.java
new file mode 100644
index 0000000..ccd8037
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ExtendedGenerator.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import com.google.inject.*;
+
+import org.eclipse.xtext.*;
+import org.eclipse.xtext.generator.Generator;
+import org.eclipse.xtext.xtext.ecoreInference.IXtext2EcorePostProcessor;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+@SuppressWarnings("restriction")
+public class ExtendedGenerator extends Generator {
+ public ExtendedGenerator() {
+ new XtextStandaloneSetup() {
+ @Override public Injector createInjector() {
+ return Guice.createInjector(new XtextRuntimeModule() {
+ @Override public Class<? extends IXtext2EcorePostProcessor> bindIXtext2EcorePostProcessor() {
+ return ProtobufEcorePostProcessor.class;
+ }
+ });
+ }
+ }.createInjectorAndDoEMFRegistration();
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2 b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2
index 9ce04ae..8fec3c7 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2
@@ -32,7 +32,7 @@
directory = "${runtimeProject}.ui/src-gen"
}
- component = Generator {
+ component = ExtendedGenerator {
pathRtProject = runtimeProject
pathUiProject = "${runtimeProject}.ui"
projectNameRt = projectName
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufEcorePostProcessor.xtend b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufEcorePostProcessor.xtend
new file mode 100644
index 0000000..9a53214
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufEcorePostProcessor.xtend
@@ -0,0 +1,40 @@
+/*
+ * 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
+
+import org.eclipse.xtext.xtext.ecoreInference.IXtext2EcorePostProcessor
+import org.eclipse.xtext.GeneratedMetamodel
+import org.eclipse.emf.ecore.EPackage
+import org.eclipse.emf.ecore.EClass
+
+/*
+ * Author: alruiz@google.com (Alex Ruiz)
+ */
+class ProtobufEcorePostProcessor implements IXtext2EcorePostProcessor {
+ override process(GeneratedMetamodel metamodel) {
+ metamodel.EPackage.process;
+ }
+
+ def process(EPackage p) {
+ for (c : p.EClassifiers.filter(typeof(EClass))) {
+ if (c.name == "Literal") {
+ c.setDefaultValueOfLiteralIndex
+ }
+ }
+ }
+
+ def setDefaultValueOfLiteralIndex(EClass c) {
+ for (attribute : c.EAllAttributes) {
+ if (attribute.name == "index") {
+ attribute.defaultValue = -1
+ return
+ }
+ }
+ }
+}
\ No newline at end of file