Search in sources :

Example 1 with FunctionNodeData

use of org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData 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 2 with FunctionNodeData

use of org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData in project linuxtools by eclipse.

the class TreeSettingsTest method testStapNodeData.

@Test
public void testStapNodeData() {
    TreeNode temp;
    TreeNode t1 = new TreeNode(new FunctionNodeData("function ftest(x:long)", null), true);
    t1.add(new TreeNode(new FuncparamNodeData("long"), "x", false));
    TreeNode t2 = new TreeNode(new ProbeNodeData("ptest"), true);
    t2.add(new TreeNode(new ProbevarNodeData("x:long"), false));
    TreeSettings.setTrees(t1, t2);
    temp = TreeSettings.getFunctionTree();
    assertTrue("Improper data type - expected FunctionNodeData but was " + temp.getData().getClass().getSimpleName(), temp.getData() instanceof FunctionNodeData);
    assertEquals("Function data not saved", t1.getData().toString(), temp.getData().toString());
    assertEquals("Funcs has children", t1.getChildCount(), temp.getChildCount());
    assertTrue("Improper data type", temp.getChildAt(0).getData() instanceof FuncparamNodeData);
    assertEquals("Function parameter data not saved", t1.getChildAt(0).getData().toString(), temp.getChildAt(0).getData().toString());
    temp = TreeSettings.getProbeTree();
    assertTrue("Improper data type", temp.getData() instanceof ProbeNodeData);
    assertEquals("Probe data not saved", t2.getData().toString(), temp.getData().toString());
    assertEquals("Probs has children", t2.getChildCount(), temp.getChildCount());
    assertTrue("Improper data type", temp.getChildAt(0).getData() instanceof ProbevarNodeData);
    assertEquals("Probe variable data not saved", t2.getChildAt(0).getData().toString(), temp.getChildAt(0).getData().toString());
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) FunctionNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData) FuncparamNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData) ProbeNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData) ProbevarNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData) Test(org.junit.Test)

Example 3 with FunctionNodeData

use of org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData in project linuxtools by eclipse.

the class TestCreateSystemtapScript method prepareTreeSettings.

/**
 * Load custom contents into the Function/Probe views.
 */
private static void prepareTreeSettings() {
    TapsetLibrary.stop();
    try {
        probeDef = File.createTempFile("probeDef", ".stp");
        funcDef = File.createTempFile("funcDef", ".stp");
        probeDef.deleteOnExit();
        funcDef.deleteOnExit();
    } catch (IOException e) {
    }
    // Leave one of the files blank to test token search failures.
    try (PrintWriter writer = new PrintWriter(probeDef)) {
        writer.print("test file\nptest\nlast line\n");
    } catch (FileNotFoundException e) {
    }
    TreeNode testProbNodeParent = new TreeNode(null, false);
    // Have static/alias folders to comply with convention (change this later).
    testProbNodeParent.add(new TreeNode(probeCategoryEmpty, true));
    testProbNodeParent.add(new TreeNode(probeCategoryFull, true));
    TreeNode testProbNodeGroup = new TreeNode(probeGroup, true);
    String innerProbe = "probegroup.inner";
    TreeNode testProbNode = new TreeDefinitionNode(new ProbeNodeData(innerProbe), innerProbe, probeDef.getPath(), true);
    testProbNode.add(new TreeNode(new ProbevarNodeData("s:string"), false));
    testProbNodeGroup.add(testProbNode);
    testProbNodeParent.getChildAt(1).add(testProbNodeGroup);
    TreeNode testProbNode2 = new TreeDefinitionNode(new ProbeNodeData(probeSingleWithoutDef), probeSingleWithoutDef, null, true);
    testProbNodeParent.getChildAt(1).add(testProbNode2);
    TreeNode testFuncNodeParent = new TreeNode(null, false);
    TreeNode testFuncNode = new TreeDefinitionNode(new FunctionNodeData("function ftest(x:long)", null), funcNodeName, funcDef.getPath(), true);
    testFuncNode.add(new TreeNode(new FuncparamNodeData("long"), "x", false));
    testFuncNodeParent.add(testFuncNode);
    TreeSettings.setTrees(testFuncNodeParent, testProbNodeParent);
    TapsetLibrary.readTreeFile();
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) FunctionNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData) TreeDefinitionNode(org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ProbeNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData) FuncparamNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData) ProbevarNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData) PrintWriter(java.io.PrintWriter)

Aggregations

FunctionNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData)3 FuncparamNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData)2 ProbeNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData)2 ProbevarNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData)2 TreeDefinitionNode (org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)2 TreeNode (org.eclipse.linuxtools.systemtap.structures.TreeNode)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Matcher (java.util.regex.Matcher)1 Test (org.junit.Test)1