Пример #1
0
 private int getStringOrCommentIndent(int offset) {
   CommonToken tokenContainingOffset = getTokenStrictlyContainingOffset(offset);
   CommonToken token = getStartOfStringToken(tokenContainingOffset);
   if (token != null) {
     int type = token.getType();
     int start = token.getCharPositionInLine();
     if (token.getStartIndex() < offset) {
       switch (type) {
         case STRING_LITERAL:
         case STRING_START:
         case ASTRING_LITERAL:
           return start + 1;
         case STRING_MID:
         case STRING_END:
         case MULTI_COMMENT:
           return start + 1;
           // uncomment to get a bigger indent
           //                    return start+3;
         case VERBATIM_STRING:
         case AVERBATIM_STRING:
           return start + 3;
       }
     }
   }
   return -1;
 }
Пример #2
0
 private void fixIndentOfStringOrCommentContinuation() throws BadLocationException {
   int endOfWs = firstEndOfWhitespace(command.offset, getEndOfCurrentLine());
   if (endOfWs < 0) return;
   CommonToken tokenContainingOffset = getTokenStrictlyContainingOffset(command.offset);
   CommonToken token = getStartOfStringToken(tokenContainingOffset);
   int pos = command.offset - getStartOfCurrentLine();
   int tokenIndent = token.getCharPositionInLine();
   if (pos > tokenIndent) return;
   StringBuilder indent = new StringBuilder();
   int startOfTokenLine = document.getLineOffset(token.getLine() - 1);
   String prefix = document.get(startOfTokenLine + pos, tokenIndent - pos);
   for (int i = 0; i < prefix.length(); i++) {
     char ch = prefix.charAt(i);
     indent.append(ch == '\t' ? '\t' : ' ');
   }
   indent.append(getExtraIndent(token));
   indent.append(getRelativeIndent(command.offset));
   if (indent.length() > 0) {
     command.length = endOfWs - command.offset;
     command.text = indent.toString();
   }
 }