Exemplo n.º 1
0
  private void compileSource(
      org.nlogo.api.JobOwner owner, List<org.nlogo.window.Events.CompiledEvent> errorEvents) {
    try {
      CompilerResults results =
          workspace
              .compiler()
              .compileMoreCode(
                  owner.source(),
                  scala.Some.apply(owner.classDisplayName() + " '" + owner.displayName() + "'"),
                  workspace.world.program(),
                  workspace.getProcedures(),
                  workspace.getExtensionManager());

      if (!results.procedures().isEmpty()) {
        results.head().init(workspace);
        results.head().setOwner(owner);
        new org.nlogo.window.Events.CompiledEvent(
                owner, workspace.world.program(), results.head(), null)
            .raise(this);
      }
    } catch (CompilerException error) {
      errorEvents.add(
          new org.nlogo.window.Events.CompiledEvent(owner, workspace.world.program(), null, error));
    }
  }
Exemplo n.º 2
0
 public void handle(org.nlogo.window.Events.CompileMoreSourceEvent e) {
   JobOwner owner = e.owner;
   if (isLoading) {
     widgets.add(owner);
     return;
   }
   if (owner.isCommandCenter()) {
     try {
       CompilerResults results =
           workspace
               .compiler()
               .compileMoreCode(
                   owner.source(),
                   scala.Some.apply(owner.classDisplayName()),
                   workspace.world.program(),
                   workspace.getProcedures(),
                   workspace.getExtensionManager());
       results.head().init(workspace);
       results.head().setOwner(owner);
       new org.nlogo.window.Events.CompiledEvent(
               owner, workspace.world.program(), results.head(), null)
           .raise(this);
     } catch (CompilerException error) {
       new org.nlogo.window.Events.CompiledEvent(owner, workspace.world.program(), null, error)
           .raise(this);
     }
   } else {
     compileWidgets();
   }
 }
Exemplo n.º 3
0
 private boolean compileProcedures() {
   workspace.world.program(workspace.world.newProgram());
   try {
     CompilerResults results =
         workspace
             .compiler()
             .compileProgram(
                 proceduresInterface.innerSource(),
                 workspace.world.newProgram(getGlobalVariableNames()),
                 workspace.getExtensionManager());
     workspace.setProcedures(results.proceduresMap());
     for (Procedure procedure : workspace.getProcedures().values()) {
       if (procedure.fileName.equals("")) {
         procedure.setOwner(proceduresInterface);
       } else if (procedure.fileName.equals("aggregate")) {
         procedure.setOwner(workspace.aggregateManager());
       } else {
         procedure.setOwner(new ExternalFileInterface(procedure.fileName));
       }
     }
     workspace.init();
     workspace.world.program(results.program());
     new org.nlogo.window.Events.CompiledEvent(proceduresInterface, results.program(), null, null)
         .raise(this);
     return true;
   } catch (CompilerException error) {
     if (AbstractWorkspace.isApplet()) {
       System.err.println("CompilerException: " + error);
       error.printStackTrace();
       new org.nlogo.window.Events.CompiledEvent(proceduresInterface, null, null, error)
           .raise(this);
     }
     if (error.fileName().equals("")) {
       new org.nlogo.window.Events.CompiledEvent(proceduresInterface, null, null, error)
           .raise(this);
     } else if (error.fileName().equals("aggregate")) {
       new org.nlogo.window.Events.CompiledEvent(workspace.aggregateManager(), null, null, error)
           .raise(this);
     } else {
       new org.nlogo.window.Events.CompiledEvent(
               new ExternalFileInterface(error.fileName()), null, null, error)
           .raise(this);
     }
     return false;
   }
 }