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;
|
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.eclipse.ui.plugin.AbstractUIPlugin;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
|
@ -46,5 +48,35 @@ public class CheckersUiActivator extends AbstractUIPlugin {
|
||||||
public static CheckersUiActivator getDefault() {
|
public static CheckersUiActivator getDefault() {
|
||||||
return plugin;
|
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;
|
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.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -62,20 +63,26 @@ public class QuickFixAssignmentInCondition implements IMarkerResolution {
|
||||||
ITextEditor editor = (ITextEditor) editorPart;
|
ITextEditor editor = (ITextEditor) editorPart;
|
||||||
IDocument doc = editor.getDocumentProvider().getDocument(
|
IDocument doc = editor.getDocumentProvider().getDocument(
|
||||||
editor.getEditorInput());
|
editor.getEditorInput());
|
||||||
int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1;
|
|
||||||
FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter(doc);
|
|
||||||
try {
|
try {
|
||||||
dad.find(doc.getLineOffset(line), "=", /* forwardSearch */ //$NON-NLS-1$
|
int charStart = marker.getAttribute(IMarker.CHAR_START, -1);
|
||||||
true, /* caseSensitive */false,
|
int position;
|
||||||
/* wholeWord */false, /* regExSearch */false);
|
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$
|
dad.replace("==", /* regExReplace */false); //$NON-NLS-1$
|
||||||
marker.delete();
|
marker.delete();
|
||||||
} catch (BadLocationException e) {
|
|
||||||
// TODO: log the error
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
// TODO: log the error
|
CheckersUiActivator.log(e);
|
||||||
e.printStackTrace();
|
} catch (BadLocationException e) {
|
||||||
|
CheckersUiActivator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue