コード例 #1
0
ファイル: Main.java プロジェクト: Hdzi/emacs
  private void commandLoad(Options options) {
    LoadResult result;
    Project project = codeAssist.getProject(options);
    try {
      progressMonitor.attach(project);
      if (options.isFileStdin()) {
        result = codeAssist.load(project, new File("(stdin)"), options.getHereDocReader(inReader));
      } else {
        result = codeAssist.load(project, options.getFile(), options.getEncoding());
      }

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

      if (options.isEmacsFormat()) {
        out.print("(");
        codeAssistError(result, options);
        out.println(")");
      } else {
        codeAssistError(result, options);
      }
    } catch (Exception e) {
      commandException(e, options);
    } finally {
      progressMonitor.detach(project);
    }
  }
コード例 #2
0
ファイル: Main.java プロジェクト: Hdzi/emacs
  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);
    }
  }
コード例 #3
0
ファイル: Main.java プロジェクト: Hdzi/emacs
  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);
    }
  }
コード例 #4
0
ファイル: Main.java プロジェクト: Hdzi/emacs
  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);
    }
  }
コード例 #5
0
ファイル: Main.java プロジェクト: Hdzi/emacs
  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);
    }
  }