Search in sources :

Example 1 with ValgrindStackFrame

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));
}
Also used : ValgrindViewPart(org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CoreMessagesViewer(org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer)

Example 2 with ValgrindStackFrame

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);
}
Also used : ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IMarker(org.eclipse.core.resources.IMarker)

Example 3 with ValgrindStackFrame

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;
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)

Example 4 with ValgrindStackFrame

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);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) CoreException(org.eclipse.core.runtime.CoreException) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with ValgrindStackFrame

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;
}
Also used : IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)

Aggregations

ValgrindStackFrame (org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)10 IValgrindMessage (org.eclipse.linuxtools.valgrind.core.IValgrindMessage)10 IMarker (org.eclipse.core.resources.IMarker)3 ValgrindError (org.eclipse.linuxtools.internal.valgrind.core.ValgrindError)3 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 TreePath (org.eclipse.jface.viewers.TreePath)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 CoreMessagesViewer (org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer)2 ValgrindViewPart (org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart)2 URI (java.net.URI)1 Stack (java.util.Stack)1 IASTNode (org.eclipse.cdt.core.dom.ast.IASTNode)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1