Example #1
0
 public CommandControl isValid2(final IteratorCounter2 it) {
   final BlocLines lines = BlocLines.single(it.peek());
   for (Command cmd : cmds) {
     final CommandControl result = cmd.isValid(lines);
     if (result == CommandControl.OK) {
       return result;
     }
     if (result == CommandControl.OK_PARTIAL && isMultilineCommandOk(it.cloneMe(), cmd) != null) {
       return result;
     }
   }
   return CommandControl.NOT_OK;
 }
Example #2
0
 private BlocLines addOneSingleLineManageEmbedded2(IteratorCounter2 it, BlocLines lines) {
   final CharSequence linetoBeAdded = it.next();
   lines = lines.add2(linetoBeAdded);
   if (StringUtils.trimNoTrace(linetoBeAdded).equals("{{")) {
     while (it.hasNext()) {
       final CharSequence s = it.next();
       lines = lines.add2(s);
       if (StringUtils.trimNoTrace(s).equals("}}")) {
         return lines;
       }
     }
   }
   return lines;
 }
Example #3
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;
 }
Example #4
0
 private CommandExecutionResult manageMultiline2(IteratorCounter2 it, AbstractPSystem system) {
   for (Command cmd : cmds) {
     if (isMultilineCommandOk(it.cloneMe(), cmd) != null) {
       final BlocLines lines = isMultilineCommandOk(it, cmd);
       if (system instanceof NewpagedDiagram) {
         final NewpagedDiagram newpagedDiagram = (NewpagedDiagram) system;
         return cmd.execute(newpagedDiagram.getLastDiagram(), lines);
       }
       return cmd.execute(system, lines);
     }
   }
   return CommandExecutionResult.ok();
 }
Example #5
0
 public CommandControl goForwardMultiline(final IteratorCounter2 it) {
   final BlocLines lines = BlocLines.single(it.peek());
   for (Command cmd : cmds) {
     final CommandControl result = cmd.isValid(lines);
     if (result == CommandControl.OK) {
       throw new IllegalStateException();
     }
     if (result == CommandControl.OK_PARTIAL && isMultilineCommandOk(it, cmd) != null) {
       return result;
     }
   }
   return CommandControl.NOT_OK;
   // throw new IllegalStateException();
 }
Example #6
0
 private BlocLines isMultilineCommandOk(IteratorCounter2 it, Command cmd) {
   BlocLines lines = new BlocLines();
   int nb = 0;
   while (it.hasNext()) {
     lines = addOneSingleLineManageEmbedded2(it, lines);
     final CommandControl result = cmd.isValid(lines);
     if (result == CommandControl.NOT_OK) {
       return null;
     }
     if (result == CommandControl.OK) {
       return lines;
     }
     nb++;
     if (cmd instanceof CommandDecoratorMultine
         && nb > ((CommandDecoratorMultine) cmd).getNbMaxLines()) {
       return null;
     }
   }
   return null;
 }
Example #7
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;
  }