Fixed: [Issue 6] Remove Xtext's own markers.
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java
new file mode 100644
index 0000000..ea86f95
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java
@@ -0,0 +1,55 @@
+/*
+ * 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.validation;
+
+import static com.google.eclipse.protobuf.ui.validation.ProtobufResourceUIValidatorExtension.EDITOR_CHECK;
+import static java.util.Arrays.asList;
+import static org.mockito.Mockito.*;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.*;
+import org.eclipse.xtext.ui.editor.validation.MarkerCreator;
+import org.eclipse.xtext.validation.Issue;
+import org.junit.*;
+
+import java.util.List;
+
+/**
+ * Tests for <code>{@link ProtobufResourceUIValidatorExtension#createMarkers(IFile, List, IProgressMonitor)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufResourceUIValidatorExtension_createMarkers_Test {
+
+ private static IFile file;
+ private static List<Issue> issues;
+ private static IProgressMonitor monitor;
+
+ @BeforeClass public static void setUpOnce() {
+ file = mock(IFile.class);
+ issues = asList(mock(Issue.class), mock(Issue.class));
+ monitor = mock(IProgressMonitor.class);
+ }
+
+ private MarkerCreator markerCreator;
+ private ProtobufResourceUIValidatorExtension validator;
+
+ @Before public void setUp() {
+ markerCreator = mock(MarkerCreator.class);
+ validator = new ProtobufResourceUIValidatorExtension();
+ validator.markerCreator = markerCreator;
+ }
+
+ @Test public void should_create_markers_using_proto_editor_marker_type() throws CoreException {
+ validator.createMarkers(file, issues, monitor);
+ for (Issue issue : issues) {
+ verify(markerCreator).createMarker(issue, file, EDITOR_CHECK);
+ }
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java
new file mode 100644
index 0000000..44a40a1
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java
@@ -0,0 +1,54 @@
+/*
+ * 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.validation;
+
+import static com.google.eclipse.protobuf.ui.validation.ProtobufResourceUIValidatorExtension.EDITOR_CHECK;
+import static org.eclipse.core.resources.IResource.DEPTH_ZERO;
+import static org.eclipse.xtext.ui.MarkerTypes.*;
+import static org.mockito.Mockito.*;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.*;
+import org.eclipse.xtext.validation.CheckMode;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProtobufResourceUIValidatorExtension#deleteMarkers(IFile, CheckMode, IProgressMonitor)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufResourceUIValidatorExtension_deleteMarkers_Test {
+
+ private static CheckMode checkMode;
+ private static IProgressMonitor monitor;
+
+ @BeforeClass public static void setUpOnce() {
+ checkMode = mock(CheckMode.class);
+ monitor = mock(IProgressMonitor.class);
+ }
+
+ private IFile file;
+ private ProtobufResourceUIValidatorExtension validator;
+
+ @Before public void setUp() {
+ file = mock(IFile.class);
+ validator = new ProtobufResourceUIValidatorExtension();
+ }
+
+ @Test public void should_delete_all_xtext_and_protocol_buffer_editor_markers() throws CoreException {
+ validator.deleteMarkers(file, checkMode, monitor);
+ verifyDeletionOfMarkers(FAST_VALIDATION, NORMAL_VALIDATION, EDITOR_CHECK);
+ }
+
+ private void verifyDeletionOfMarkers(String...markerTypes) throws CoreException {
+ for (String markerType : markerTypes) {
+ verify(file).deleteMarkers(markerType, true, DEPTH_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 b0aca08..c4df5f0 100644
--- a/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
+++ b/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
@@ -21,4 +21,4 @@
command.name.1 = Insert semicolon
command.tooltip.1 = Insert semicolon
protoc.marker.name = Protocol Buffer Compiler
-protoq.marker.name = Protocol Buffer (Quick Check)
\ No newline at end of file
+editor.marker.name = Protocol Buffer Problem
diff --git a/com.google.eclipse.protobuf.ui/plugin.xml b/com.google.eclipse.protobuf.ui/plugin.xml
index 9e3b2c3..c46e8aa 100644
--- a/com.google.eclipse.protobuf.ui/plugin.xml
+++ b/com.google.eclipse.protobuf.ui/plugin.xml
@@ -262,6 +262,17 @@
<persistent value="true">
</persistent>
</extension>
+ <extension
+ id="editorMarker"
+ name="%editor.marker.name"
+ point="org.eclipse.core.resources.markers">
+ <super type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <super type="org.eclipse.core.resources.textmarker">
+ </super>
+ <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/ProtobufUiModule.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
index ff92c08..9bbaa42 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
@@ -24,6 +24,7 @@
import org.eclipse.xtext.ui.editor.preferences.*;
import org.eclipse.xtext.ui.editor.quickfix.XtextQuickAssistProcessor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.*;
+import org.eclipse.xtext.ui.validation.IResourceUIValidatorExtension;
import com.google.eclipse.protobuf.scoping.IFileUriResolver;
import com.google.eclipse.protobuf.ui.builder.nature.AutoAddNatureEditorCallback;
@@ -44,7 +45,7 @@
import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferenceStoreInitializer;
import com.google.eclipse.protobuf.ui.quickfix.ProtobufQuickAssistProcessor;
import com.google.eclipse.protobuf.ui.scoping.FileUriResolver;
-import com.google.eclipse.protobuf.ui.validation.ValidateOnActivation;
+import com.google.eclipse.protobuf.ui.validation.*;
import com.google.inject.Binder;
/**
@@ -61,47 +62,46 @@
setValidationTrigger(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), plugin);
}
- private void setValidationTrigger(IWorkbenchWindow w, AbstractUIPlugin plugin) {
- if (w == null || !(plugin instanceof ProtobufActivator)) return;
- w.getPartService().addPartListener(new ValidateOnActivation());
- }
-
public Class<? extends IFileUriResolver> bindFileUriResolver() {
return FileUriResolver.class;
}
-
+
public Class<? extends IHighlightingConfiguration> bindHighlightingConfiguration() {
return HighlightingConfiguration.class;
}
-
+
@Override public Class<? extends IContentOutlinePage> bindIContentOutlinePage() {
return ProtobufOutlinePage.class;
}
+
+ public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProvider() {
+ return ProtobufDocumentationProvider.class;
+ }
@Override public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector() {
return ProtobufHyperlinkDetector.class;
}
+ public Class<? extends IPreferenceStoreAccess> bindIPreferenceStoreAccess() {
+ return PreferenceStoreAccess.class;
+ }
+
@Override public Class<? extends IReconciler> bindIReconciler() {
return ProtobufReconciler.class;
}
- @Override public Class<? extends IXtextEditorCallback> bindIXtextEditorCallback() {
- return AutoAddNatureEditorCallback.class;
- }
-
- public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProvider() {
- return ProtobufDocumentationProvider.class;
- }
-
- public Class<? extends IPreferenceStoreAccess> bindIPreferenceStoreAccess() {
- return PreferenceStoreAccess.class;
+ public Class<? extends IResourceUIValidatorExtension> bindIResourceUIValidatorExtension() {
+ return ProtobufResourceUIValidatorExtension.class;
}
public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() {
return ProtobufSemanticHighlightingCalculator.class;
}
+ @Override public Class<? extends IXtextEditorCallback> bindIXtextEditorCallback() {
+ return AutoAddNatureEditorCallback.class;
+ }
+
public Class<? extends XtextDocumentProvider> bindXtextDocumentProvider() {
return ProtobufDocumentProvider.class;
}
@@ -115,7 +115,7 @@
.annotatedWith(named("FileOutsideWorkspaceIconUpdater"))
.to(FileOutsideWorkspaceIconUpdater.class);
}
-
+
@Override public void configureLanguageSpecificURIEditorOpener(Binder binder) {
if (!isWorkbenchRunning())return;
binder.bind(IURIEditorOpener.class)
@@ -130,7 +130,7 @@
configurePreferenceInitializer(binder, "pathsPreferences", PathsPreferenceStoreInitializer.class);
configurePreferenceInitializer(binder, "saveActionsPreferences", SaveActionsPreferenceStoreInitializer.class);
}
-
+
private void configurePreferenceInitializer(Binder binder, String name,
Class<? extends IPreferenceStoreInitializer> initializerType) {
binder.bind(IPreferenceStoreInitializer.class).annotatedWith(named(name)).to(initializerType);
@@ -141,4 +141,9 @@
.annotatedWith(IOutlineContribution.LinkWithEditor.class)
.to(LinkWithEditor.class);
}
+
+ private void setValidationTrigger(IWorkbenchWindow w, AbstractUIPlugin plugin) {
+ if (w == null || !(plugin instanceof ProtobufActivator)) return;
+ w.getPartService().addPartListener(new ValidateOnActivation());
+ }
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java
index 478bfcc..7403a06 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java
@@ -22,21 +22,21 @@
*/
class ProtocMarkerFactory {
- private static final String PROTOC = "com.google.eclipse.protobuf.ui.protocMarker";
+ private static final String PROTOC_CHECK = "com.google.eclipse.protobuf.ui.protocMarker";
private final IFile file;
private final IMarker[] markers;
ProtocMarkerFactory(IFile file) throws CoreException {
this.file = file;
- file.deleteMarkers(PROTOC, true, DEPTH_INFINITE);
+ file.deleteMarkers(PROTOC_CHECK, true, DEPTH_INFINITE);
markers = file.findMarkers(FAST_VALIDATION, true, DEPTH_INFINITE);
}
void createErrorIfNecessary(String fileName, String message, int lineNumber) throws CoreException {
String location = file.getLocation().toOSString();
if (!location.endsWith(fileName) || containsMarker(message, lineNumber)) return;
- IMarker marker = file.createMarker(PROTOC);
+ IMarker marker = file.createMarker(PROTOC_CHECK);
marker.setAttribute(SEVERITY, SEVERITY_ERROR);
marker.setAttribute(MESSAGE, message);
marker.setAttribute(LINE_NUMBER, lineNumber);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension.java
new file mode 100644
index 0000000..18c5e11
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension.java
@@ -0,0 +1,47 @@
+/*
+ * 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.validation;
+
+import static org.eclipse.core.resources.IResource.DEPTH_ZERO;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.inject.Inject;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.*;
+import org.eclipse.xtext.ui.editor.validation.MarkerCreator;
+import org.eclipse.xtext.ui.validation.DefaultResourceUIValidatorExtension;
+import org.eclipse.xtext.validation.*;
+
+import java.util.List;
+
+/**
+ * Creates/deletes markers of type "Protocol Buffer Problem" instead of the default "Xtext Check."
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufResourceUIValidatorExtension extends DefaultResourceUIValidatorExtension {
+
+ static final String EDITOR_CHECK = "com.google.eclipse.protobuf.ui.editorMarker";
+
+ @VisibleForTesting
+ @Inject MarkerCreator markerCreator;
+
+ @Override protected void createMarkers(IFile file, List<Issue> list, IProgressMonitor monitor) throws CoreException {
+ for (Issue issue : list) {
+ markerCreator.createMarker(issue, file, EDITOR_CHECK);
+ }
+ }
+
+ @Override protected void deleteMarkers(IFile file, CheckMode checkMode, IProgressMonitor monitor)
+ throws CoreException {
+ super.deleteMarkers(file, checkMode, monitor);
+ file.deleteMarkers(EDITOR_CHECK, true, DEPTH_ZERO);
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
index 2959fc2..099db1c 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
@@ -25,6 +25,8 @@
import com.google.inject.Inject;
/**
+ * Verifies that imports only refer to "proto2" files.
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ImportValidator extends AbstractDeclarativeValidator {
@@ -34,6 +36,11 @@
@Override public void register(EValidatorRegistrar registrar) {}
+ /**
+ * Verifies that the imports in the given root only refer to "proto2" files. If non-proto2 imports are found, this
+ * validator creates warning markers for such imports.
+ * @param root the root containing the imports to check.
+ */
@Check
public void checkNonProto2Imports(Protobuf root) {
warnIfNonProto2ImportsFound(root.eResource());