Package org.jnode.driver.console

Examples of org.jnode.driver.console.CompletionInfo


            if (url.getProtocol().equals("file") &&
                    (url.getAuthority() == null || url.getAuthority().length() == 0) &&
                    (url.getQuery() == null || url.getQuery().length() == 0)) {
                // Use a FileArgument to do the work of completing the pathname,
                // capturing the results using our own CompletionInfo object.
                CompletionInfo myCompletion = new CommandCompletions();
                new FileArgument(null, getFlags()).complete(myCompletion, url.getPath(), flags);
                // Then turn the completions back into "file:" URLs
                for (String c : myCompletion.getCompletions()) {
                    // (Kludge - the 'true' argument prevents an extra space
                    // character from being appended to the completions.)
                    completions.addCompletion("file:" + c, true);
                }
            }
View Full Code Here


        }
    }

    @Test
    public void testGetCompletion() {
        CompletionInfo ci = new CommandCompletions();
        Assert.assertEquals(null, ci.getCompletion());

        ci.addCompletion("full-1");
        Assert.assertEquals("full-1 ", ci.getCompletion());

        ci.addCompletion("full-2");
        Assert.assertEquals("full-", ci.getCompletion());

        ci.addCompletion("partial", true);
        Assert.assertEquals(null, ci.getCompletion());
    }
View Full Code Here

     * @param completer the object (e.g. shell) responsible for completion.
     * @return <code>true</code> if we output a list of completion alternatives.
     * @throws IOException
     */
    public boolean complete(InputCompleter completer) throws IOException {
        CompletionInfo info = null;
        String ending =
            posOnCurrentLine != currentLine.length() ? currentLine.substring(posOnCurrentLine) : "";
        info = completer.complete(currentLine.substring(0, posOnCurrentLine));
        boolean res = printList(info);
        String completion = info.getCompletion();
        if (completion != null) {
            int startPos = info.getCompletionStart();
            if (startPos == -1) {
                setContent(currentLine.substring(0, posOnCurrentLine) + completion + ending);
            } else {
                setContent(currentLine.substring(0, startPos) + completion + ending);
            }
View Full Code Here

        }
    }

    public static void checkCompletions(TestCommandShell cs, String line, String[] expected, int startPos) {
        cs.setReadingCommand(true);
        CompletionInfo ci = cs.complete(line);
        SortedSet<String> completions = ci.getCompletions();
        if (completions.size() != expected.length) {
            err("Wrong number of completions", expected, completions);
        }
        int i = 0;
        for (String completion : completions) {
            if (!completion.equals(expected[i])) {
                err("Mismatch for completion #" + i, expected, completions);
            }
            i++;
        }
        if (startPos == -1) {
            assert (startPos == ci.getCompletionStart() ||
                line.length() == ci.getCompletionStart());
        } else {
            TestCase.assertEquals(startPos, ci.getCompletionStart());
        }
    }
View Full Code Here

        new CommandCompletions();
    }

    @Test
    public void testAddCompletion() {
        CompletionInfo ci = new CommandCompletions();

        ci.addCompletion("full-1");
        ci.addCompletion("full-2", false);
        ci.addCompletion("partial", true);
        SortedSet<String> completions = ci.getCompletions();
        Assert.assertEquals(3, completions.size());

        Iterator<String> it = completions.iterator();
        Assert.assertEquals("full-1 ", it.next());
        Assert.assertEquals("full-2 ", it.next());
View Full Code Here

        Assert.assertEquals("partial", it.next());
    }

    @Test
    public void testSetCompletionStart() {
        CompletionInfo ci = new CommandCompletions();
        Assert.assertEquals(-1, ci.getCompletionStart());
        ci.setCompletionStart(-1);
        Assert.assertEquals(-1, ci.getCompletionStart());
        ci.setCompletionStart(1);
        Assert.assertEquals(1, ci.getCompletionStart());
        ci.setCompletionStart(1);
        Assert.assertEquals(1, ci.getCompletionStart());
        try {
            ci.setCompletionStart(2);
            Assert.fail("no exception");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

            errPW.println("Problem in completer: " + ex.getMessage());
            stackTrace(ex);
        }  

        // Make sure that the shell's completion context gets nulled.
        CompletionInfo myCompletion = completion;
        completion = null;
        return myCompletion;
    }
View Full Code Here

TOP

Related Classes of org.jnode.driver.console.CompletionInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.