Package jline

Examples of jline.SimpleCompletor$NoOpFilter


  }

  public static Completor getCommandCompletor () {
    // SimpleCompletor matches against a pre-defined wordlist
    // We start with an empty wordlist and build it up
    SimpleCompletor sc = new SimpleCompletor(new String[0]);

    // We add Hive function names
    // For functions that aren't infix operators, we add an open
    // parenthesis at the end.
    for (String s : FunctionRegistry.getFunctionNames()) {
      if (s.matches("[a-z_]+")) {
        sc.addCandidateString(s + "(");
      } else {
        sc.addCandidateString(s);
      }
    }

    // We add Hive keywords, including lower-cased versions
    for (String s : ParseDriver.getKeywords()) {
      sc.addCandidateString(s);
      sc.addCandidateString(s.toLowerCase());
    }

    // Because we use parentheses in addition to whitespace
    // as a keyword delimiter, we need to define a new ArgumentDelimiter
    // that recognizes parenthesis as a delimiter.
View Full Code Here


  }

  public static Completor[] getCommandCompletor () {
    // SimpleCompletor matches against a pre-defined wordlist
    // We start with an empty wordlist and build it up
    SimpleCompletor sc = new SimpleCompletor(new String[0]);

    // We add Hive function names
    // For functions that aren't infix operators, we add an open
    // parenthesis at the end.
    for (String s : FunctionRegistry.getFunctionNames()) {
      if (s.matches("[a-z_]+")) {
        sc.addCandidateString(s + "(");
      } else {
        sc.addCandidateString(s);
      }
    }

    // We add Hive keywords, including lower-cased versions
    for (String s : HiveParser.getKeywords()) {
      sc.addCandidateString(s);
      sc.addCandidateString(s.toLowerCase());
    }

    // Because we use parentheses in addition to whitespace
    // as a keyword delimiter, we need to define a new ArgumentDelimiter
    // that recognizes parenthesis as a delimiter.
    ArgumentDelimiter delim = new AbstractArgumentDelimiter () {
      @Override
      public boolean isDelimiterChar (String buffer, int pos) {
        char c = buffer.charAt(pos);
        return (Character.isWhitespace(c) || c == '(' || c == ')' ||
          c == '[' || c == ']');
      }
    };

    // The ArgumentCompletor allows us to match multiple tokens
    // in the same line.
    final ArgumentCompletor ac = new ArgumentCompletor(sc, delim);
    // By default ArgumentCompletor is in "strict" mode meaning
    // a token is only auto-completed if all prior tokens
    // match. We don't want that since there are valid tokens
    // that are not in our wordlist (eg. table and column names)
    ac.setStrict(false);

    // ArgumentCompletor always adds a space after a matched token.
    // This is undesirable for function names because a space after
    // the opening parenthesis is unnecessary (and uncommon) in Hive.
    // We stack a custom Completor on top of our ArgumentCompletor
    // to reverse this.
    Completor completor = new Completor () {
      @Override
      public int complete (String buffer, int offset, List completions) {
        List<String> comp = completions;
        int ret = ac.complete(buffer, offset, completions);
        // ConsoleReader will do the substitution if and only if there
        // is exactly one valid completion, so we ignore other cases.
        if (completions.size() == 1) {
          if (comp.get(0).endsWith("( ")) {
            comp.set(0, comp.get(0).trim());
          }
        }
        return ret;
      }
    };

    HiveConf.ConfVars[] confs = HiveConf.ConfVars.values();
    String[] vars = new String[confs.length];
    for (int i = 0; i < vars.length; i++) {
      vars[i] = confs[i].varname;
    }
    SimpleCompletor conf = new SimpleCompletor(vars);
    conf.setDelimiter(".");

    SimpleCompletor set = new SimpleCompletor("set") {
      @Override
      public int complete(String buffer, int cursor, List clist) {
        return buffer != null && buffer.equals("set") ? super.complete(buffer, cursor, clist) : -1;
      }
    };
View Full Code Here

            return;
        }

        final ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
        reader.addCompletor(new FileNameCompletor());
        reader.addCompletor(new SimpleCompletor(CommandManager.keys().toArray(new String[CommandManager.size()])));

        String line;
        while ((line = reader.readLine(PROMPT)) != null) {
            if (EXIT_CMD.equals(line)) {
                break;
View Full Code Here

    for (int i = 0; i < beeLine.commandHandlers.length; i++) {
      String[] cmds = beeLine.commandHandlers[i].getNames();
      for (int j = 0; cmds != null && j < cmds.length; j++) {
        Completor[] comps = beeLine.commandHandlers[i].getParameterCompletors();
        List<Completor> compl = new LinkedList<Completor>();
        compl.add(new SimpleCompletor(BeeLine.COMMAND_PREFIX + cmds[j]));
        compl.addAll(Arrays.asList(comps));
        compl.add(new NullCompletor()); // last param no complete
        completors.add(new ArgumentCompletor(
            compl.toArray(new Completor[0])));
      }
View Full Code Here

  public int complete(String buf, int pos, List cand) {
    if (beeLine.getDatabaseConnection() == null) {
      return -1;
    }
    return new SimpleCompletor(beeLine.getDatabaseConnection().getTableNames(true))
        .complete(buf, pos, cand);
  }
View Full Code Here


  @Override
  public int complete(String buf, int pos, List cand) {
    try {
      return new SimpleCompletor(propertyNames()).complete(buf, pos, cand);
    } catch (Exception e) {
      beeLine.handleException(e);
      return -1;
    }
  }
View Full Code Here

            return;
        }

        final ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
        reader.addCompletor(new FileNameCompletor());
        reader.addCompletor(new SimpleCompletor(CommandManager.keys().toArray(new String[CommandManager.size()])));

        String line;
        while ((line = reader.readLine(PROMPT)) != null) {
            if (EXIT_CMD.equals(line)) {
                break;
View Full Code Here

        try {
            final StreamManager streamManager = new StreamManager(out, err, lineSep);

            final ConsoleReader reader = new ConsoleReader(sin, streamManager.getSout());
            reader.addCompletor(new FileNameCompletor());
            reader.addCompletor(new SimpleCompletor(COMMANDS.keySet().toArray(new String[COMMANDS.size()])));
            // TODO : add completers

            String line;
            final StringBuilder builtWelcome = new StringBuilder("Apache OpenEJB ")
                .append(OpenEjbVersion.get().getVersion())
View Full Code Here

      }
      autoComplete[i++] = "count=";
      autoComplete[i++] = "astoff";
      autoComplete[i++] = "aston";
      completors.add(new SimpleCompletor(autoComplete));
      reader.addCompletor(new ArgumentCompletor(completors));

      String line;
      // we want some more comfort
      File historyFile = new File("history.txt");
View Full Code Here

        autoComplete[i++] = func.getImage() + "(";
      }
      autoComplete[i++] = "count=";
      autoComplete[i++] = "astoff";
      autoComplete[i++] = "aston";
      completors.add(new SimpleCompletor(autoComplete));
      reader.addCompletor(new ArgumentCompletor(completors));

      String line;
      // we want some more comfort
      File historyFile = new File("history.txt");
View Full Code Here

TOP

Related Classes of jline.SimpleCompletor$NoOpFilter

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.