Search in sources :

Example 1 with TreeDefinitionNode

use of org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode in project linuxtools by eclipse.

the class TreeSettings method readTree.

/**
 * Opposite action as writeTree. Reconstruct a tree from a previously-saved {@link IMemento}.
 * @param data The {@link IMemento} to read the tree out of.
 * @return The reconstructed {@link TreeNode}.
 */
private static TreeNode readTree(IMemento data) {
    String disp = data.getString(M_DISP);
    String def = data.getString(M_DEFINITON);
    boolean c = data.getBoolean(M_CLICKABLE);
    Object d = StapTreeDataFactory.createObjectFromString(data.getString(M_DATA), data.getString(M_DATATYPE));
    TreeNode parent;
    if (def == null) {
        parent = new TreeNode(d, disp, c);
    } else {
        parent = new TreeDefinitionNode(d, disp, getValueFromString(def), c);
    }
    for (IMemento child : data.getChildren()) {
        parent.add(readTree(child));
    }
    return parent;
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) TreeDefinitionNode(org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode) IMemento(org.eclipse.ui.IMemento)

Example 2 with TreeDefinitionNode

use of org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode in project linuxtools by eclipse.

the class FunctionParser method addFunctionFromScript.

/**
 * Searches the actual contents of a .stp script file for a specific function, and adds
 * @param functionName The name of the function to search for.
 * @param scriptText The contents of the script to search, with its comments removed
 * (Use {@link CommentRemover} on file contents before passing them here, if necessary).
 * @param scriptFilename The name of the script file being searched.
 */
private void addFunctionFromScript(String functionName, String scriptText, String scriptFilename) {
    String regex = MessageFormat.format(FUNC_REGEX, functionName);
    Matcher mScript = Pattern.compile(regex).matcher(scriptText);
    if (mScript.find()) {
        String functionLine = mScript.group();
        String functionType = mScript.group(1);
        // if it's really a void function, or if its return type is just unspecified
        if (functionType == null && isPatternInScriptBlock(scriptText, mScript.end(), P_RETURN)) {
            functionType = UNKNOWN_TYPE;
        }
        TreeDefinitionNode function = new TreeDefinitionNode(new FunctionNodeData(functionLine, functionType), functionName, scriptFilename, true);
        tree.add(function);
        addParamsFromString(mScript.group(2), function);
    }
}
Also used : Matcher(java.util.regex.Matcher) FunctionNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData) TreeDefinitionNode(org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)

Example 3 with TreeDefinitionNode

use of org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode in project linuxtools by eclipse.

the class ProbeParser method delTapsets.

@Override
protected int delTapsets(String[] tapsets, IProgressMonitor monitor) {
    TreeNode aliases = tree.getChildByName(Messages.ProbeParser_aliasProbes);
    // come from removed directories, and remove them from the group.
    for (int i = 0; i < tapsets.length; i++) {
        for (int g = 0, gn = aliases.getChildCount(); g < gn; g++) {
            if (monitor.isCanceled()) {
                return IStatus.CANCEL;
            }
            TreeNode group = aliases.getChildAt(g);
            for (int p = 0, pn = group.getChildCount(); p < pn; p++) {
                String definition = ((TreeDefinitionNode) group.getChildAt(p)).getDefinition();
                if (definition != null && definition.startsWith(tapsets[i])) {
                    group.remove(p--);
                    pn--;
                }
            }
            // If removing the only probe left in a probe group, remove the group.
            if (group.getChildCount() == 0) {
                aliases.remove(g--);
                gn--;
            }
        }
    }
    return IStatus.OK;
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) TreeDefinitionNode(org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)

Example 4 with TreeDefinitionNode

use of org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode in project linuxtools by eclipse.

the class DefinitionHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    TreeDefinitionNode t = getSelection(event);
    if (t == null) {
        return null;
    }
    String filename = t.getDefinition();
    if (filename == null) {
        return null;
    }
    File file = new File(filename);
    OpenFileHandler open = new OpenFileHandler();
    open.executeOnFile(file);
    if (open.isSuccessful() && t.getData() instanceof ISearchableNode) {
        IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        STPEditor editor = (STPEditor) editorPart;
        editor.jumpToLocation(findDefinitionLine((ISearchableNode) t.getData(), editor) + 1, 0);
    }
    return null;
}
Also used : OpenFileHandler(org.eclipse.linuxtools.internal.systemtap.ui.ide.OpenFileHandler) TreeDefinitionNode(org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode) ISearchableNode(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ISearchableNode) STPEditor(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor) IEditorPart(org.eclipse.ui.IEditorPart) File(java.io.File)

Example 5 with TreeDefinitionNode

use of org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode in project linuxtools by eclipse.

the class DefinitionHandler method getSelection.

private TreeDefinitionNode getSelection(ExecutionEvent event) {
    IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
    Object[] selections = selection.toArray();
    return (selections.length == 1 && selections[0] instanceof TreeDefinitionNode) ? (TreeDefinitionNode) selections[0] : null;
}
Also used : TreeDefinitionNode(org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

TreeDefinitionNode (org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)10 TreeNode (org.eclipse.linuxtools.systemtap.structures.TreeNode)4 FunctionNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData)2 IMemento (org.eclipse.ui.IMemento)2 Test (org.junit.Test)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Matcher (java.util.regex.Matcher)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 OpenFileHandler (org.eclipse.linuxtools.internal.systemtap.ui.ide.OpenFileHandler)1 STPEditor (org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor)1 FuncparamNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData)1 ISearchableNode (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ISearchableNode)1 ProbeNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData)1 ProbevarNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData)1 IEditorPart (org.eclipse.ui.IEditorPart)1 Before (org.junit.Before)1