Package org.hybridlabs.source.beautifier

Examples of org.hybridlabs.source.beautifier.JavaImportBeautifierImpl


      message += "jalopy";
    }
    message += ": ";
    LOG.info(message + " under " + targetRootDirectory);

    JavaImportBeautifierImpl beautifier = new JavaImportBeautifierImpl();
    FormatManager manager = new FormatManager();
    manager.setConvention(beautifier);
    beautifier.setOrganizeImports(imports);
    // There are problems with the Jalopy parser for the generated files:
    // Unexpected char '<'
    beautifier.setFormat(jalopy);

    List<File> sourceFiles = manager.getAllJavaFiles(sourceRootDirectory);

    // Now reformat and save the targeted files to the target directory
    int listSize = sourceFiles.size();
    for (int i = 0; i < listSize; i++) {
      File sourceFile = (File) sourceFiles.get(i);
      LOG.info(message + sourceFile.getName() + " under "
          + sourceFile.getParent());

      CharacterSequence sequence = new CharacterSequence(
          FileHelper.loadStringBuffer(sourceFile));
      String original = sequence.getString();

      try {
        beautifier.beautify(sequence);
        // Only overwrite the file if the beautifier changes it, or if a
        // different directory
        // Sometimes Jalopy throws an error and returns a zero length
        // file.
        if (sequence.length() > 1
View Full Code Here


   *             If the creation of a new file or directory fails
   */
  public static void formatFile(File sourceFile, String targetRootDirectory,
      boolean imports, boolean jalopy) throws FileNotFoundException,
      IOException {
    JavaImportBeautifierImpl beautifier = new JavaImportBeautifierImpl();
    FormatManager manager = new FormatManager();
    manager.setConvention(beautifier);
    beautifier.setOrganizeImports(imports);
    // There are problems with the Jalopy parser for the generated files:
    // Unexpected char '<'
    beautifier.setFormat(jalopy);

    LOG.info("Formatting file: " + sourceFile.getName());

    CharacterSequence sequence = new CharacterSequence(
        FileHelper.loadStringBuffer(sourceFile));

    try {
      beautifier.beautify(sequence);
      // Only overwrite the file if the beautifier changes it, or if a
      // different directory
      // Sometimes Jalopy throws an error and returns a zero length file.
      if (sequence.length() > 1) {
        File targetFile = null;
View Full Code Here

import org.hybridlabs.source.beautifier.JavaImportBeautifierImpl;

public class DocumentationTest extends TestCase {

    public void testSampleEntityBean() throws Exception {
        JavaImportBeautifierImpl beautifier = new JavaImportBeautifierImpl();
        beautifier.setFormat(true);
        beautifier.setOrganizeImports(true);

        CharacterSequence sequence = new CharacterSequence(loadTestFile("Documentation_Sample1.java_input"));
        beautifier.beautify(sequence);

        CharacterSequence expectedOutput = new CharacterSequence(loadTestFile("Documentation_Sample1.java_output"));
        compare(expectedOutput, sequence);

    }
View Full Code Here

    private boolean debugMode;

    public void execute() throws BuildException {
        super.execute();

        JavaImportBeautifierImpl beautifier = new JavaImportBeautifierImpl();
        beautifier.setConventionFilePath(conventionFilePath);
        beautifier.setFormat(format);
        beautifier.setOrganizeImports(organizeImport);

        // find all .java files in the specified path
        String[] fileList = fileSet.getDirectoryScanner(getProject()).getIncludedFiles();

        for (int i = 0; i < fileList.length; i++) {
            File file = new File(fileSet.getDir(getProject()).getAbsolutePath() + "/" + fileList[i]);
            try {
                beautifier.beautify(file, debugMode ? new File(file.getAbsoluteFile()+"_debug") : null);
            } catch (FileNotFoundException e) {
                throw new BuildException(e.getMessage(), e);
            } catch (IOException e) {
                throw new BuildException(e.getMessage(), e);
            }
View Full Code Here

TOP

Related Classes of org.hybridlabs.source.beautifier.JavaImportBeautifierImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.