11package org .eclipse .swt .tools .internal ;
22
33import java .io .*;
4+ import java .nio .file .*;
45import java .util .*;
56import java .util .Map .*;
67
@@ -125,7 +126,7 @@ public static void main(String[] args) {
125126 basher .bashJavaSourceTree (source , target , out );
126127 List <String > bashedList = basher .getBashed ();
127128 basher .status ("Bashed" , bashedList , targetSubdir );
128- if (bashedList .size () > 0 ) {
129+ if (! bashedList .isEmpty () ) {
129130 totalBashed += bashedList .size ();
130131 if (fVerbose )
131132 basher .status ("Didn't change" , basher .getUnchanged (),
@@ -152,26 +153,17 @@ void status(String label, List<String> list, String targetSubdir) {
152153 }
153154
154155 char [] readFile (File file ) {
155- try (Reader in = new FileReader (file )) {
156- CharArrayWriter storage = new CharArrayWriter ();
157- char [] chars = new char [8192 ];
158- int read = in .read (chars );
159- while (read > 0 ) {
160- storage .write (chars , 0 , read );
161- storage .flush ();
162- read = in .read (chars );
163- }
164- return storage .toCharArray ();
156+ try {
157+ return Files .readString (file .toPath ()).toCharArray ();
165158 } catch (IOException ioe ) {
166159 System .out .println ("*** Could not read " + file );
167160 }
168161 return null ;
169162 }
170163
171- void writeFile (char [] contents , File file ) {
172- try (Writer out = new FileWriter (file )) {
173- out .write (contents );
174- out .flush ();
164+ void writeFile (String contents , File file ) {
165+ try {
166+ Files .writeString (file .toPath (), contents );
175167 } catch (IOException ioe ) {
176168 System .out .println ("*** Could not write to " + file );
177169 if (fVerbose ) {
@@ -196,11 +188,8 @@ void bashJavaSourceTree(File sourceDir, File targetDir, File outDir) {
196188
197189 String [] list = sourceDir .list ();
198190 if (list != null ) {
199- int count = list .length ;
200- for (int i = 0 ; i < count ; i ++) {
201- String filename = list [i ];
202- if (filename .equals ("CVS" ) || filename .equals ("internal" )
203- || filename .equals ("library" ))
191+ for (String filename : list ) {
192+ if (filename .equals ("internal" ) || filename .equals ("library" ))
204193 continue ;
205194 File source = new File (sourceDir , filename );
206195 File target = new File (targetDir , filename );
@@ -238,14 +227,14 @@ void bashFile(final File source, final File target, File out) {
238227 ASTParser parser = ASTParser .newParser (AST .getJLSLatest ());
239228 final Document sourceDocument = new Document (new String (contents ));
240229 parser .setSource (contents );
241- CompilationUnit sourceUnit = ( CompilationUnit ) parser .createAST (null );
230+ ASTNode sourceUnit = parser .createAST (null );
242231
243232 contents = readFile (target );
244233 if (contents == null ) return ;
245234 String targetContents = new String (contents );
246235 final Document targetDocument = new Document (targetContents );
247236 parser .setSource (contents );
248- CompilationUnit targetUnit = ( CompilationUnit ) parser .createAST (null );
237+ ASTNode targetUnit = parser .createAST (null );
249238
250239 final HashMap <String , String > comments = new HashMap <>();
251240 sourceUnit .accept (new ASTVisitor () {
@@ -395,7 +384,7 @@ public boolean visit(TypeDeclaration node) {
395384 * c) names that are in the filter list are never API,
396385 * or they are old API that is defined in the super on some platforms
397386 */
398- if (comments .size () > 0 ) {
387+ if (! comments .isEmpty () ) {
399388 String [] filter = new String [] {
400389 "Color.win32_newDeviceint" ,
401390 "Cursor.win32_newDeviceint" ,
@@ -447,7 +436,7 @@ public boolean visit(TypeDeclaration node) {
447436 };
448437 for (Entry <String , String > entry : comments .entrySet ()) {
449438 String name = entry .getKey ();
450- if (entry .getValue ().length () > 0 ){
439+ if (! entry .getValue ().isEmpty () ){
451440 int i = 0 ;
452441 for (i = 0 ; i < filter .length ; i ++) {
453442 if (name .equals (filter [i ])) break ;
@@ -462,7 +451,7 @@ public boolean visit(TypeDeclaration node) {
462451 String newContents = targetDocument .get ();
463452 if (!targetContents .equals (newContents )) {
464453 if (makeDirectory (out .getParentFile ())) {
465- writeFile (newContents . toCharArray () , out );
454+ writeFile (newContents , out );
466455 fBashed .add (target .toString ());
467456 } else {
468457 System .out .println ("*** Could not create " + out .getParent ());
0 commit comments