Fixed: [Issue 163] Compiler errors reporting.
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/OptionBasedErrorParser_parseAndAddMarkerIfNecessary_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/OptionBasedErrorParser_parseAndAddMarkerIfNecessary_Test.java
new file mode 100644
index 0000000..0797967
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/OptionBasedErrorParser_parseAndAddMarkerIfNecessary_Test.java
@@ -0,0 +1,42 @@
+/*
+ * 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.protoc;
+
+import static org.mockito.Mockito.*;
+
+import org.eclipse.core.runtime.CoreException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for <code>{@link OptionBasedErrorParser#parseAndAddMarkerIfNecessary(String, ProtocMarkerFactory)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class OptionBasedErrorParser_parseAndAddMarkerIfNecessary_Test {
+ private ProtocMarkerFactory markerFactory;
+ private OptionBasedErrorParser outputParser;
+
+ @Before public void setUp() {
+ markerFactory = mock(ProtocMarkerFactory.class);
+ outputParser = new OptionBasedErrorParser();
+ }
+
+ @Test public void should_not_create_IMarker_if_line_does_not_match_error_pattern() throws CoreException {
+ String line = "Expected field name.";
+ outputParser.parseAndAddMarkerIfNecessary(line, markerFactory);
+ verifyZeroInteractions(markerFactory);
+ }
+
+ @Test public void should_attempt_to_create_IMarker_if_line_matches_error_pattern() throws CoreException {
+ String line = "--java_out: geocoding.proto: geocoding.proto: Cannot generate Java output.";
+ outputParser.parseAndAddMarkerIfNecessary(line, markerFactory);
+ verify(markerFactory).createErrorIfNecessary("geocoding.proto", "Cannot generate Java output.", -1);
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java
index 87ece3d..60e7433 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java
@@ -29,15 +29,15 @@
private static final String PROTOC = "com.google.eclipse.protobuf.ui.protocMarker";
private FileStub file;
- private MarkerStub fastValidationMarker;
+ private MarkerStub marker;
private ProtocMarkerFactory markerFactory;
@Before public void setUp() throws CoreException {
file = new FileStub();
file.setLocation(new Path("home/alex/protos/test1.proto"));
file.createMarker(PROTOC);
- fastValidationMarker = error(EDITOR_CHECK, "Expected field name.", 68);
- file.addMarker(fastValidationMarker);
+ marker = error(EDITOR_CHECK, "Expected field name.", 68);
+ file.addMarker(marker);
markerFactory = new ProtocMarkerFactory(file);
}
@@ -56,8 +56,8 @@
}
@Test public void should_not_create_marker_if_a_similar_one_exists() throws CoreException {
- markerFactory.createErrorIfNecessary("test1.proto", fastValidationMarker.message(),
- fastValidationMarker.lineNumber());
+ markerFactory.createErrorIfNecessary("test1.proto", marker.message(),
+ marker.lineNumber());
assertThat(file.markerCount(PROTOC), equalTo(0));
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java
index b10eca6..c020ca0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java
@@ -10,7 +10,8 @@
import static java.util.regex.Pattern.compile;
-import java.util.regex.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.core.runtime.CoreException;
@@ -19,14 +20,16 @@
*/
class CodeGenerationErrorParser implements ProtocOutputParser {
/*
- * (.*):\\s*(--.*)
- * --1- -*- --2-
+ * (--.*):\\s*(--.*):\\s*(--.*)
+ * --1--- -*- --2--- -*- --3---
*
- * 1: file name
+ * 1: option (e.g. --java_out)
* *: whitespace
- * 2: description
+ * 2: file name
+ * *: whitespace
+ * 3: description
*/
- private static final Pattern ERROR_PATTERN = compile("(.*):\\s*(--.*)");
+ private static final Pattern ERROR_PATTERN = compile("(--.*):\\s*(--.*):\\s*(--.*)");
@Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
@@ -34,7 +37,7 @@
if (!errorMatcher.matches()) {
return false;
}
- markerFactory.createErrorIfNecessary(errorMatcher.group(1), errorMatcher.group(2), -1);
+ markerFactory.createErrorIfNecessary(errorMatcher.group(2), errorMatcher.group(3), -1);
return true;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java
index 133b251..4be2186 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java
@@ -19,7 +19,7 @@
*/
class CompoundParser implements ProtocOutputParser {
private static final List<ProtocOutputParser> PARSERS =
- asList(new LineSpecificErrorParser(), new CodeGenerationErrorParser());
+ asList(new LineSpecificErrorParser(), new CodeGenerationErrorParser(), new OptionBasedErrorParser());
@Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OptionBasedErrorParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OptionBasedErrorParser.java
new file mode 100644
index 0000000..533e784
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OptionBasedErrorParser.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 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.protoc;
+
+import static java.util.regex.Pattern.compile;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class OptionBasedErrorParser implements ProtocOutputParser {
+ /*
+ * (--.*):\\s*(.*):\\s*(.*)
+ * --1--- -*- --2- -*- --3-
+ *
+ * 1: option (e.g. --java_out)
+ * *: whitespace
+ * 2: file name
+ * *: whitespace
+ * 3: description
+ */
+ private static final Pattern ERROR_PATTERN = compile("(--.*):\\s*(.*):\\s*(.*)");
+
+ @Override
+ public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
+ Matcher errorMatcher = ERROR_PATTERN.matcher(line);
+ if (!errorMatcher.matches()) {
+ return false;
+ }
+ markerFactory.createErrorIfNecessary(errorMatcher.group(2), errorMatcher.group(3), -1);
+ return true;
+ }
+}