Пример #1
0
 private AbstractPSystem executeOneLine(
     AbstractPSystem sys, UmlSource source, final IteratorCounter2 it) {
   final CommandControl commandControl = isValid2(it);
   if (commandControl == CommandControl.NOT_OK) {
     final ErrorUml err =
         new ErrorUml(
             ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", it.currentNum(), it.peek().getLocation());
     if (OptionFlags.getInstance().isUseSuggestEngine()) {
       final SuggestEngine engine = new SuggestEngine(source, this);
       final SuggestEngineResult result = engine.tryToSuggest(sys);
       if (result.getStatus() == SuggestEngineStatus.ONE_SUGGESTION) {
         err.setSuggest(result);
       }
     }
     sys = new PSystemError(source, err, null);
   } else if (commandControl == CommandControl.OK_PARTIAL) {
     final IteratorCounter2 saved = it.cloneMe();
     final CommandExecutionResult result = manageMultiline2(it, sys);
     if (result.isOk() == false) {
       sys =
           new PSystemError(
               source,
               new ErrorUml(
                   ErrorUmlType.EXECUTION_ERROR,
                   result.getError(),
                   it.currentNum() - 1,
                   saved.next().getLocation()),
               null);
     }
   } else if (commandControl == CommandControl.OK) {
     final CharSequence line = it.next();
     final BlocLines lines = BlocLines.single(line);
     Command cmd = getFirstCommandOkForLines(lines);
     final CommandExecutionResult result = sys.executeCommand(cmd, lines);
     if (result.isOk() == false) {
       sys =
           new PSystemError(
               source,
               new ErrorUml(
                   ErrorUmlType.EXECUTION_ERROR,
                   result.getError(),
                   it.currentNum() - 1,
                   ((CharSequence2) line).getLocation()),
               result.getDebugLines());
     }
     if (result.getNewDiagram() != null) {
       sys = result.getNewDiagram();
     }
   } else {
     assert false;
   }
   return sys;
 }
Пример #2
0
  public final Diagram createSystem(UmlSource source) {
    final IteratorCounter2 it = source.iterator2();
    final CharSequence2 startLine = it.next();
    if (StartUtils.isArobaseStartDiagram(startLine) == false) {
      throw new UnsupportedOperationException();
    }

    if (source.isEmpty()) {
      return buildEmptyError(source, startLine.getLocation());
    }
    AbstractPSystem sys = createEmptyDiagram();

    while (it.hasNext()) {
      if (StartUtils.isArobaseEndDiagram(it.peek())) {
        if (sys == null) {
          return null;
        }
        final String err = sys.checkFinalError();
        if (err != null) {
          return buildEmptyError(source, err, it.peek().getLocation());
        }
        if (source.getTotalLineCount() == 2) {
          return buildEmptyError(source, it.peek().getLocation());
        }
        sys.makeDiagramReady();
        if (sys.isOk() == false) {
          return null;
        }
        sys.setSource(source);
        return sys;
      }
      sys = executeOneLine(sys, source, it);
      if (sys instanceof PSystemError) {
        return sys;
      }
    }
    sys.setSource(source);
    return sys;
  }