mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
[307414] - fixed quick fix for assignment in condition - used position information
This commit is contained in:
parent
080bcc692d
commit
a9c6b8f9a7
2 changed files with 49 additions and 10 deletions
|
@ -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;
|
||||
|
||||
|
@ -47,4 +49,34 @@ public class CheckersUiActivator extends AbstractUIPlugin {
|
|||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue