Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF3
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/plugin.properties6
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml24
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/pom.xml2
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAddSemicolon.java178
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.java5
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.properties7
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixRenameMember.java75
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUseDotOperator.java64
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUsePointer.java64
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/AbstractAstRewriteQuickFix.java2
-rw-r--r--codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF2
-rw-r--r--codan/org.eclipse.cdt.codan.ui/pom.xml2
-rw-r--r--codan/org.eclipse.cdt.codan.ui/schema/codanMarkerResolution.exsd3
14 files changed, 431 insertions, 6 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF
index ae0d4e02558..3f66cd87854 100644
--- a/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.checkers.ui;singleton:=true
-Bundle-Version: 3.2.0.qualifier
+Bundle-Version: 3.2.1.qualifier
Bundle-Activator: org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
@@ -19,6 +19,7 @@ Require-Bundle: org.eclipse.core.resources,
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: %Bundle-Vendor
+Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.codan.internal.checkers.ui;x-internal:=true,
org.eclipse.cdt.codan.internal.checkers.ui.quickfix;x-friends:="org.eclipse.cdt.codan.checkers.ui.test"
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.properties b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.properties
new file mode 100644
index 00000000000..90857c91515
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.properties
@@ -0,0 +1,6 @@
+GCCFixitNoMember.errormsg=\u2018(.*)\u2019 has no member named \u2018(.*)\u2019.*did you mean \u2018(.*)\u2019.*
+GCCFixitMissingSemicolon.errormsg=expected \u2018;\u2019 before \u2018(.*)\u2019.*
+GCCFixitNoPointerOpCPP=request for member \u2018.*\u2019 in \u2018(.*)\u2019, which is of pointer type \u2018.*\u2019.*maybe you meant to use \u2018->\u2019.*
+GCCFixitNoPointerOperator.errormsg=\u2018(.*)\u2019 is a pointer(.*)did you mean to use \u2018->\u2019.*
+GCCFixitInvalidPtrTypeCPP=base operand of \u2018->\u2019 has non-pointer type \u2018(.*)\u2019.*
+GCCFixitInvalidPtrStruct.errormsg=invalid type argument of \u2018->\u2019.*have \u2018struct (.*)\u2019.* \ No newline at end of file
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml
index a0f1d5a77e5..571d2bee6a5 100644
--- a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml
@@ -32,6 +32,30 @@
messagePattern="`(.*)' undeclared \(first use in this function\)">
</resolution>
<resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixRenameMember"
+ messagePattern="%GCCFixitNoMember.errormsg">
+ </resolution>
+ <resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixAddSemicolon"
+ messagePattern="%GCCFixitMissingSemicolon.errormsg">
+ </resolution>
+ <resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixUsePointer"
+ messagePattern="%GCCFixitNoPointerOpCPP">
+ </resolution>
+ <resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixUsePointer"
+ messagePattern="%GCCFixitNoPointerOperator.errormsg">
+ </resolution>
+ <resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixUseDotOperator"
+ messagePattern="%GCCFixitInvalidPtrTypeCPP">
+ </resolution>
+ <resolution
+ class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixUseDotOperator"
+ messagePattern="%GCCFixitInvalidPtrStruct.errormsg">
+ </resolution>
+ <resolution
class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.QuickFixCreateField"
problemId="org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem">
</resolution>
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/pom.xml b/codan/org.eclipse.cdt.codan.checkers.ui/pom.xml
index 85bbb0702e9..42fcea4da60 100644
--- a/codan/org.eclipse.cdt.codan.checkers.ui/pom.xml
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/pom.xml
@@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
- <version>3.2.0-SNAPSHOT</version>
+ <version>3.2.1-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.codan.checkers.ui</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAddSemicolon.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAddSemicolon.java
new file mode 100644
index 00000000000..cff3b481512
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAddSemicolon.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * 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.AbstractAstRewriteQuickFix;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public class QuickFixAddSemicolon extends AbstractAstRewriteQuickFix {
+
+ @Override
+ public String getLabel() {
+ return QuickFixMessages.QuickFixAddSemicolon_add_semicolon;
+ }
+
+ @Override
+ public void modifyAST(IIndex index, IMarker marker) {
+ IASTTranslationUnit ast;
+ try {
+ ITranslationUnit tu = getTranslationUnitViaEditor(marker);
+ ast = tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
+ } catch (CoreException e) {
+ CheckersUiActivator.log(e);
+ return;
+ }
+ IASTNode astNode = null;
+ if (isCodanProblem())
+ return;
+
+ // We need to back up in the file
+
+ // Start by finding the original reported position and line number
+ int lineNum = marker.getAttribute(IMarker.LINE_NUMBER, 0) - 1;
+
+ if (lineNum < 1) {
+ return;
+ }
+
+ IDocument document = getDocument();
+
+ int lineOffset;
+ int lineLength;
+ try {
+ lineOffset = document.getLineOffset(lineNum);
+ lineLength = document.getLineLength(lineNum);
+ } catch (BadLocationException e2) {
+ return;
+ }
+
+ // find the position of the reported token
+ int pos = getOffset(marker, getDocument());
+ String name = null;
+ try {
+ name = getProblemArgument(marker, 0);
+ } catch (Exception e) {
+ return;
+ }
+ if (name == null)
+ return;
+ FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter(getDocument());
+ IRegion region;
+ try {
+ region = dad.find(pos, name,
+ /* forwardSearch */true, /* caseSensitive */true,
+ /* wholeWord */false, /* regExSearch */false);
+ } catch (BadLocationException e) {
+ return;
+ }
+
+ if (region == null)
+ return;
+
+ // now we have the offset
+ int offset = region.getOffset();
+ IASTNode prevNode = null;
+
+ // see if there are previous nodes on same line
+ if (lineOffset < offset) {
+ astNode = getASTFirstContainedNodeFromPosition(ast, lineOffset, lineLength);
+ if (astNode != null) {
+ IASTFileLocation fileLoc = astNode.getFileLocation();
+ if (fileLoc == null)
+ return;
+ int length = lineLength;
+ while (fileLoc.getNodeOffset() < offset) {
+ prevNode = astNode;
+ astNode = getASTFirstContainedNodeFromPosition(ast, fileLoc.getNodeOffset() + fileLoc.getNodeLength(), length);
+ fileLoc = astNode.getFileLocation();
+ if (fileLoc == null)
+ return;
+ length -= fileLoc.getNodeLength();
+ }
+ }
+ }
+
+ // if we didn't find the previous node on the same line, go back a line at a time and find last node on line
+ while (prevNode == null) {
+ lineNum -= 1;
+ if (lineNum < 0)
+ return; // don't bother once we have reached start of file
+ try {
+ lineOffset = document.getLineOffset(lineNum);
+ lineLength = document.getLineLength(lineNum);
+ } catch (BadLocationException e) {
+ return;
+ }
+ int x = lineOffset;
+ int leftover = lineLength;
+ // get a node at a time from line and keep track of last node found
+ while (x < lineOffset + lineLength) {
+ astNode = getASTFirstContainedNodeFromPosition(ast, x, leftover);
+ if (astNode == null)
+ break;
+ prevNode = astNode;
+ IASTFileLocation fileLoc = astNode.getFileLocation();
+ if (fileLoc == null)
+ break;
+ x += fileLoc.getNodeLength();
+ leftover -= fileLoc.getNodeLength();
+ }
+
+ }
+
+ IASTFileLocation location = prevNode.getFileLocation();
+ if (location == null)
+ return;
+ int replacementLoc = location.getNodeOffset() + location.getNodeLength();
+ // in the case of a Problem statement, it might include \n or \r\n as part
+ // of the node, so we must just assume the semi-colon belongs at the end of
+ // the line
+ if (replacementLoc == offset)
+ replacementLoc -= System.lineSeparator().length();
+ try {
+ // insert the semi-colon
+ document.replace(replacementLoc, 0, ";"); //$NON-NLS-1$
+ } catch (BadLocationException e1) {
+ return;
+ }
+
+ try {
+ // remove marker now that has been dealt with
+ marker.delete();
+ } catch (CoreException e) {
+ CheckersUiActivator.log(e);
+ }
+ }
+
+ /**
+ * @param ast
+ * @param charStart
+ * @param length
+ * @return
+ */
+ private IASTNode getASTFirstContainedNodeFromPosition(IASTTranslationUnit ast, final int charStart, final int length) {
+ IASTNode node = ast.getNodeSelector(null).findFirstContainedNode(charStart, length);
+ return node;
+ }
+
+
+}
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.java
index b92a501ec1b..b0fb468cf8c 100644
--- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.java
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.java
@@ -19,6 +19,11 @@ public class QuickFixMessages extends NLS {
public static String QuickFixCreateField_create_field;
public static String QuickFixCreateLocalVariable_create_local_variable;
public static String QuickFixCreateParameter_create_parameter;
+ public static String QuickFixRenameMember_rename_member;
+ public static String QuickFixAddSemicolon_add_semicolon;
+ public static String QuickFixUsePointer_replace_dot;
+ public static String QuickFixUseDotOperator_replace_ptr;
+ public static String QuickFixForFixit_apply_fixit;
static {
NLS.initializeMessages(QuickFixMessages.class.getName(), QuickFixMessages.class);
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.properties b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.properties
index 5d306e0c48b..421fbd9cdc5 100644
--- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.properties
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixMessages.properties
@@ -13,4 +13,9 @@ CaseBreakQuickFixComment_Label=Add suppressing comment
QuickFixCreateClass_CreateNewClass=Create new class
QuickFixCreateField_create_field=Create field
QuickFixCreateLocalVariable_create_local_variable=Create local variable
-QuickFixCreateParameter_create_parameter=Create parameter \ No newline at end of file
+QuickFixCreateParameter_create_parameter=Create parameter
+QuickFixRenameMember_rename_member=Rename to suggested member
+QuickFixAddSemicolon_add_semicolon=Add semicolon
+QuickFixUsePointer_replace_dot=Replace '.' with '->'
+QuickFixUseDotOperator_replace_ptr=Replace '->' with '.'
+QuickFixForFixit_apply_fixit=Apply compiler recommended fix-it \ No newline at end of file
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixRenameMember.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixRenameMember.java
new file mode 100644
index 00000000000..1736a825687
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixRenameMember.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.internal.core.model.CodanProblemMarker;
+import org.eclipse.cdt.codan.ui.AbstractAstRewriteQuickFix;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.INodeFactory;
+import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ltk.core.refactoring.Change;
+
+public class QuickFixRenameMember extends AbstractAstRewriteQuickFix {
+
+ @Override
+ public String getLabel() {
+ return QuickFixMessages.QuickFixRenameMember_rename_member;
+ }
+
+ @Override
+ public void modifyAST(IIndex index, IMarker marker) {
+ IASTTranslationUnit ast;
+ try {
+ ITranslationUnit tu = getTranslationUnitViaEditor(marker);
+ ast = tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
+ } catch (CoreException e) {
+ CheckersUiActivator.log(e);
+ return;
+ }
+ IASTName astName;
+ if (isCodanProblem()) {
+ astName = getASTNameFromMarker(marker, ast);
+ } else {
+ astName = getAstNameFromProblemArgument(marker, ast, 1);
+ }
+ if (astName == null) {
+ return;
+ }
+ ASTRewrite r = ASTRewrite.create(ast);
+ INodeFactory factory = ast.getASTNodeFactory();
+
+ String[] args = CodanProblemMarker.getProblemArguments(marker);
+ if (args == null || args.length < 3)
+ return;
+ IASTName newName = factory.newName(args[2]);
+ r.replace(astName, newName, null);
+ Change c = r.rewriteAST();
+ try {
+ c.perform(new NullProgressMonitor());
+ } catch (CoreException e) {
+ CheckersUiActivator.log(e);
+ return;
+ }
+ try {
+ marker.delete();
+ } catch (CoreException e) {
+ CheckersUiActivator.log(e);
+ }
+ }
+
+}
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUseDotOperator.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUseDotOperator.java
new file mode 100644
index 00000000000..793adf90f4b
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUseDotOperator.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public class QuickFixUseDotOperator extends AbstractCodanCMarkerResolution {
+
+ @Override
+ public String getLabel() {
+ return QuickFixMessages.QuickFixUseDotOperator_replace_ptr;
+ }
+
+ @Override
+ public void apply(IMarker marker, IDocument document) {
+ int lineNum = marker.getAttribute(IMarker.LINE_NUMBER, -1);
+ try {
+ if (lineNum >= 0) {
+ FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter(document);
+ int lineOffset = document.getLineOffset(lineNum - 1);
+ int columnOffset = getColumnOffset(marker);
+ IRegion region;
+ try {
+ region = dad.find(lineOffset + columnOffset, "->", //$NON-NLS-1$
+ /* forwardSearch */true, /* caseSensitive */true,
+ /* wholeWord */true, /* regExSearch */false);
+ document.replace(region.getOffset(), 2, "."); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ return;
+ }
+ }
+ marker.delete();
+ } catch (BadLocationException | CoreException e) {
+ CheckersUiActivator.log(e);
+ }
+ }
+
+ private int getColumnOffset(IMarker marker) {
+ // Get the column offset from the problem.variable attribute which is set for
+ // the generic C/C++ error message in cdt.core.
+ String offset = marker.getAttribute("problem.variable", "1:"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (offset.charAt(offset.length() - 1) == ':') {
+ String strToParse = offset.substring(0, offset.length() - 1);
+ return Integer.parseInt(strToParse) - 1;
+ }
+ return 0;
+ }
+
+}
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUsePointer.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUsePointer.java
new file mode 100644
index 00000000000..bbebab5ed7f
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixUsePointer.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public class QuickFixUsePointer extends AbstractCodanCMarkerResolution {
+
+ @Override
+ public String getLabel() {
+ return QuickFixMessages.QuickFixUsePointer_replace_dot;
+ }
+
+ @Override
+ public void apply(IMarker marker, IDocument document) {
+ int lineNum = marker.getAttribute(IMarker.LINE_NUMBER, -1);
+ try {
+ if (lineNum >= 0) {
+ FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter(document);
+ int lineOffset = document.getLineOffset(lineNum - 1);
+ int columnOffset = getColumnOffset(marker);
+ IRegion region;
+ try {
+ region = dad.find(lineOffset + columnOffset - 1, ".", //$NON-NLS-1$
+ /* forwardSearch */true, /* caseSensitive */true,
+ /* wholeWord */true, /* regExSearch */false);
+ document.replace(region.getOffset(), 1, "->"); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ return;
+ }
+ }
+ marker.delete();
+ } catch (BadLocationException | CoreException e) {
+ CheckersUiActivator.log(e);
+ }
+ }
+
+ private int getColumnOffset(IMarker marker) {
+ // Get the column offset from the problem.variable attribute which is set for
+ // the generic C/C++ error message in cdt.core.
+ String offset = marker.getAttribute("problem.variable", "1:"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (offset.charAt(offset.length() - 1) == ':') {
+ String strToParse = offset.substring(0, offset.length() - 1);
+ return Integer.parseInt(strToParse) - 1;
+ }
+ return 0;
+ }
+
+}
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/AbstractAstRewriteQuickFix.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/AbstractAstRewriteQuickFix.java
index 055241a4d6b..32221605f8c 100644
--- a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/AbstractAstRewriteQuickFix.java
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/AbstractAstRewriteQuickFix.java
@@ -102,5 +102,5 @@ public abstract class AbstractAstRewriteQuickFix extends AbstractCodanCMarkerRes
}
astName = getASTNameFromPositions(ast, region.getOffset(), region.getLength());
return astName;
- }
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
index 1cf05ea963f..547e968c8cb 100644
--- a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.ui; singleton:=true
-Bundle-Version: 3.2.0.qualifier
+Bundle-Version: 3.2.1.qualifier
Bundle-Activator: org.eclipse.cdt.codan.internal.ui.CodanUIActivator
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.cdt.codan.core,
diff --git a/codan/org.eclipse.cdt.codan.ui/pom.xml b/codan/org.eclipse.cdt.codan.ui/pom.xml
index 5c5d6d32a4f..fe87fb744b5 100644
--- a/codan/org.eclipse.cdt.codan.ui/pom.xml
+++ b/codan/org.eclipse.cdt.codan.ui/pom.xml
@@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
- <version>3.2.0-SNAPSHOT</version>
+ <version>3.2.1-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.codan.ui</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/codan/org.eclipse.cdt.codan.ui/schema/codanMarkerResolution.exsd b/codan/org.eclipse.cdt.codan.ui/schema/codanMarkerResolution.exsd
index c9c9ca64135..ed9dbcc0172 100644
--- a/codan/org.eclipse.cdt.codan.ui/schema/codanMarkerResolution.exsd
+++ b/codan/org.eclipse.cdt.codan.ui/schema/codanMarkerResolution.exsd
@@ -80,6 +80,9 @@ If this is not codan problem (for example gcc error), it can be ommitted. Messag
<documentation>
If problem id is not enought to identity the fix messagePattern can be used to apply fix for given message
</documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
</annotation>
</attribute>
</complexType>

Back to the top