예제 #1
0
 @Override
 public Boolean caseRichStringLiteral(RichStringLiteral object) {
   String value = object.getValue();
   List<TextLine> lines = TextLines.splitString(value);
   if (lines.isEmpty()) {
     Literal literal = factory.createLiteral();
     literal.setLength(0);
     literal.setOffset(0);
     literal.setLiteral(object);
     addToCurrentLine(literal);
   } else {
     for (TextLine textLine : lines) {
       Literal literal = factory.createLiteral();
       literal.setLength(textLine.length());
       literal.setOffset(textLine.getRelativeOffset());
       literal.setLiteral(object);
       addToCurrentLine(literal);
       if (textLine.hasTrailingLineBreak()) {
         LineBreak lineBreak = factory.createLineBreak();
         lineBreak.setLength(textLine.getDelimiterLength());
         lineBreak.setOffset(textLine.getRelativeOffset() + textLine.length());
         lineBreak.setLiteral(object);
         addToCurrentLine(lineBreak);
         currentLine = null;
       }
     }
   }
   return Boolean.TRUE;
 }
예제 #2
0
 protected void addToCurrentLine(LinePart part) {
   if (currentLine == null) {
     currentLine = factory.createLine();
     if (!(part instanceof Literal) && !result.getLines().isEmpty()) {
       Line prevLine = result.getLines().get(result.getLines().size() - 1);
       LineBreak lineBreak = (LineBreak) prevLine.getParts().get(prevLine.getParts().size() - 1);
       Literal literal = factory.createLiteral();
       literal.setLength(0);
       literal.setOffset(lineBreak.getLiteral().getValue().length());
       literal.setLiteral(lineBreak.getLiteral());
       currentLine.getParts().add(literal);
     }
     result.getLines().add(currentLine);
   }
   if (part != null) currentLine.getParts().add(part);
 }