public static void reformatJavaSource(File file) throws CoreException {
  try {
    String generatedSource=textFromFile(file);
    String reformattedSource=reformatJavaSourceAsString(generatedSource);
    if (!reformattedSource.equals(generatedSource)) {
      writeStringToFile(reformattedSource,file);
    }
  }
 catch (  IOException ioe) {
    throw new CoreException(new Status(Status.ERROR,CorePlugin.PLUGIN_ID,"IOException while trying to reformat source code in new project"));
  }
}

public static void reformatJavaSource ( File file ) throws CoreException { try { String generatedSource = textFromFile ( file ) ; String reformattedSource = reformatJavaSourceAsString ( generatedSource ) ; if ( ! reformattedSource . equals ( generatedSource ) ) { writeStringToFile ( reformattedSource , file ) ; } } catch ( IOException ioe ) { throw new CoreException ( new Status ( Status . ERROR , CorePlugin . PLUGIN_ID , "IOException while trying to reformat source code in new project" ) ) ; } }
given a java . io . file containing java source , call the eclipse auto - format code on that source and write it back to disk .
