use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame in project linuxtools by eclipse.
the class LinkedResourceDoubleClickTest method doDoubleClick.
private void doDoubleClick() {
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
CoreMessagesViewer viewer = view.getMessagesViewer();
// get first leaf
IValgrindMessage[] elements = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
IValgrindMessage element = elements[0];
TreePath path = new TreePath(new Object[] { element });
frame = null;
while (element.getChildren().length > 0) {
element = element.getChildren()[0];
path = path.createChildPath(element);
if (element instanceof ValgrindStackFrame) {
frame = (ValgrindStackFrame) element;
}
}
assertNotNull(frame);
viewer.getTreeViewer().expandToLevel(frame, AbstractTreeViewer.ALL_LEVELS);
TreeSelection selection = new TreeSelection(path);
// do double click
IDoubleClickListener listener = viewer.getDoubleClickListener();
listener.doubleClick(new DoubleClickEvent(viewer.getTreeViewer(), selection));
}
use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame in project linuxtools by eclipse.
the class LinkedResourceMarkerTest method findMarker.
private void findMarker(ArrayList<IMarker> markers, IValgrindMessage error) throws Exception, CoreException {
ValgrindStackFrame frame = null;
IValgrindMessage[] children = error.getChildren();
for (int i = 0; i < children.length; i++) {
if (frame == null && children[i] instanceof ValgrindStackFrame && isWorkspaceFrame((ValgrindStackFrame) children[i])) {
frame = (ValgrindStackFrame) children[i];
} else if (children[i] instanceof ValgrindError) {
findMarker(markers, children[i]);
}
}
int ix = -1;
for (int i = 0; i < markers.size(); i++) {
IMarker marker = markers.get(i);
if (marker.getAttribute(IMarker.MESSAGE).equals(error.getText()) && marker.getResource().getName().equals(frame.getFile()) && marker.getAttribute(IMarker.LINE_NUMBER).equals(frame.getLine())) {
ix = i;
}
}
assertFalse(ix < 0);
markers.remove(ix);
}
use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame in project linuxtools by eclipse.
the class WrongDeallocationResolution method getAllocFunction.
/**
* Returns the allocation function that relates to the given marker
* @param marker {@link IMarker} object that points to where the wrong de-allocation function is
* @return {@link String} object containing the allocation function
* @throws BadLocationException
*/
private String getAllocFunction(IMarker marker, IDocument document) throws BadLocationException {
IValgrindMessage allocMessage = null;
String file = marker.getResource().getName();
int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
// $NON-NLS-1$
IValgrindMessage[] wrongDeallocMessages = getMessagesByText(Messages.getString("ValgrindMemcheckQuickFixes.Wrong_dealloc_message"));
for (IValgrindMessage wrongDeallocMessage : wrongDeallocMessages) {
ValgrindStackFrame stackBottom = getStackBottom(wrongDeallocMessage);
int stackBottomLine = stackBottom.getLine();
String stackBottomFile = stackBottom.getFile();
if (stackBottomLine == line && file != null && stackBottomFile.endsWith(file)) {
allocMessage = getStackBottom(getNestedStack(wrongDeallocMessage));
}
}
if (allocMessage instanceof ValgrindStackFrame) {
int allocLine = ((ValgrindStackFrame) allocMessage).getLine() - 1;
int allocOffset = document.getLineOffset(allocLine);
int allocLength = document.getLineLength(allocLine);
return document.get(allocOffset, allocLength);
}
return null;
}
use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame in project linuxtools by eclipse.
the class WrongDeallocationResolution method apply.
@Override
public void apply(IMarker marker, IDocument document) {
try {
IASTNode astNode = getIASTNode(marker, document);
if (astNode != null) {
int nodeLength = astNode.getFileLocation().getNodeLength();
int nodeOffset = astNode.getFileLocation().getNodeOffset();
String content = document.get(nodeOffset, nodeLength);
if (content.contains(DELETE)) {
String allocFunction = getAllocFunction(marker, document);
if (allocFunction.contains(NEW)) {
// $NON-NLS-1$
content = document.get(nodeOffset, nodeLength).replace(DELETE, DELETE + "[]");
document.replace(nodeOffset, nodeLength, content);
} else {
addParentheses(astNode, document);
if (content.contains("[")) {
// $NON-NLS-1$
removeBrackets(astNode, document);
}
content = document.get(nodeOffset, nodeLength).replace(DELETE, FREE);
document.replace(nodeOffset, nodeLength, content);
}
} else if (content.contains(FREE)) {
if (getAllocFunction(marker, document).contains("[")) {
// $NON-NLS-1$
// $NON-NLS-1$
content = content.concat("[]");
}
content = content.replace(FREE, DELETE);
document.replace(nodeOffset, nodeLength, content);
}
IValgrindMessage message = getMessage(marker);
removeMessage(message.getParent());
ValgrindStackFrame nestedStackFrame = getStackBottom(getNestedStack(message.getParent()));
int nestedLine = nestedStackFrame.getLine();
String nestedFile = nestedStackFrame.getFile();
removeMarker(nestedFile, nestedLine, marker.getType());
marker.delete();
}
} catch (BadLocationException | CoreException e) {
Status status = new Status(IStatus.ERROR, ValgrindUIPlugin.PLUGIN_ID, null, e);
// $NON-NLS-1$
String title = Messages.getString("ValgrindMemcheckQuickFixes.Valgrind_error_title");
// $NON-NLS-1$
String message = Messages.getString("ValgrindMemcheckQuickFixes.Error_applying_quickfix");
showErrorMessage(title, message, status);
}
}
use of org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame in project linuxtools by eclipse.
the class WrongDeallocationResolution method getStackBottom.
/**
* Return the last nested element from a given {@link IValgrindMessage}, or null if there are
* no nested messages.
* @param message
* @return The {@link ValgrindStackFrame} in the bottom of the nested stack
*/
private ValgrindStackFrame getStackBottom(IValgrindMessage message) {
ValgrindStackFrame stackBottom = null;
IValgrindMessage[] children = message.getChildren();
for (IValgrindMessage child : children) {
if (child instanceof ValgrindStackFrame) {
stackBottom = (ValgrindStackFrame) child;
}
}
return stackBottom;
}
Aggregations