Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.eclipse.swt.tools.internal;

import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.Map.*;

Expand Down Expand Up @@ -125,7 +126,7 @@ public static void main(String[] args) {
basher.bashJavaSourceTree(source, target, out);
List<String> 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(),
Expand All @@ -152,26 +153,17 @@ void status(String label, List<String> 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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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<String, String> comments = new HashMap<>();
sourceUnit.accept(new ASTVisitor() {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -447,7 +436,7 @@ public boolean visit(TypeDeclaration node) {
};
for (Entry<String, String> 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;
Expand All @@ -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());
Expand Down
Loading