View Javadoc
1   package org.andromda.core.common;
2   
3   import de.plushnikov.doctorjim.ImportProcessor;
4   import de.plushnikov.doctorjim.javaparser.ParseException;
5   import java.io.File;
6   import org.apache.log4j.Logger;
7   
8   /**
9    * Implementation of PostProcessor interface to organize imports in java files
10   * @author Plushnikov Michail
11   */
12  public class ImportBeautifierPostProcessorImpl implements PostProcessor
13  {
14      /** The logger instance. */
15      private static final Logger LOGGER = Logger.getLogger(ImportBeautifierPostProcessorImpl.class);
16  
17      /**
18       * Determines if this file should be postprocessed in current postprocessor
19       * @param pFile file for postprocessing
20       * @return true if postprocessing should be done, false sonst
21       */
22      public boolean acceptFile(File pFile)
23      {
24          return null!=pFile && pFile.getName().endsWith(".java");
25      }
26  
27      /**
28       * Postprocess the source
29       * @param pSource the Source for postprocessing
30       * @param pPreviousData the Source of existing file, may be null or empty
31       * @return postprocessed source
32       * @throws Exception on errors occurred
33       */
34      public String postProcess(String pSource, String pPreviousData) throws Exception
35      {
36          try
37          {
38              return new ImportProcessor().organizeImports(pSource);
39          }
40          catch (ParseException ex)
41          {
42              LOGGER.debug("Error PostProcessing ", ex);
43              throw ex;
44          }
45      }
46  }