package lombok.delombok;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.List;
import javax.tools.JavaFileObject;
import lombok.javac.CommentInfo;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
public class DelombokResult {
private final List<CommentInfo> ;
private final List<Integer> textBlockStarts;
private final JCCompilationUnit compilationUnit;
private final boolean changed;
private final FormatPreferences formatPreferences;
public DelombokResult(List<CommentInfo> comments, List<Integer> textBlockStarts, JCCompilationUnit compilationUnit, boolean changed, FormatPreferences formatPreferences) {
this.comments = comments;
this.textBlockStarts = textBlockStarts;
this.compilationUnit = compilationUnit;
this.changed = changed;
this.formatPreferences = formatPreferences;
}
public void print(Writer out) throws IOException {
if (!changed) {
CharSequence content = getContent();
if (content != null) {
out.write(content.toString());
return;
}
}
if (formatPreferences.generateDelombokComment()) {
out.write("// Generated by delombok at ");
out.write(String.valueOf(new Date()));
out.write(System.getProperty("line.separator"));
}
com.sun.tools.javac.util.List<CommentInfo> comments_;
int[] textBlockStarts_;
if (comments instanceof com.sun.tools.javac.util.List) comments_ = (com.sun.tools.javac.util.List<CommentInfo>) comments;
else comments_ = com.sun.tools.javac.util.List.from(comments.toArray(new CommentInfo[0]));
textBlockStarts_ = new int[textBlockStarts.size()];
int idx = 0;
for (int tbs : textBlockStarts) textBlockStarts_[idx++] = tbs;
FormatPreferences preferences = new FormatPreferenceScanner().scan(formatPreferences, getContent());
compilationUnit.accept(new PrettyPrinter(out, compilationUnit, comments_, textBlockStarts_, preferences));
}
private CharSequence getContent() throws IOException {
JavaFileObject sourceFile = compilationUnit.getSourceFile();
if (sourceFile == null) return null;
return sourceFile.getCharContent(true);
}
public boolean isChanged() {
return changed;
}
}