Java Code Examples for com.github.javaparser.printer.PrettyPrinterConfiguration#setPrintComments()

The following examples show how to use com.github.javaparser.printer.PrettyPrinterConfiguration#setPrintComments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceProjectImpl.java    From chrome-devtools-java-client with Apache License 2.0 6 votes vote down vote up
@Override
public void saveAll() {
  PrettyPrinterConfiguration prettyPrinterConfiguration = new PrettyPrinterConfiguration();
  prettyPrinterConfiguration.setIndent("\t");
  prettyPrinterConfiguration.setPrintComments(true);
  prettyPrinterConfiguration.setPrintJavadoc(true);
  prettyPrinterConfiguration.setOrderImports(true);

  PrettyPrinter prettyPrinter = new PrettyPrinter(prettyPrinterConfiguration);

  JavaFormatterOptions javaFormatterOptions =
      JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.GOOGLE).build();

  sourceRoot.setPrinter(googleCodeFormatter(javaFormatterOptions, prettyPrinter::print));
  sourceRoot.saveAll(sourceRoot.getRoot());
}
 
Example 2
Source File: JavaMethodParser.java    From Siamese with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visit(MethodDeclaration n, Object arg) {
    ArrayList<crest.siamese.document.Parameter> paramsList = new ArrayList<>();
    // do not include comments in the indexed code
    PrettyPrinterConfiguration ppc = new PrettyPrinterConfiguration();
    ppc.setPrintComments(false);
    ppc.setPrintJavaDoc(false);
    // retrieve the comments separately
    String comment = retrieveComments(n);
    int begin = -1;
    int end = -1;
    if (n.getBegin().isPresent()) begin = n.getBegin().get().line;
    if (n.getEnd().isPresent()) end = n.getEnd().get().line;
    methodList.add(createNewMethod(n.getName().asString(), comment, n.toString(ppc), begin,
            end, paramsList, n.getDeclarationAsString()));
    super.visit(n, arg);
}
 
Example 3
Source File: JavaMethodParser.java    From Siamese with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visit(ConstructorDeclaration c, Object arg) {
    ArrayList<crest.siamese.document.Parameter> paramsList = new ArrayList<>();
    // do not include comments in the indexed code
    PrettyPrinterConfiguration ppc = new PrettyPrinterConfiguration();
    ppc.setPrintComments(false);
    ppc.setPrintJavaDoc(false);
    String comment = retrieveComments(c);
    int begin = -1;
    int end = -1;
    if (c.getBegin().isPresent()) begin = c.getBegin().get().line;
    if (c.getEnd().isPresent()) end = c.getEnd().get().line;
    methodList.add(createNewMethod(c.getName().asString(), comment, c.toString(ppc), begin,
            end, paramsList, c.getDeclarationAsString()));
    super.visit(c, arg);
}