Skip to content

Commit 2f18de7

Browse files
committed
Streamline ua.tests.doc bundle code
* Reduce variable/method scopes * Do not needlessly convert from collection to array and back * Use foreach
1 parent b9d3edb commit 2f18de7

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/actions/CheckLinkAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2016 IBM Corporation and others.
2+
* Copyright (c) 2009, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -64,10 +64,9 @@ private void checkLinks() {
6464
System.out.println("Checked " + count + " links");
6565
}
6666
//System.out.println("Process " + next);
67-
URL url;
6867
boolean opened;
6968
try {
70-
url = new URL(next);
69+
URL url = new URL(next);
7170
//URLConnection connection = url.openConnection();
7271
//connection.
7372
try (InputStream input = url.openStream()) {

ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/actions/CheckTocAction.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2016 IBM Corporation and others.
2+
* Copyright (c) 2009, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,6 @@
1414

1515
package org.eclipse.ua.tests.doc.internal.actions;
1616

17-
import java.util.ArrayList;
1817
import java.util.List;
1918

2019
import org.eclipse.core.runtime.ILog;
@@ -30,14 +29,12 @@
3029

3130
public class CheckTocAction implements IWorkbenchWindowActionDelegate {
3231
private IWorkbenchWindow window;
33-
public static List<BrokenLink> errors = new ArrayList<>();
3432

35-
public static void showErrors() {
33+
private static void showErrors(List<BrokenLink> errors) {
3634
if (errors.isEmpty()) {
3735
reportStatus("No errors detected in load");
3836
}
39-
for (int i = 0; i < errors.size(); i++) {
40-
BrokenLink link = errors.get(i);
37+
for (BrokenLink link : errors) {
4138
reportStatus("Invalid link in \"" + link.getTocID() + "\": " + link.getHref());
4239
}
4340
}
@@ -66,22 +63,22 @@ public void run(IAction action) {
6663
if (dlg.getReturnCode() == Window.CANCEL) {
6764
return;
6865
}
69-
Toc[] tocsToCheck = dlg.getTocsToCheck();
66+
List<Toc> tocsToCheck = dlg.getTocsToCheck();
7067
checkTocFilesExist(tocsToCheck);
7168

7269
}
7370

74-
public void checkTocFilesExist(Toc[] tocsToCheck) {
71+
public void checkTocFilesExist(List<Toc> tocsToCheck) {
7572
for (Toc toc : tocsToCheck) {
7673
String id = toc.getTocContribution().getId();
7774
reportStatus("Testing " + id);
7875
String[] href = { id };
7976
try {
80-
errors = TocValidator.validate(href);
77+
List<BrokenLink> errors = TocValidator.validate(href);
78+
showErrors(errors);
8179
} catch (Exception e) {
8280
e.printStackTrace();
8381
}
84-
showErrors();
8582
}
8683
}
8784

ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/actions/LoadTocAction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2016 IBM Corporation and others.
2+
* Copyright (c) 2009, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -84,8 +84,7 @@ public static void showErrors() {
8484
} else {
8585
reportStatus("Testing complete, errors found");
8686
}
87-
for (Iterator<String> iter = errors.iterator(); iter.hasNext();) {
88-
String errorMessage = iter.next();
87+
for (String errorMessage : errors) {
8988
reportStatus(errorMessage);
9089
}
9190
errors = null;
@@ -170,11 +169,11 @@ public void run(IAction action) {
170169
return;
171170
}
172171
int testKind = dlg.getTestKind();
173-
PrioritizedFilter[] filters = new PrioritizedFilter[] {
172+
PrioritizedFilter[] filters = {
174173
new PrioritizedFilter(new OnLoadFilter(testKind), 1),
175174
new PrioritizedFilter(new AddScriptFilter(), 2)};
176175
ExtraFilters.setFilters(filters);
177-
Toc[] tocsToCheck = dlg.getTocsToCheck();
176+
List<Toc> tocsToCheck = dlg.getTocsToCheck();
178177
if (testKind == SelectTocDialog.PAGES_EXIST) {
179178
new CheckTocAction().checkTocFilesExist(tocsToCheck);
180179
return;

ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/dialogs/SelectTocDialog.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ protected void okPressed() {
9696
super.okPressed();
9797
}
9898

99-
public Toc[] getTocsToCheck() {
100-
ArrayList<Toc> selected = new ArrayList<>();
99+
public java.util.List<Toc> getTocsToCheck() {
100+
java.util.List<Toc> selected = new ArrayList<>();
101101
for (int selectedToc : selectedTocs) {
102102
selected.add(tocs[selectedToc]);
103103
}
104-
Toc[] tocsToCheck = selected.toArray(new Toc[0]) ;
105-
return tocsToCheck;
104+
return selected;
106105
}
107106

108107
public int getTestKind() {

0 commit comments

Comments
 (0)