1 package org.simantics.scl.compiler.internal.parsing.declarations;
4 public class DDocumentationAst extends DeclarationAst {
5 public final String documentation;
7 public DDocumentationAst(String documentation) {
8 this.documentation = cleanUp(documentation);
12 public void toString(int indentation, StringBuilder b) {
13 for(int i=0;i<indentation;++i) b.append(" ");
15 b.append(documentation);
20 private static String cleanUp(String documentation) {
22 int end = documentation.length();
24 char c = documentation.charAt(end-1);
25 if(c != ' ' && c != '\n')
31 for(int i=0;i<end;++i) {
32 char c = documentation.charAt(i);
39 // Calculate common indentation
40 int lineStart = begin;
41 int commonIndentation = Integer.MAX_VALUE;
42 for(int i=begin;i<end;++i) {
43 char c = documentation.charAt(i);
47 else if(lineStart >= 0 && c != ' ') {
48 int indentation = i - lineStart;
49 commonIndentation = Math.min(commonIndentation, indentation);
50 if(commonIndentation == 0) {
51 if(begin == 0 && end == documentation.length())
54 return documentation.substring(begin, end);
60 // Remove common indentation
61 StringBuilder result = new StringBuilder();
62 int charsToSkip = commonIndentation;
63 for(int i=begin;i<end;++i) {
64 char c = documentation.charAt(i);
67 charsToSkip = commonIndentation;
75 return result.toString();