Package org.hybridlabs.source.formatter

Examples of org.hybridlabs.source.formatter.JavaImportBeautifier


    private boolean debugMode;
   
    public void execute() throws BuildException {
        super.execute();
       
        JavaImportBeautifier beautifier = new JavaImportBeautifier();
        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


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

        JavaImportBeautifier beautifier = new JavaImportBeautifier();
        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 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 {
        JavaImportBeautifier beautifier = new JavaImportBeautifier();
        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

TOP

Related Classes of org.hybridlabs.source.formatter.JavaImportBeautifier

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.