Search in sources :

Example 11 with TreeNode

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

the class STPMetadataSingleton method isVariableInProbe.

public boolean isVariableInProbe(String probe, String variable) {
    TreeNode node = getProbeAlias(probe);
    if (node == null) {
        return false;
    }
    for (int i = 0, n = node.getChildCount(); i < n; i++) {
        TreeNode child = node.getChildAt(i);
        String nodeVar = ((ProbevarNodeData) child.getData()).getCompletionText();
        if (nodeVar.equals(variable)) {
            return true;
        }
    }
    return false;
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) ProbevarNodeData(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData)

Example 12 with TreeNode

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

the class STPMetadataSingleton method getMatchingChildren.

private TreeNode[] getMatchingChildren(TreeNode node, String prefix) {
    ArrayList<TreeNode> matches = new ArrayList<>();
    for (int i = 0, n = node.getChildCount(); i < n; i++) {
        TreeNode childNode = node.getChildAt(i);
        String childName;
        if (childNode.getData() instanceof ICompletable) {
            childName = ((ICompletable) childNode.getData()).getCompletionText();
        } else {
            childName = childNode.toString();
        }
        if (childName.startsWith(prefix)) {
            matches.add(childNode);
        }
    }
    return matches.toArray(new TreeNode[0]);
}
Also used : ICompletable(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ICompletable) TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) ArrayList(java.util.ArrayList)

Example 13 with TreeNode

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

the class KernelSourceTreeTest method testBuildKernelTree.

@Test
public void testBuildKernelTree() {
    TreeNode t;
    // Null
    String direct = null;
    String[] excluded = null;
    kst.buildKernelTree(direct, excluded);
    assertNull("Null directory", kst.getTree());
    // Empty string for directory
    direct = "";
    kst.buildKernelTree(direct, excluded);
    assertNull("Empty string directory", kst.getTree());
    // Missing folder
    direct = "/noSuchDirectory/";
    kst.buildKernelTree(direct, excluded);
    assertEquals("Missing directory", 0, kst.getTree().getChildCount());
    // Inaccessible
    direct = "/root/";
    kst.buildKernelTree(direct, excluded);
    assertEquals("Inaccessable directory", 0, kst.getTree().getChildCount());
    // No .c or .h files
    direct = "/bin/";
    kst.buildKernelTree(direct, excluded);
    t = kst.getTree();
    assertEquals("Bin folder item count", 0, t.getChildCount());
    assertTrue("Bin folder name", "bin".equals(t.toString()));
    assertTrue("Bin has file", t.getData() instanceof IFileStore);
    excluded = new String[] { ".git" };
    // No .c or .h files
    direct = "/tmp/";
    kst.buildKernelTree(direct, excluded);
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) IFileStore(org.eclipse.core.filesystem.IFileStore) Test(org.junit.Test)

Example 14 with TreeNode

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

the class TreeNodeTest method testTreeNode.

@Test
public void testTreeNode() {
    String d1 = "One";
    String d2 = "two";
    String s1 = "one";
    TreeNode t1 = new TreeNode(d1, s1, false);
    assertEquals("Create child count", 0, t1.getChildCount());
    assertEquals("Create child string", s1, t1.toString());
    assertEquals("Create child data", d1, t1.getData());
    assertFalse("Create child clickable", t1.isClickable());
    TreeNode t2 = new TreeNode(d2, true);
    assertEquals("Create child count", 0, t2.getChildCount());
    assertTrue("Create child string", t2.toString().equals(d2));
    assertEquals("Create child data", d2, t2.getData());
    assertTrue("Create child clickable", t2.isClickable());
    TreeNode t3 = new TreeNode(null, true);
    assertEquals("Create child count", 0, t3.getChildCount());
    assertEquals("Create child string", null, t3.toString());
    assertEquals("Create child data", null, t3.getData());
    assertTrue("Create child clickable", t3.isClickable());
    TreeNode t4 = new TreeNode(d1, s1, false);
    assertEquals("Create child count", 0, t4.getChildCount());
    assertEquals("Create child string", s1, t4.toString());
    assertEquals("Create child data", d1, t4.getData());
    assertFalse("Create child clickable", t4.isClickable());
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) Test(org.junit.Test)

Example 15 with TreeNode

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

the class TreeNodeTest method testAddAt.

@Test
public void testAddAt() {
    TreeNode test1 = new TreeNode("one", false);
    t.addAt(test1, 0);
    assertEquals("Child added to front", test1, t.getChildAt(0));
    assertEquals("Child correctly added", 3, t.getChildCount());
    TreeNode test2 = new TreeNode("two", false);
    t.addAt(test2, 1);
    assertEquals("Child added to middle", test2, t.getChildAt(1));
    assertEquals("Child correctly added", 4, t.getChildCount());
    TreeNode test3 = new TreeNode("three", false);
    t.addAt(test3, 3);
    assertEquals("Child added to end", test3, t.getChildAt(3));
    assertEquals("Child correctly added", 5, t.getChildCount());
    TreeNode test4 = new TreeNode("four", false);
    t.addAt(test4, 30);
    assertEquals("Child added to end", test4, t.getChildAt(5));
    assertEquals("Child correctly added", 6, t.getChildCount());
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) Test(org.junit.Test)

Aggregations

TreeNode (org.eclipse.linuxtools.systemtap.structures.TreeNode)34 Test (org.junit.Test)15 TreeDefinitionNode (org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)4 Scanner (java.util.Scanner)3 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 ProbevarNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData)3 ArrayList (java.util.ArrayList)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 FuncparamNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData)2 FunctionNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData)2 ProbeNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Matcher (java.util.regex.Matcher)1 IStatus (org.eclipse.core.runtime.IStatus)1