Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorJeff Johnston2017-02-03 23:12:43 +0000
committerJeff Johnston2017-04-18 00:01:27 +0000
commit795a90288b0a1331de1709da640433c6338c090c (patch)
treed986ff3dd730b2525848f10621d1947b8126e58b /codan
parent908a609a53d2a1d171e74b93ad19e7727f891edb (diff)
downloadorg.eclipse.cdt-795a90288b0a1331de1709da640433c6338c090c.tar.gz
org.eclipse.cdt-795a90288b0a1331de1709da640433c6338c090c.tar.xz
org.eclipse.cdt-795a90288b0a1331de1709da640433c6338c090c.zip
Bug 497670 - Support compiler provided "fix-it" hints
- add new FixitErrorParser that extends RegexErrorParser and is used to replace the error parser for GNUCErrorParser - add new FixManager class to bind a fixit message with its problem marker - modify ProblemMarkerFilterManager to register the last accepted ProblemMarkerInfo for a particular resource so the FixitErrorParser can find the last error marker for the file that precedes the fixit message - FixitErrorParser looks for fix-it messages and binds them via FixitManager to the last error marker for the file - add new Fixit class to contain the details of a gcc fix-it - add new QuickFixForFixit which applies the gcc fix-it for the file - add new (.*) regex in codan.ui.checkers patterns that will trigger before any other error and will look for the fix-it message format - change cdt.core to expose cdt.internal.errorparsers to codan.checkers.ui - change codan.core to expose codan.internal.core.model to codan.checkers.ui - fix CDocumentProvider.setOverlay method to not overlay a CMarkerAnnotation that has a quick fix - when deleting all C problem markers, also make a call to FixManager.deleteAllMarkers() so markers aren't left referenced Change-Id: Ibf8ff7d8addb1bf092dc4ef35de0d92de0309589
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml4
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixForFixit.java54
-rw-r--r--codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF7
3 files changed, 61 insertions, 4 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml
index 571d2bee6a..e8e8104b71 100644
--- a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml
@@ -4,6 +4,10 @@
<extension
point="org.eclipse.cdt.codan.ui.codanMarkerResolution">
<resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixForFixit"
+ messagePattern=".*">
+ </resolution>
+ <resolution
class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CatchByReferenceQuickFix"
problemId="org.eclipse.cdt.codan.internal.checkers.CatchByReference">
</resolution>
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixForFixit.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixForFixit.java
new file mode 100644
index 0000000000..ad37b339b9
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixForFixit.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat 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:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
+
+import org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator;
+import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
+import org.eclipse.cdt.internal.errorparsers.Fixit;
+import org.eclipse.cdt.internal.errorparsers.FixitManager;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+public class QuickFixForFixit extends AbstractCodanCMarkerResolution {
+
+ @Override
+ public String getLabel() {
+ return QuickFixMessages.QuickFixForFixit_apply_fixit;
+ }
+
+ @Override
+ public void apply(IMarker marker, IDocument document) {
+ int lineNum = marker.getAttribute(IMarker.LINE_NUMBER, -1);
+ try {
+ if (lineNum >= 0) {
+ Fixit f = FixitManager.getInstance().findFixit(marker);
+ int lineOffset = document.getLineOffset(f.getLineNumber() - 1);
+ int columnOffset = f.getColumnNumber() - 1;
+ try {
+ document.replace(lineOffset + columnOffset, f.getLength(), f.getChange());
+ } catch (BadLocationException e) {
+ return;
+ }
+ }
+ FixitManager.getInstance().deleteMarker(marker);
+ marker.delete();
+ } catch (BadLocationException | CoreException e) {
+ CheckersUiActivator.log(e);
+ }
+ }
+
+ @Override
+ public boolean isApplicable(IMarker marker) {
+ return FixitManager.getInstance().hasFixit(marker);
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
index 2c31a7823a..bf94805afe 100644
--- a/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
@@ -11,9 +11,7 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.cdt.codan.core,
org.eclipse.cdt.codan.core.model,
- org.eclipse.cdt.codan.core.model.cfg;
- x-friends:="org.eclipse.cdt.codan.core.cxx,
- org.eclipse.cdt.codan.checkers",
+ org.eclipse.cdt.codan.core.model.cfg;x-friends:="org.eclipse.cdt.codan.core.cxx,org.eclipse.cdt.codan.checkers",
org.eclipse.cdt.codan.core.param,
org.eclipse.cdt.codan.internal.core;
x-friends:="org.eclipse.cdt.codan.core,
@@ -26,4 +24,5 @@ Export-Package: org.eclipse.cdt.codan.core,
x-friends:="org.eclipse.cdt.codan.core.cxx,
org.eclipse.cdt.codan.core.test,
org.eclipse.cdt.codan.ui,
- org.eclipse.cdt.codan.ui.cxx"
+ org.eclipse.cdt.codan.ui.cxx,
+ org.eclipse.cdt.codan.checkers.ui"

Back to the top