Ejemplo n.º 1
0
  public void reparse(Snapshot snapshot, String content) throws ParseException {
    LOG.warning("Thread id " + Thread.currentThread().getId());
    LOG.warning("Parsing document " + (count++));

    this.snapshot = snapshot;

    // mirahParser = new mirah.impl.MirahParser ();
    // mirahParser.parse(snapshot.getText().toString());
    diag = new MirahParseDiagnostics();
    Mirahc compiler = new Mirahc();

    // Project proj = snapshot.getSource().getFileObject().getLookup().lookup(Project.class);
    FileObject src = snapshot.getSource().getFileObject();
    // LOG.warning("Source file is "+src);
    ClassPath compileClassPath = ClassPath.getClassPath(src, ClassPath.COMPILE);
    // LOG.warning("Project directory is "+proj.getProjectDirectory().getName());
    // LOG.warning("Parsing classpath is "+compileClassPath.toString());

    ClassPath buildClassPath = ClassPath.getClassPath(src, ClassPath.EXECUTE);

    // LOG.warning("Execute classapth is "+buildClassPath.toString());

    ClassPath srcClassPath = ClassPath.getClassPath(src, ClassPath.SOURCE);
    // LOG.warning("Src classapth is "+srcClassPath.toString());

    compiler.setDestination(buildClassPath.toString());
    compiler.setDiagnostics(diag);

    List<String> paths = new ArrayList<String>();
    if (!"".equals(srcClassPath.toString())) {
      paths.add(srcClassPath.toString());
    }
    if (!"".equals(buildClassPath.toString())) {
      paths.add(buildClassPath.toString());
    }
    if (!"".equals(compileClassPath.toString())) {
      paths.add(compileClassPath.toString());
    }

    StringBuilder classPath = new StringBuilder();
    for (String path : paths) {
      classPath.append(path);
      classPath.append(File.pathSeparator);
    }

    String cp = ".";
    if (classPath.length() >= 1) {
      cp = classPath.toString().substring(0, classPath.length() - 1);
    }
    compiler.setClasspath(cp);
    DocumentDebugger debugger = new DocumentDebugger();

    compiler.setDebugger(debugger);

    ClassPath bootClassPath = ClassPath.getClassPath(src, ClassPath.BOOT);
    if (!"".equals(bootClassPath.toString())) {
      compiler.setBootClasspath(bootClassPath.toString());
    }
    String srcText = content;

    compiler.addFakeFile(src.getPath(), srcText);

    try {
      compiler.compile(new String[0]);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    LOG.warning("Finished parsing document");

    synchronized (documentDebuggers) {
      LOG.warning("Inside sync documentDebuggers");
      Document doc = snapshot.getSource().getDocument(true);
      LOG.warning("Resolved types " + debugger.resolvedTypes);
      if (debugger.resolvedTypes.size() > 0) {
        debugger.compiler = compiler;
        LOG.warning("NEW DOCUMENT DEBUGGER ADDED");
        documentDebuggers.put(doc, debugger);
        fireOnParse(doc);
      }
    }
  }
Ejemplo n.º 2
0
 public void reparse(Snapshot snapshot) throws ParseException {
   reparse(snapshot, snapshot.getText().toString());
 }