From a9c6b8f9a77668c42b1d685e95dcc4e556ac7e32 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Thu, 8 Apr 2010 01:10:35 +0000 Subject: [PATCH] [307414] - fixed quick fix for assignment in condition - used position information --- .../checkers/ui/CheckersUiActivator.java | 32 +++++++++++++++++++ .../QuickFixAssignmentInCondition.java | 27 ++++++++++------ 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/CheckersUiActivator.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/CheckersUiActivator.java index 3c03dcebff1..8e225f97909 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/CheckersUiActivator.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/CheckersUiActivator.java @@ -1,5 +1,7 @@ package org.eclipse.cdt.codan.internal.checkers.ui; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -46,5 +48,35 @@ public class CheckersUiActivator extends AbstractUIPlugin { public static CheckersUiActivator getDefault() { return plugin; } + + /** + * Logs the specified status with this plug-in's log. + * + * @param status + * status to log + */ + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + + /** + * Logs an internal error with the specified throwable + * + * @param e + * the exception to be logged + */ + public static void log(Throwable e) { + log(new Status(IStatus.ERROR, PLUGIN_ID, 1, "Internal Error", e)); //$NON-NLS-1$ + } + + /** + * Logs an internal error with the specified message. + * + * @param message + * the error message to log + */ + public static void log(String message) { + log(new Status(IStatus.ERROR, PLUGIN_ID, 1, message, null)); + } } diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java index f17010e013a..bae8065bdf0 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; +import org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; @@ -62,20 +63,26 @@ public class QuickFixAssignmentInCondition implements IMarkerResolution { ITextEditor editor = (ITextEditor) editorPart; IDocument doc = editor.getDocumentProvider().getDocument( editor.getEditorInput()); - int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1; - FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter(doc); try { - dad.find(doc.getLineOffset(line), "=", /* forwardSearch */ //$NON-NLS-1$ - true, /* caseSensitive */false, - /* wholeWord */false, /* regExSearch */false); + int charStart = marker.getAttribute(IMarker.CHAR_START, -1); + int position; + if (charStart > 0) { + position = charStart; + } else { + int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1; + position = doc.getLineOffset(line); + } + FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter( + doc); + dad.find(position, "=", /* forwardSearch *///$NON-NLS-1$ + true, /* caseSensitive */false, + /* wholeWord */false, /* regExSearch */false); dad.replace("==", /* regExReplace */false); //$NON-NLS-1$ marker.delete(); - } catch (BadLocationException e) { - // TODO: log the error - e.printStackTrace(); } catch (CoreException e) { - // TODO: log the error - e.printStackTrace(); + CheckersUiActivator.log(e); + } catch (BadLocationException e) { + CheckersUiActivator.log(e); } } }