diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b13c07305de..e56e888646c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -54,7 +54,7 @@ jobs: run: | git lfs pull --include='/binaries/org.eclipse.swt.win32.win32.x86_64/WebView2Loader.dll' - name: Set up Java ${{ matrix.java }} - uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1 + uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0 with: java-version: ${{ matrix.java }} distribution: 'temurin' diff --git a/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java b/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java index 7ffbf48288a..0bd4eecbc84 100644 --- a/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java +++ b/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java @@ -1,6 +1,7 @@ package org.eclipse.swt.tools.internal; import java.io.*; +import java.nio.file.*; import java.util.*; import java.util.Map.*; @@ -125,7 +126,7 @@ public static void main(String[] args) { basher.bashJavaSourceTree(source, target, out); List bashedList = basher.getBashed(); basher.status("Bashed", bashedList, targetSubdir); - if (bashedList.size() > 0) { + if (!bashedList.isEmpty()) { totalBashed += bashedList.size(); if (fVerbose) basher.status("Didn't change", basher.getUnchanged(), @@ -152,26 +153,17 @@ void status(String label, List list, String targetSubdir) { } char[] readFile(File file) { - try (Reader in = new FileReader(file)) { - CharArrayWriter storage = new CharArrayWriter(); - char[] chars = new char[8192]; - int read = in.read(chars); - while (read > 0) { - storage.write(chars, 0, read); - storage.flush(); - read = in.read(chars); - } - return storage.toCharArray(); + try { + return Files.readString(file.toPath()).toCharArray(); } catch (IOException ioe) { System.out.println("*** Could not read " + file); } return null; } - void writeFile(char[] contents, File file) { - try (Writer out = new FileWriter(file)) { - out.write(contents); - out.flush(); + void writeFile(String contents, File file) { + try { + Files.writeString(file.toPath(), contents); } catch (IOException ioe) { System.out.println("*** Could not write to " + file); if (fVerbose) { @@ -196,11 +188,8 @@ void bashJavaSourceTree(File sourceDir, File targetDir, File outDir) { String[] list = sourceDir.list(); if (list != null) { - int count = list.length; - for (int i = 0; i < count; i++) { - String filename = list[i]; - if (filename.equals("CVS") || filename.equals("internal") - || filename.equals("library")) + for (String filename: list) { + if (filename.equals("internal") || filename.equals("library")) continue; File source = new File(sourceDir, filename); File target = new File(targetDir, filename); @@ -238,14 +227,14 @@ void bashFile(final File source, final File target, File out) { ASTParser parser = ASTParser.newParser(AST.getJLSLatest()); final Document sourceDocument = new Document(new String(contents)); parser.setSource(contents); - CompilationUnit sourceUnit = (CompilationUnit)parser.createAST(null); + ASTNode sourceUnit = parser.createAST(null); contents = readFile(target); if (contents == null) return; String targetContents = new String(contents); final Document targetDocument = new Document(targetContents); parser.setSource(contents); - CompilationUnit targetUnit = (CompilationUnit)parser.createAST(null); + ASTNode targetUnit = parser.createAST(null); final HashMap comments = new HashMap<>(); sourceUnit.accept(new ASTVisitor() { @@ -395,7 +384,7 @@ public boolean visit(TypeDeclaration node) { * c) names that are in the filter list are never API, * or they are old API that is defined in the super on some platforms */ - if (comments.size() > 0) { + if (!comments.isEmpty()) { String [] filter = new String [] { "Color.win32_newDeviceint", "Cursor.win32_newDeviceint", @@ -447,7 +436,7 @@ public boolean visit(TypeDeclaration node) { }; for (Entry entry: comments.entrySet()) { String name = entry.getKey(); - if (entry.getValue().length() > 0){ + if (!entry.getValue().isEmpty()){ int i = 0; for (i = 0; i < filter.length; i++) { if (name.equals(filter[i])) break; @@ -462,7 +451,7 @@ public boolean visit(TypeDeclaration node) { String newContents = targetDocument.get(); if (!targetContents.equals(newContents)) { if (makeDirectory(out.getParentFile())) { - writeFile(newContents.toCharArray(), out); + writeFile(newContents, out); fBashed.add(target.toString()); } else { System.out.println("*** Could not create " + out.getParent());