Cleaned up code that parses and reports errors. Added check for property tag numbers to be greater than zero.
diff --git a/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties b/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
index b699865..6feb38a 100644
--- a/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
+++ b/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
@@ -16,4 +16,6 @@
command.tooltip.0 = Open Quick Outline
command.description.1 = Insert semicolon.
command.name.1 = Insert semicolon
-command.tooltip.1 = Insert semicolon
\ No newline at end of file
+command.tooltip.1 = Insert semicolon
+protoc.marker.name = Protocol Buffer Compiler
+protoq.marker.name = Protocol Buffer (Quick Check)
\ No newline at end of file
diff --git a/com.google.eclipse.protobuf.ui/build.properties b/com.google.eclipse.protobuf.ui/build.properties
index 0d2ea5b..0ffd4f4 100644
--- a/com.google.eclipse.protobuf.ui/build.properties
+++ b/com.google.eclipse.protobuf.ui/build.properties
@@ -4,4 +4,5 @@
.,\
plugin.xml,\
OSGI-INF/,\
- icons/
+ icons/,\
+ OSGI-INF/l10n/bundle.properties
diff --git a/com.google.eclipse.protobuf.ui/plugin.xml b/com.google.eclipse.protobuf.ui/plugin.xml
index fd013cb..133a7c3 100644
--- a/com.google.eclipse.protobuf.ui/plugin.xml
+++ b/com.google.eclipse.protobuf.ui/plugin.xml
@@ -170,7 +170,7 @@
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.builder.ProtobufBuildParticipant">
</participant>
</extension>
- <extension id="pbmarker" name="Protocol Buffer Marker" point="org.eclipse.core.resources.markers">
+ <extension id="protocMarker" name="%protoc.marker.name" point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.problemmarker">
</super>
<super type="org.eclipse.core.resources.textmarker">
@@ -178,7 +178,7 @@
<persistent value="true">
</persistent>
</extension>
-
+
<!-- Rename Refactoring -->
<extension point="org.eclipse.ui.handlers">
<handler
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
index ad2fe4a..fe1066b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
@@ -39,7 +39,7 @@
private static Logger logger = Logger.getLogger(ProtobufBuildParticipant.class);
@Inject private IPreferenceStoreAccess preferenceStoreAccess;
- @Inject private MarkerFactory markerFactory;
+ @Inject private ProtocOutputParser outputParser;
@Inject private ProtocCommandFactory commandFactory;
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
@@ -80,7 +80,7 @@
private void generateSingleProto(IFile source, String protocPath, TargetLanguage language, String outputFolderPath) {
String command = commandFactory.protocCommand(source, protocPath, language, outputFolderPath);
try {
- source.deleteMarkers(MarkerFactory.MARKER_ID, true, DEPTH_INFINITE);
+ source.deleteMarkers(ProtocOutputParser.MARKER_ID, true, DEPTH_INFINITE);
Process process = Runtime.getRuntime().exec(command);
processStream(process.getErrorStream(), source);
process.destroy();
@@ -96,8 +96,9 @@
reader = new InputStreamReader(stream);
BufferedReader bufferedReader = new BufferedReader(reader);
String line = null;
+ ProtocMarkerFactory markerFactory = new ProtocMarkerFactory(source);
while ((line = bufferedReader.readLine()) != null) {
- markerFactory.parseAndCreateMarkerIfNecessary(line, source);
+ outputParser.parseAndAddMarkerIfNecessary(line, markerFactory);
System.out.println("[protoc] " + line);
}
} catch (Exception e) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java
new file mode 100644
index 0000000..f67be7c
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.builder;
+
+import static org.eclipse.core.resources.IMarker.*;
+import static org.eclipse.core.resources.IResource.DEPTH_INFINITE;
+import static org.eclipse.xtext.ui.MarkerTypes.FAST_VALIDATION;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Factory of <code>{@link IMarker}</code>s derived from errors reported by protoc.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class ProtocMarkerFactory {
+
+ static final String MARKER_ID = "com.google.eclipse.protobuf.ui.protocMarker";
+
+ private final IFile file;
+ private final IMarker[] markers;
+
+ ProtocMarkerFactory(IFile file) throws CoreException {
+ this.file = file;
+ markers = this.file.findMarkers(FAST_VALIDATION, true, DEPTH_INFINITE);
+ }
+
+ void createErrorIfNecessary(String description, int lineNumber) throws CoreException {
+ if (containsMarker(description, lineNumber)) return;
+ IMarker marker = file.createMarker(MARKER_ID);
+ marker.setAttribute(SEVERITY, SEVERITY_ERROR);
+ marker.setAttribute(MESSAGE, description);
+ marker.setAttribute(LINE_NUMBER, lineNumber);
+ }
+
+ private boolean containsMarker(String description, int lineNumber) throws CoreException {
+ for (IMarker marker : markers)
+ if (marker.getAttribute(MESSAGE).equals(description) && marker.getAttribute(LINE_NUMBER).equals(lineNumber))
+ return true;
+ return false;
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/MarkerFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java
similarity index 63%
rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/MarkerFactory.java
rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java
index 7a850b5..8ce8bc5 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/MarkerFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java
@@ -9,23 +9,20 @@
package com.google.eclipse.protobuf.ui.builder;
import static java.lang.Integer.parseInt;
-import static org.eclipse.core.resources.IMarker.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
/**
- * Parses the output of protoc and create error markers if necessary.
+ * Parses the output of protoc.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-class MarkerFactory {
+class ProtocOutputParser {
- static final String MARKER_ID = "com.google.eclipse.protobuf.ui.pbmarker";
+ static final String MARKER_ID = "com.google.eclipse.protobuf.ui.protocMarker";
/*
* (.*):(\\d+):(\\d+):\\s*(.*)
@@ -39,18 +36,11 @@
*/
private static final Pattern ERROR_PATTERN = Pattern.compile("(.*):(\\d+):(\\d+):\\s*(.*)");
- void parseAndCreateMarkerIfNecessary(String line, IFile file) throws CoreException {
- parseError(line, file);
- }
-
- private void parseError(String line, IFile file) throws CoreException {
+ void parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
Matcher errorMatcher = ERROR_PATTERN.matcher(line);
if (!errorMatcher.matches()) return;
int lineNumber = parseInt(errorMatcher.group(2));
String description = errorMatcher.group(4);
- IMarker marker = file.createMarker(MARKER_ID);
- marker.setAttribute(SEVERITY, SEVERITY_ERROR);
- marker.setAttribute(MESSAGE, description);
- marker.setAttribute(LINE_NUMBER, lineNumber);
+ markerFactory.createErrorIfNecessary(description, lineNumber);
}
}