Пример #1
0
  private void commandTypeInference(Options options) {
    TypeInferenceResult result;
    Project project = codeAssist.getProject(options);
    try {
      progressMonitor.attach(project);
      if (options.isFileStdin()) {
        result =
            codeAssist.typeInference(
                project,
                new File("(stdin)"),
                options.getHereDocReader(inReader),
                options.getLocation());
      } else {
        result =
            codeAssist.typeInference(
                project, options.getFile(), options.getEncoding(), options.getLocation());
      }

      if (options.isPrintAST()) {
        Logger.debug("AST:\n%s", result.getAST());
      }

      if (options.isTest()) {
        Set<String> data = new HashSet<String>();
        for (IRubyObject klass : result.getTypeSet()) {
          data.add(klass.toString());
        }
        test(options, data);
      } else {
        if (options.isEmacsFormat()) {
          out.print("(");
          out.print("(type");
          for (IRubyObject klass : result.getTypeSet()) {
            out.print(" \"");
            out.print(klass);
            out.print("\"");
          }
          out.println(")");
          codeAssistError(result, options);
          out.println(")");
        } else {
          for (IRubyObject klass : result.getTypeSet()) {
            out.print("type: ");
            out.println(klass);
          }
          codeAssistError(result, options);
        }
      }
    } catch (Exception e) {
      if (options.isTest()) {
        testError(options);
      }
      commandException(e, options);
    } finally {
      progressMonitor.detach(project);
    }
  }
Пример #2
0
  private void commandFindDefinition(Options options) {
    FindDefinitionResult result;
    Project project = codeAssist.getProject(options);
    try {
      progressMonitor.attach(project);
      if (options.isFileStdin()) {
        result =
            codeAssist.findDefinition(
                project,
                new File("(stdin)"),
                options.getHereDocReader(inReader),
                options.getLocation());
      } else {
        result =
            codeAssist.findDefinition(
                project, options.getFile(), options.getEncoding(), options.getLocation());
      }

      if (options.isPrintAST()) {
        Logger.debug("AST:\n%s", result.getAST());
      }

      if (options.isTest()) {
        Set<String> data = new HashSet<String>();
        for (SourceLocation location : result.getLocations()) {
          data.add(location.toString());
        }
        test(options, data);
      } else {
        if (options.isEmacsFormat()) {
          out.print("(");
          out.print("(location");
          for (SourceLocation location : result.getLocations()) {
            if (location.getFile() != null)
              out.printf(" (%s . %d)", emacsStringLiteral(location.getFile()), location.getLine());
          }
          out.println(")");
          codeAssistError(result, options);
          out.println(")");
        } else {
          for (SourceLocation location : result.getLocations()) {
            out.printf("location: %d %s\n", location.getLine(), location.getFile());
          }
          codeAssistError(result, options);
        }
      }
    } catch (Exception e) {
      if (options.isTest()) testError(options);
      commandException(e, options);
    } finally {
      progressMonitor.detach(project);
    }
  }
Пример #3
0
  private void commandWhere(Options options) {
    WhereResult result;
    Project project = codeAssist.getProject(options);
    try {
      progressMonitor.attach(project);
      if (options.isFileStdin()) {
        result =
            codeAssist.where(
                project,
                new File("(stdin)"),
                options.getHereDocReader(inReader),
                options.getLine());
      } else {
        result =
            codeAssist.where(project, options.getFile(), options.getEncoding(), options.getLine());
      }

      if (options.isPrintAST()) {
        Logger.debug("AST:\n%s", result.getAST());
      }

      if (options.isTest()) {
        Set<String> data = new HashSet<String>();
        if (result.getName() != null) data.add(result.getName());
        test(options, data);
      } else {
        if (options.isEmacsFormat()) {
          out.print("(");
          if (result.getName() != null) out.printf("(name . \"%s\")", result.getName());
          codeAssistError(result, options);
          out.println(")");
        } else {
          if (result.getName() != null) {
            out.print("name: ");
            out.println(result.getName());
          }
          codeAssistError(result, options);
        }
      }
    } catch (Exception e) {
      if (options.isTest()) testError(options);
      commandException(e, options);
    } finally {
      progressMonitor.detach(project);
    }
  }
Пример #4
0
 private void command(String command, Options options) {
   long start = System.currentTimeMillis();
   Logger.info("command: %s", command);
   if (options.isTest() && !options.isKeepEnv()) {
     codeAssist.clear();
   }
   if (command.equals("code-completion")) {
     commandCodeCompletion(options);
   } else if (command.equals("type-inference")) {
     commandTypeInference(options);
   } else if (command.equals("find-definition")) {
     commandFindDefinition(options);
   } else if (command.equals("where")) {
     commandWhere(options);
   } else if (command.equals("load")) {
     commandLoad(options);
   } else if (command.equals("script")) {
     script(options);
   } else if (command.equals("clear")) {
     commandClear(options);
   } else if (command.equals("gc")) {
     commandGC(options);
   } else if (command.equals("list-project")) {
     commandListProject(options);
   } else if (command.equals("open-project")) {
     commandOpenProject(options);
   } else if (command.equals("close-project")) {
     commandCloseProject(options);
   } else if (command.equals("environment")) {
     commandEnvironment(options);
   } else if (command.equals("help")) {
     commandHelp(options);
   } else if (command.equals("version")) {
     commandVersion(options);
   } else if (command.length() == 0) {
   } else {
     commandUnknown(command, options);
   }
   if (options.isTime()) {
     Logger.message("%s: %dms", command, (System.currentTimeMillis() - start));
   }
 }
Пример #5
0
  private void commandCodeCompletion(Options options) {
    CodeCompletionResult result;
    Project project = codeAssist.getProject(options);
    try {
      progressMonitor.attach(project);
      if (options.isFileStdin()) {
        result =
            codeAssist.codeCompletion(
                project,
                new File("(stdin)"),
                options.getHereDocReader(inReader),
                options.getLocation());
      } else {
        result =
            codeAssist.codeCompletion(
                project, options.getFile(), options.getEncoding(), options.getLocation());
      }

      if (options.isPrintAST()) {
        Logger.debug("AST:\n%s", result.getAST());
      }

      String prefix = options.getPrefix();
      if (options.isTest()) {
        Set<String> data = new HashSet<String>();
        for (CodeCompletionResult.CompletionCandidate completion : result.getCandidates()) {
          data.add(completion.getCompletion());
        }
        test(options, data);
      } else {
        if (options.isEmacsFormat()) {
          out.print("(");
          out.print("(completion");
          for (CodeCompletionResult.CompletionCandidate completion : result.getCandidates()) {
            if (prefix == null || completion.getCompletion().startsWith(prefix)) {
              out.printf(
                  " (\"%s\" \"%s\" \"%s\" \"%s\")",
                  completion.getCompletion(),
                  completion.getQualifiedName(),
                  completion.getBaseName(),
                  completion.getKind());
            }
          }
          out.println(")");
          codeAssistError(result, options);
          out.println(")");
        } else {
          for (CodeCompletionResult.CompletionCandidate completion : result.getCandidates()) {
            if (prefix == null || completion.getCompletion().startsWith(prefix)) {
              out.printf(
                  "completion: %s %s %s %s\n",
                  completion.getCompletion(),
                  completion.getQualifiedName(),
                  completion.getBaseName(),
                  completion.getKind());
            }
          }
          codeAssistError(result, options);
        }
      }
    } catch (Exception e) {
      if (options.isTest()) {
        testError(options);
      }
      commandException(e, options);
    } finally {
      progressMonitor.detach(project);
    }
  }